testit-js-commons 5.0.7 → 5.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -6,8 +6,6 @@ export declare class TestRunsService extends BaseService implements ITestRunsSer
|
|
|
6
6
|
protected _client: any;
|
|
7
7
|
protected _converter: ITestRunConverter;
|
|
8
8
|
private readonly _testResults;
|
|
9
|
-
/** Finalized via POST setAutoTestResults in this process (skip duplicate bulk send). */
|
|
10
|
-
private readonly finalizedExternalIds;
|
|
11
9
|
/** testResultId by autoTestExternalId within current run (InProgress POST + final POST). */
|
|
12
10
|
private readonly testResultIdsByExternalId;
|
|
13
11
|
constructor(config: AdapterConfig);
|
|
@@ -25,8 +25,6 @@ class TestRunsService extends common_1.BaseService {
|
|
|
25
25
|
constructor(config) {
|
|
26
26
|
super(config);
|
|
27
27
|
this.config = config;
|
|
28
|
-
/** Finalized via POST setAutoTestResults in this process (skip duplicate bulk send). */
|
|
29
|
-
this.finalizedExternalIds = new Set();
|
|
30
28
|
/** testResultId by autoTestExternalId within current run (InProgress POST + final POST). */
|
|
31
29
|
this.testResultIdsByExternalId = new Map();
|
|
32
30
|
this._client = new AdaptersApi.TestRunsApi(AdaptersApi.ApiClient.instance);
|
|
@@ -180,13 +178,6 @@ class TestRunsService extends common_1.BaseService {
|
|
|
180
178
|
var _a, _b;
|
|
181
179
|
for (const result of results) {
|
|
182
180
|
const externalId = result.autoTestExternalId;
|
|
183
|
-
if (this.finalizedExternalIds.has(externalId)) {
|
|
184
|
-
(0, utils_1.logTmsLoadTestRun)("Bulk import: skip sendTestResults (already finalized)", {
|
|
185
|
-
testRunId,
|
|
186
|
-
autoTestExternalId: externalId,
|
|
187
|
-
});
|
|
188
|
-
continue;
|
|
189
|
-
}
|
|
190
181
|
const autotestResult = this._converter.toOriginAutotestResult(result);
|
|
191
182
|
(0, utils_1.escapeHtmlInObject)(autotestResult);
|
|
192
183
|
(0, utils_1.logTmsLoadTestRun)("POST setAutoTestResults (final)", {
|
|
@@ -198,7 +189,6 @@ class TestRunsService extends common_1.BaseService {
|
|
|
198
189
|
});
|
|
199
190
|
yield this.sendAutotestResultWithRetry(testRunId, autotestResult)
|
|
200
191
|
.then(() => {
|
|
201
|
-
this.finalizedExternalIds.add(externalId);
|
|
202
192
|
(0, utils_1.logTmsLoadTestRun)("Finalized test result via sendTestResults", {
|
|
203
193
|
testRunId,
|
|
204
194
|
autoTestExternalId: externalId,
|
|
@@ -49,14 +49,13 @@ describe("TestRunsService.loadAutotests", () => {
|
|
|
49
49
|
yield service.loadAutotests("run-1", [makeResult()]);
|
|
50
50
|
expect(internal._client.adaptersTestRunsIdTestResultsPost).toHaveBeenCalledTimes(1);
|
|
51
51
|
expect(internal._testResults.updateTestResult).not.toHaveBeenCalled();
|
|
52
|
-
expect(internal.finalizedExternalIds.has("ext-1")).toBe(true);
|
|
53
52
|
}));
|
|
54
|
-
it("
|
|
53
|
+
it("allows repeated POST for the same externalId (retry attempts)", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
55
54
|
const service = new testruns_service_1.TestRunsService(makeConfig());
|
|
56
55
|
const internal = service;
|
|
57
|
-
|
|
58
|
-
yield service.loadAutotests("run-1", [makeResult()]);
|
|
59
|
-
expect(internal._client.adaptersTestRunsIdTestResultsPost).
|
|
56
|
+
yield service.loadAutotests("run-1", [makeResult({ outcome: "Failed" })]);
|
|
57
|
+
yield service.loadAutotests("run-1", [makeResult({ outcome: "Passed" })]);
|
|
58
|
+
expect(internal._client.adaptersTestRunsIdTestResultsPost).toHaveBeenCalledTimes(2);
|
|
60
59
|
}));
|
|
61
60
|
});
|
|
62
61
|
describe("TestRunsService.updateSetupTeardown", () => {
|
|
@@ -8,11 +8,22 @@ export declare class BaseStrategy implements IStrategy {
|
|
|
8
8
|
client: IClient;
|
|
9
9
|
testRunId: Promise<TestRunId>;
|
|
10
10
|
private syncStorageRunner?;
|
|
11
|
+
/** externalId whose first attempt was posted as InProgress; finals deferred until teardown. */
|
|
12
|
+
private deferredExternalId?;
|
|
13
|
+
/** All attempts (including retries) for deferredExternalId, in order. */
|
|
14
|
+
private readonly deferredResults;
|
|
11
15
|
protected constructor(config: AdapterConfig);
|
|
12
16
|
setup(): Promise<void>;
|
|
13
17
|
teardown(): Promise<void>;
|
|
18
|
+
private flushDeferredResults;
|
|
14
19
|
loadAutotest(autotest: AutotestPost, status: string): Promise<void>;
|
|
15
20
|
private updateTestLinkToWorkItems;
|
|
21
|
+
/**
|
|
22
|
+
* Split batch: attempts for the deferred InProgress autotest go to the queue;
|
|
23
|
+
* everything else is posted as final immediately.
|
|
24
|
+
*/
|
|
25
|
+
private partitionByDeferred;
|
|
26
|
+
private enqueueDeferred;
|
|
16
27
|
loadTestRun(autotests: AutotestResult[]): Promise<void>;
|
|
17
28
|
updateSetupTeardown(autotests: AutotestResult[]): Promise<void>;
|
|
18
29
|
private tryStartSyncStorage;
|
|
@@ -21,6 +21,8 @@ const logger_1 = __importDefault(require("../logger"));
|
|
|
21
21
|
class BaseStrategy {
|
|
22
22
|
constructor(config) {
|
|
23
23
|
this.config = config;
|
|
24
|
+
/** All attempts (including retries) for deferredExternalId, in order. */
|
|
25
|
+
this.deferredResults = [];
|
|
24
26
|
this.client = new client_1.Client(config);
|
|
25
27
|
this.testRunId = Promise.resolve(config.testRunId);
|
|
26
28
|
}
|
|
@@ -38,6 +40,7 @@ class BaseStrategy {
|
|
|
38
40
|
return __awaiter(this, void 0, void 0, function* () {
|
|
39
41
|
var _a, _b;
|
|
40
42
|
const testRunId = yield this.testRunId;
|
|
43
|
+
yield this.flushDeferredResults(testRunId);
|
|
41
44
|
yield ((_a = this.syncStorageRunner) === null || _a === void 0 ? void 0 : _a.setWorkerStatus("completed"));
|
|
42
45
|
yield ((_b = this.syncStorageRunner) === null || _b === void 0 ? void 0 : _b.completeProcessing());
|
|
43
46
|
// With active sync-storage, run completion is finalized by sync-storage itself.
|
|
@@ -49,6 +52,27 @@ class BaseStrategy {
|
|
|
49
52
|
//await this.client.testRuns.completeTestRun(testRunId);
|
|
50
53
|
});
|
|
51
54
|
}
|
|
55
|
+
flushDeferredResults(testRunId) {
|
|
56
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
if (this.deferredResults.length === 0) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const results = this.deferredResults.splice(0, this.deferredResults.length);
|
|
61
|
+
(0, utils_1.logTmsLoadTestRun)("flush deferred finals", {
|
|
62
|
+
testRunId,
|
|
63
|
+
autoTestExternalId: this.deferredExternalId,
|
|
64
|
+
count: results.length,
|
|
65
|
+
});
|
|
66
|
+
yield this.client.testRuns.loadAutotests(testRunId, results).catch((err) => {
|
|
67
|
+
var _a;
|
|
68
|
+
logger_1.default.error("[strategy] FAILED to flush deferred results", {
|
|
69
|
+
autoTestExternalId: this.deferredExternalId,
|
|
70
|
+
error: (_a = err === null || err === void 0 ? void 0 : err.body) !== null && _a !== void 0 ? _a : err,
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
this.deferredExternalId = undefined;
|
|
74
|
+
});
|
|
75
|
+
}
|
|
52
76
|
loadAutotest(autotest, status) {
|
|
53
77
|
return __awaiter(this, void 0, void 0, function* () {
|
|
54
78
|
var _a, _b, _c, _d, _e, _f;
|
|
@@ -93,6 +117,37 @@ class BaseStrategy {
|
|
|
93
117
|
});
|
|
94
118
|
});
|
|
95
119
|
}
|
|
120
|
+
/**
|
|
121
|
+
* Split batch: attempts for the deferred InProgress autotest go to the queue;
|
|
122
|
+
* everything else is posted as final immediately.
|
|
123
|
+
*/
|
|
124
|
+
partitionByDeferred(autotests) {
|
|
125
|
+
if (!this.deferredExternalId) {
|
|
126
|
+
return { deferred: [], immediate: autotests };
|
|
127
|
+
}
|
|
128
|
+
const deferred = [];
|
|
129
|
+
const immediate = [];
|
|
130
|
+
for (const result of autotests) {
|
|
131
|
+
if (result.autoTestExternalId === this.deferredExternalId) {
|
|
132
|
+
deferred.push(result);
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
immediate.push(result);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return { deferred, immediate };
|
|
139
|
+
}
|
|
140
|
+
enqueueDeferred(results) {
|
|
141
|
+
if (results.length === 0) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
this.deferredResults.push(...results);
|
|
145
|
+
(0, utils_1.logTmsLoadTestRun)("enqueue deferred attempts", {
|
|
146
|
+
autoTestExternalId: this.deferredExternalId,
|
|
147
|
+
added: results.length,
|
|
148
|
+
queued: this.deferredResults.length,
|
|
149
|
+
});
|
|
150
|
+
}
|
|
96
151
|
loadTestRun(autotests) {
|
|
97
152
|
return __awaiter(this, void 0, void 0, function* () {
|
|
98
153
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
@@ -102,11 +157,21 @@ class BaseStrategy {
|
|
|
102
157
|
testRunId,
|
|
103
158
|
batchSize: autotests.length,
|
|
104
159
|
firstExternalId: firstResult === null || firstResult === void 0 ? void 0 : firstResult.autoTestExternalId,
|
|
160
|
+
deferredExternalId: this.deferredExternalId,
|
|
105
161
|
syncRunnerActive: Boolean((_b = (_a = this.syncStorageRunner) === null || _a === void 0 ? void 0 : _a.isActive) === null || _b === void 0 ? void 0 : _b.call(_a)),
|
|
106
162
|
isMaster: Boolean((_d = (_c = this.syncStorageRunner) === null || _c === void 0 ? void 0 : _c.isMasterWorker) === null || _d === void 0 ? void 0 : _d.call(_c)),
|
|
107
163
|
});
|
|
164
|
+
// Already holding an InProgress slot: buffer retries of that autotest, post the rest.
|
|
165
|
+
if (this.deferredExternalId) {
|
|
166
|
+
const { deferred, immediate } = this.partitionByDeferred(autotests);
|
|
167
|
+
this.enqueueDeferred(deferred);
|
|
168
|
+
if (immediate.length > 0) {
|
|
169
|
+
yield this.client.testRuns.loadAutotests(testRunId, immediate);
|
|
170
|
+
}
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
108
173
|
// InProgress is only for the first result (the one used for sync storage cut).
|
|
109
|
-
// Its final payload
|
|
174
|
+
// Its final payload (and retries of the same externalId) are deferred until teardown.
|
|
110
175
|
if (firstResult) {
|
|
111
176
|
const isMasterWorker = Boolean((_f = (_e = this.syncStorageRunner) === null || _e === void 0 ? void 0 : _e.isMasterWorker) === null || _f === void 0 ? void 0 : _f.call(_e));
|
|
112
177
|
const published = yield ((_g = this.syncStorageRunner) === null || _g === void 0 ? void 0 : _g.sendInProgressTestResult((0, syncstorage_1.toTestResultCutModel)(firstResult, this.config.projectId)));
|
|
@@ -145,10 +210,13 @@ class BaseStrategy {
|
|
|
145
210
|
});
|
|
146
211
|
throw err;
|
|
147
212
|
}
|
|
148
|
-
|
|
213
|
+
this.deferredExternalId = firstResult.autoTestExternalId;
|
|
214
|
+
this.enqueueDeferred([firstResult]);
|
|
149
215
|
const rest = autotests.slice(1);
|
|
150
|
-
|
|
151
|
-
|
|
216
|
+
const { deferred, immediate } = this.partitionByDeferred(rest);
|
|
217
|
+
this.enqueueDeferred(deferred);
|
|
218
|
+
if (immediate.length > 0) {
|
|
219
|
+
yield this.client.testRuns.loadAutotests(testRunId, immediate);
|
|
152
220
|
}
|
|
153
221
|
return;
|
|
154
222
|
}
|