testit-js-commons 5.1.2 → 5.1.3-TMS-6.0

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.
Files changed (33) hide show
  1. package/lib/adapters-api/dist/ApiClient.js +5 -6
  2. package/lib/adapters-api/dist/api/AttachmentsApi.js +5 -5
  3. package/lib/adapters-api/dist/api/AutoTestsApi.js +10 -118
  4. package/lib/adapters-api/dist/api/ConfigurationsApi.js +1 -1
  5. package/lib/adapters-api/dist/api/CustomAttributesApi.js +4 -4
  6. package/lib/adapters-api/dist/api/ParametersApi.js +3 -3
  7. package/lib/adapters-api/dist/api/ProjectAttributesApi.js +2 -2
  8. package/lib/adapters-api/dist/api/ProjectSectionsApi.js +1 -1
  9. package/lib/adapters-api/dist/api/ProjectWorkItemsApi.js +1 -1
  10. package/lib/adapters-api/dist/api/ProjectsApi.js +4 -4
  11. package/lib/adapters-api/dist/api/SectionsApi.js +2 -2
  12. package/lib/adapters-api/dist/api/TestResultsApi.js +3 -3
  13. package/lib/adapters-api/dist/api/TestRunsApi.js +8 -8
  14. package/lib/adapters-api/dist/api/WorkItemsApi.js +3 -3
  15. package/lib/adapters-api/dist/api/WorkflowsApi.js +1 -1
  16. package/lib/adapters-api/dist/index.js +7 -0
  17. package/lib/adapters-api/dist/model/AutoTestCaseModel.js +85 -0
  18. package/lib/adapters-api/dist/model/AutoTestFilterApiModel.js +27 -0
  19. package/lib/adapters-api/dist/model/AutoTestModel.js +15 -0
  20. package/lib/adapters-api/dist/model/AutoTestUpdateApiModel.js +4 -6
  21. package/lib/adapters-api/dist/model/CreateWorkItemApiModel.js +22 -0
  22. package/lib/adapters-api/dist/model/CustomAttributeType.js +6 -0
  23. package/lib/adapters-api/dist/model/CustomAttributeTypesEnum.js +6 -0
  24. package/lib/adapters-api/dist/model/WorkItemApiResult.js +28 -4
  25. package/lib/adapters-api/dist/model/WorkItemEntityTypeApiModel.js +6 -0
  26. package/lib/adapters-api/dist/model/WorkItemFilterApiModel.js +40 -0
  27. package/lib/adapters-api/dist/model/WorkItemTypeModel.js +6 -0
  28. package/lib/adapters-api/index.d.ts +85 -96
  29. package/lib/common/base.service.js +4 -1
  30. package/lib/services/syncstorage/syncstorage.runner.d.ts +29 -7
  31. package/lib/services/syncstorage/syncstorage.runner.js +233 -22
  32. package/lib/services/syncstorage/syncstorage.runner.test.js +67 -3
  33. package/package.json +1 -1
@@ -15,6 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.SyncStorageRunner = void 0;
16
16
  const fs_1 = require("fs");
17
17
  const promises_1 = require("fs/promises");
18
+ const http_1 = require("http");
18
19
  const https_1 = require("https");
19
20
  const path_1 = require("path");
20
21
  const process_1 = require("process");
@@ -26,7 +27,6 @@ const logger_1 = __importDefault(require("../../logger"));
26
27
  const SyncStorageClient = require("../../sync-storage/dist/index");
27
28
  class SyncStorageRunner {
28
29
  constructor(testRunId, config) {
29
- var _a;
30
30
  this.testRunId = testRunId;
31
31
  this.config = config;
32
32
  this.isMaster = false;
@@ -35,28 +35,115 @@ class SyncStorageRunner {
35
35
  this.running = false;
36
36
  this.workerPid = `worker-${process.pid}-${Date.now()}`;
37
37
  this.baseUrl = config.url;
38
- this.port = (_a = config.syncStoragePort) !== null && _a !== void 0 ? _a : "49152";
38
+ this.preferredPort = SyncStorageRunner.parsePort(config.syncStoragePort, 49152);
39
+ this.port = String(this.preferredPort);
39
40
  this.serviceUrl = `http://localhost:${this.port}`;
40
- const apiClient = new SyncStorageClient.ApiClient(this.serviceUrl);
41
- apiClient.timeout = SyncStorageRunner.REQUEST_TIMEOUT_MS;
42
- this.healthApi = new SyncStorageClient.HealthApi(apiClient);
43
- this.workersApi = new SyncStorageClient.WorkersApi(apiClient);
44
- this.testResultsApi = new SyncStorageClient.TestResultsApi(apiClient);
45
- this.completionApi = new SyncStorageClient.CompletionApi(apiClient);
46
41
  this.registerRequestModel = SyncStorageClient.RegisterRequest;
47
42
  this.setWorkerStatusRequestModel = SyncStorageClient.SetWorkerStatusRequest;
48
43
  this.testResultCutModel = SyncStorageClient.TestResultCutApiModel;
44
+ this.rebindClients();
45
+ }
46
+ static parsePort(value, defaultPort) {
47
+ if (value == null || value === "" || value === "null") {
48
+ return defaultPort;
49
+ }
50
+ const parsed = Number.parseInt(String(value).trim(), 10);
51
+ return Number.isFinite(parsed) ? parsed : defaultPort;
52
+ }
53
+ static resolvePortMaxBump() {
54
+ const raw = process.env.SYNC_STORAGE_PORT_MAX_BUMP ||
55
+ process.env.TMS_SYNC_STORAGE_PORT_MAX_BUMP;
56
+ if (!raw) {
57
+ return SyncStorageRunner.DEFAULT_PORT_MAX_BUMP;
58
+ }
59
+ const parsed = Number.parseInt(String(raw).trim(), 10);
60
+ return Number.isFinite(parsed) && parsed >= 0
61
+ ? parsed
62
+ : SyncStorageRunner.DEFAULT_PORT_MAX_BUMP;
49
63
  }
64
+ static resolvePortAction(healthOk, runningTestRunId, myTestRunId) {
65
+ if (!healthOk) {
66
+ return "START_NEW";
67
+ }
68
+ if (!runningTestRunId) {
69
+ return "ATTACH";
70
+ }
71
+ if (runningTestRunId === myTestRunId) {
72
+ return "ATTACH";
73
+ }
74
+ return "TRY_NEXT";
75
+ }
76
+ /**
77
+ * Start or attach. Foreign testRunId / bind-register race → port+1 .. +maxBump.
78
+ * Do not process.exit-kill SS (detached / CI wait-completion); wait is completeProcessing().
79
+ */
50
80
  start() {
51
81
  return __awaiter(this, void 0, void 0, function* () {
52
82
  try {
53
- const healthy = yield this.healthcheck();
54
- if (!healthy) {
55
- const started = yield this.startLocalProcess();
56
- if (!started) {
57
- return false;
83
+ if (this.running) {
84
+ return true;
85
+ }
86
+ const maxBump = SyncStorageRunner.resolvePortMaxBump();
87
+ for (let offset = 0; offset <= maxBump; offset++) {
88
+ const candidate = this.preferredPort + offset;
89
+ this.port = String(candidate);
90
+ this.rebindClients();
91
+ const healthOk = yield this.healthcheck();
92
+ const runningId = healthOk ? yield this.fetchHealthTestRunId() : undefined;
93
+ const action = SyncStorageRunner.resolvePortAction(healthOk, runningId, this.testRunId);
94
+ if (action === "TRY_NEXT") {
95
+ logger_1.default.info(`Port ${candidate} busy with testRunId=${runningId}; trying ${candidate + 1}`);
96
+ continue;
97
+ }
98
+ if (candidate !== this.preferredPort) {
99
+ logger_1.default.info(`syncStoragePort effective=${this.port} (preferred=${this.preferredPort})`);
58
100
  }
101
+ if (action === "ATTACH") {
102
+ if (!runningId) {
103
+ logger_1.default.warn(`Existing sync-storage on port ${this.port} does not report testRunId in /health; ` +
104
+ `compatibility cannot be verified. Current testRunId: ${this.testRunId}`);
105
+ }
106
+ if (yield this.tryRegister()) {
107
+ this.running = true;
108
+ return true;
109
+ }
110
+ logger_1.default.info(`Attach/register failed on port ${candidate} (race or incompatible); trying next`);
111
+ continue;
112
+ }
113
+ if (yield this.tryStartOwnedProcess()) {
114
+ if (yield this.tryRegister()) {
115
+ this.running = true;
116
+ return true;
117
+ }
118
+ this.cleanupFailedSpawn();
119
+ logger_1.default.info(`Could not claim port ${candidate} for testRunId=${this.testRunId}; trying next`);
120
+ continue;
121
+ }
122
+ this.cleanupFailedSpawn();
123
+ logger_1.default.info(`Could not start sync-storage on port ${candidate}; trying next`);
59
124
  }
125
+ logger_1.default.warn(`No free sync-storage port in ${this.preferredPort}..${this.preferredPort + maxBump} for testRunId ${this.testRunId}`);
126
+ return false;
127
+ }
128
+ catch (error) {
129
+ logger_1.default.warn(`Sync storage start failed: ${error}`);
130
+ this.cleanupFailedSpawn();
131
+ return false;
132
+ }
133
+ });
134
+ }
135
+ rebindClients() {
136
+ this.serviceUrl = `http://localhost:${this.port}`;
137
+ const apiClient = new SyncStorageClient.ApiClient(this.serviceUrl);
138
+ apiClient.timeout = SyncStorageRunner.REQUEST_TIMEOUT_MS;
139
+ this.healthApi = new SyncStorageClient.HealthApi(apiClient);
140
+ this.workersApi = new SyncStorageClient.WorkersApi(apiClient);
141
+ this.testResultsApi = new SyncStorageClient.TestResultsApi(apiClient);
142
+ this.completionApi = new SyncStorageClient.CompletionApi(apiClient);
143
+ }
144
+ tryRegister() {
145
+ return __awaiter(this, void 0, void 0, function* () {
146
+ try {
60
147
  const request = this.registerRequestModel.constructFromObject({
61
148
  pid: this.workerPid,
62
149
  testRunId: this.testRunId,
@@ -65,11 +152,11 @@ class SyncStorageRunner {
65
152
  });
66
153
  const response = yield this.withRetry(() => __awaiter(this, void 0, void 0, function* () { return this.workersApi.registerPost(request); }), SyncStorageRunner.RETRY_COUNT);
67
154
  this.isMaster = Boolean(response === null || response === void 0 ? void 0 : response.is_master);
68
- this.running = true;
155
+ this.startKeepAlive();
69
156
  return true;
70
157
  }
71
158
  catch (error) {
72
- logger_1.default.warn(`Sync storage start failed: ${error}`);
159
+ logger_1.default.warn(`Sync storage register failed on port ${this.port}: ${error}`);
73
160
  return false;
74
161
  }
75
162
  });
@@ -186,6 +273,10 @@ class SyncStorageRunner {
186
273
  testRunId: this.testRunId,
187
274
  });
188
275
  yield this.withRetry(() => __awaiter(this, void 0, void 0, function* () { return this.workersApi.setWorkerStatusPost(request); }), SyncStorageRunner.RETRY_COUNT);
276
+ if (status === "completed") {
277
+ // Stop keep-alive only — do not wait-completion here (multi-suite mid-run).
278
+ this.stopKeepAlive();
279
+ }
189
280
  }
190
281
  catch (error) {
191
282
  logger_1.default.warn(`Sync storage set worker status failed: ${error}`);
@@ -194,6 +285,7 @@ class SyncStorageRunner {
194
285
  }
195
286
  completeProcessing() {
196
287
  return __awaiter(this, void 0, void 0, function* () {
288
+ this.stopKeepAlive();
197
289
  if (!this.running || !this.isMaster) {
198
290
  return;
199
291
  }
@@ -212,6 +304,70 @@ class SyncStorageRunner {
212
304
  }
213
305
  });
214
306
  }
307
+ startKeepAlive() {
308
+ var _a, _b;
309
+ this.stopKeepAlive();
310
+ this.keepAliveTimer = setInterval(() => {
311
+ void this.sendKeepAlive();
312
+ }, SyncStorageRunner.KEEP_ALIVE_INTERVAL_MS);
313
+ // Do not keep the event loop alive solely for keep-alive.
314
+ (_b = (_a = this.keepAliveTimer).unref) === null || _b === void 0 ? void 0 : _b.call(_a);
315
+ }
316
+ stopKeepAlive() {
317
+ if (this.keepAliveTimer) {
318
+ clearInterval(this.keepAliveTimer);
319
+ this.keepAliveTimer = undefined;
320
+ }
321
+ }
322
+ sendKeepAlive() {
323
+ return new Promise((resolve) => {
324
+ const payload = JSON.stringify({
325
+ pid: this.workerPid,
326
+ testRunId: this.testRunId,
327
+ });
328
+ const requestOptions = {
329
+ hostname: "localhost",
330
+ port: Number(this.port),
331
+ path: "/keep_alive",
332
+ method: "POST",
333
+ headers: {
334
+ "Content-Type": "application/json",
335
+ "Content-Length": Buffer.byteLength(payload),
336
+ },
337
+ timeout: SyncStorageRunner.KEEP_ALIVE_TIMEOUT_MS,
338
+ };
339
+ const httpReq = (0, http_1.request)(requestOptions, (res) => {
340
+ let body = "";
341
+ res.on("data", (chunk) => {
342
+ body += chunk;
343
+ });
344
+ res.on("end", () => {
345
+ if (res.statusCode === 404) {
346
+ if (body.includes("Worker not found")) {
347
+ logger_1.default.warn(`keep_alive: worker not found (pid=${this.workerPid})`);
348
+ }
349
+ else {
350
+ logger_1.default.debug(`keep_alive endpoint unavailable (HTTP 404, pid=${this.workerPid})`);
351
+ }
352
+ }
353
+ else if (res.statusCode && res.statusCode >= 400) {
354
+ logger_1.default.debug(`keep_alive failed: HTTP ${res.statusCode} (pid=${this.workerPid})`);
355
+ }
356
+ resolve();
357
+ });
358
+ });
359
+ httpReq.on("error", (err) => {
360
+ logger_1.default.debug(`keep_alive failed for pid=${this.workerPid}: ${err}`);
361
+ resolve();
362
+ });
363
+ httpReq.on("timeout", () => {
364
+ httpReq.destroy();
365
+ resolve();
366
+ });
367
+ httpReq.write(payload);
368
+ httpReq.end();
369
+ });
370
+ }
215
371
  healthcheck() {
216
372
  return __awaiter(this, void 0, void 0, function* () {
217
373
  try {
@@ -223,8 +379,37 @@ class SyncStorageRunner {
223
379
  }
224
380
  });
225
381
  }
226
- startLocalProcess() {
382
+ fetchHealthTestRunId() {
227
383
  return __awaiter(this, void 0, void 0, function* () {
384
+ return new Promise((resolve) => {
385
+ const req = (0, http_1.get)(`http://localhost:${this.port}/health`, { timeout: 1000 }, (res) => {
386
+ let body = "";
387
+ res.on("data", (chunk) => {
388
+ body += chunk;
389
+ });
390
+ res.on("end", () => {
391
+ try {
392
+ const data = JSON.parse(body);
393
+ resolve(typeof data.testRunId === "string" && data.testRunId
394
+ ? data.testRunId
395
+ : undefined);
396
+ }
397
+ catch (_a) {
398
+ resolve(undefined);
399
+ }
400
+ });
401
+ });
402
+ req.on("error", () => resolve(undefined));
403
+ req.on("timeout", () => {
404
+ req.destroy();
405
+ resolve(undefined);
406
+ });
407
+ });
408
+ });
409
+ }
410
+ tryStartOwnedProcess() {
411
+ return __awaiter(this, void 0, void 0, function* () {
412
+ var _a, _b;
228
413
  try {
229
414
  const executablePath = yield this.prepareExecutable();
230
415
  const command = [
@@ -233,17 +418,25 @@ class SyncStorageRunner {
233
418
  "--baseURL", this.baseUrl,
234
419
  "--privateToken", this.config.privateToken,
235
420
  ];
236
- // Do not inherit stdout/stderr: sync-storage binary logs stay silent unless TMS_DEBUG_SYNC_STORAGE=1 adapter traces.
421
+ // Detached where supported; do not process.exit-kill SS (CI/Work X must outlive runner).
422
+ // Wait for Work X via completeProcessing(), not exit hooks.
237
423
  this.syncStorageProcess = (0, child_process_1.spawn)(executablePath, command, {
238
424
  cwd: (0, path_1.join)(process.cwd(), "build", ".caches"),
239
425
  stdio: "ignore",
240
- detached: process_1.platform === "win32",
426
+ detached: true,
241
427
  });
428
+ (_b = (_a = this.syncStorageProcess).unref) === null || _b === void 0 ? void 0 : _b.call(_a);
242
429
  const started = yield this.waitForStartup();
243
- if (started) {
244
- yield this.delay(SyncStorageRunner.PROCESS_WARMUP_MS);
430
+ if (!started) {
431
+ return false;
245
432
  }
246
- return started;
433
+ const runningId = yield this.fetchHealthTestRunId();
434
+ if (runningId && runningId !== this.testRunId) {
435
+ logger_1.default.info(`Port ${this.port} became sync-storage for other testRunId=${runningId} after start race`);
436
+ return false;
437
+ }
438
+ yield this.delay(SyncStorageRunner.PROCESS_WARMUP_MS);
439
+ return true;
247
440
  }
248
441
  catch (error) {
249
442
  logger_1.default.warn(`Sync storage local process start failed: ${error}`);
@@ -251,6 +444,20 @@ class SyncStorageRunner {
251
444
  }
252
445
  });
253
446
  }
447
+ cleanupFailedSpawn() {
448
+ this.stopKeepAlive();
449
+ this.running = false;
450
+ this.isMaster = false;
451
+ if (this.syncStorageProcess && !this.syncStorageProcess.killed) {
452
+ try {
453
+ this.syncStorageProcess.kill();
454
+ }
455
+ catch (_a) {
456
+ // best-effort
457
+ }
458
+ }
459
+ this.syncStorageProcess = undefined;
460
+ }
254
461
  waitForStartup() {
255
462
  return __awaiter(this, void 0, void 0, function* () {
256
463
  const deadline = Date.now() + SyncStorageRunner.STARTUP_TIMEOUT_MS;
@@ -354,11 +561,15 @@ class SyncStorageRunner {
354
561
  }
355
562
  }
356
563
  exports.SyncStorageRunner = SyncStorageRunner;
357
- SyncStorageRunner.VERSION = "v0.3.12";
564
+ /** Floor+channel: binary must expose /keep_alive and /health.testRunId (0.4.x). */
565
+ SyncStorageRunner.VERSION = "v0.4.3-tms-6.0";
358
566
  SyncStorageRunner.STARTUP_TIMEOUT_MS = 30000;
359
567
  SyncStorageRunner.STARTUP_POLL_MS = 1000;
360
568
  SyncStorageRunner.PROCESS_WARMUP_MS = 2000;
361
569
  SyncStorageRunner.REQUEST_TIMEOUT_MS = 15000;
362
570
  SyncStorageRunner.RETRY_COUNT = 3;
363
571
  SyncStorageRunner.IN_PROGRESS_POLL_MS = 200;
572
+ SyncStorageRunner.DEFAULT_PORT_MAX_BUMP = 10;
573
+ SyncStorageRunner.KEEP_ALIVE_INTERVAL_MS = 25000;
574
+ SyncStorageRunner.KEEP_ALIVE_TIMEOUT_MS = 5000;
364
575
  SyncStorageRunner.REPO_BASE = "https://github.com/testit-tms/sync-storage-public/releases/download";
@@ -11,7 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const syncstorage_runner_1 = require("./syncstorage.runner");
13
13
  const child_process_1 = require("child_process");
14
- jest.mock("child_process", () => (Object.assign(Object.assign({}, jest.requireActual("child_process")), { spawn: jest.fn(() => ({})) })));
14
+ jest.mock("child_process", () => (Object.assign(Object.assign({}, jest.requireActual("child_process")), { spawn: jest.fn(() => ({ unref: jest.fn() })) })));
15
15
  const spawnMock = child_process_1.spawn;
16
16
  function makeConfig() {
17
17
  return {
@@ -28,30 +28,73 @@ describe("SyncStorageRunner", () => {
28
28
  beforeEach(() => {
29
29
  spawnMock.mockClear();
30
30
  delete process.env.TMS_DEBUG_SYNC_STORAGE;
31
+ delete process.env.SYNC_STORAGE_PORT_MAX_BUMP;
32
+ });
33
+ it("resolvePortAction: free / same / foreign / legacy", () => {
34
+ expect(syncstorage_runner_1.SyncStorageRunner.resolvePortAction(false, undefined, "run-b")).toBe("START_NEW");
35
+ expect(syncstorage_runner_1.SyncStorageRunner.resolvePortAction(true, "run-a", "run-a")).toBe("ATTACH");
36
+ expect(syncstorage_runner_1.SyncStorageRunner.resolvePortAction(true, "run-a", "run-b")).toBe("TRY_NEXT");
37
+ expect(syncstorage_runner_1.SyncStorageRunner.resolvePortAction(true, undefined, "run-b")).toBe("ATTACH");
38
+ });
39
+ it("parsePort defaults on bad input", () => {
40
+ expect(syncstorage_runner_1.SyncStorageRunner.parsePort(undefined, 49152)).toBe(49152);
41
+ expect(syncstorage_runner_1.SyncStorageRunner.parsePort("null", 49152)).toBe(49152);
42
+ expect(syncstorage_runner_1.SyncStorageRunner.parsePort("50000", 49152)).toBe(50000);
31
43
  });
32
44
  it("should spawn local process with stdio ignored", () => __awaiter(void 0, void 0, void 0, function* () {
33
45
  const runner = new syncstorage_runner_1.SyncStorageRunner("run-1", makeConfig());
34
46
  const internal = runner;
35
47
  internal.prepareExecutable = jest.fn().mockResolvedValue("/bin/syncstorage");
36
48
  internal.waitForStartup = jest.fn().mockResolvedValue(true);
49
+ internal.fetchHealthTestRunId = jest.fn().mockResolvedValue("run-1");
37
50
  internal.delay = jest.fn().mockResolvedValue(undefined);
38
- yield internal.startLocalProcess();
39
- expect(spawnMock).toHaveBeenCalledWith("/bin/syncstorage", expect.arrayContaining(["--testRunId", "run-1"]), expect.objectContaining({ stdio: "ignore" }));
51
+ yield internal.tryStartOwnedProcess();
52
+ expect(spawnMock).toHaveBeenCalledWith("/bin/syncstorage", expect.arrayContaining(["--testRunId", "run-1"]), expect.objectContaining({ stdio: "ignore", detached: true }));
40
53
  }));
41
54
  it("should mark runner as active and resolve master status after start", () => __awaiter(void 0, void 0, void 0, function* () {
42
55
  const runner = new syncstorage_runner_1.SyncStorageRunner("run-1", makeConfig());
43
56
  const internal = runner;
44
57
  internal.healthcheck = jest.fn().mockResolvedValue(true);
58
+ internal.fetchHealthTestRunId = jest.fn().mockResolvedValue("run-1");
45
59
  internal.workersApi = { registerPost: jest.fn().mockResolvedValue({ is_master: true }) };
46
60
  const started = yield runner.start();
47
61
  expect(started).toBe(true);
48
62
  expect(runner.isActive()).toBe(true);
49
63
  expect(runner.isMasterWorker()).toBe(true);
50
64
  }));
65
+ it("should bump port when preferred has foreign testRunId", () => __awaiter(void 0, void 0, void 0, function* () {
66
+ const runner = new syncstorage_runner_1.SyncStorageRunner("run-new", makeConfig());
67
+ const internal = runner;
68
+ internal.healthcheck = jest.fn().mockImplementation(() => __awaiter(void 0, void 0, void 0, function* () {
69
+ return internal.port === "49152";
70
+ }));
71
+ internal.fetchHealthTestRunId = jest.fn().mockImplementation(() => __awaiter(void 0, void 0, void 0, function* () {
72
+ return internal.port === "49152" ? "run-old" : undefined;
73
+ }));
74
+ internal.tryStartOwnedProcess = jest.fn().mockResolvedValue(true);
75
+ internal.tryRegister = jest.fn().mockResolvedValue(true);
76
+ const started = yield runner.start();
77
+ expect(started).toBe(true);
78
+ expect(internal.port).toBe("49153");
79
+ expect(internal.tryStartOwnedProcess).toHaveBeenCalled();
80
+ }));
81
+ it("should fail when all ports are busy with foreign testRunId", () => __awaiter(void 0, void 0, void 0, function* () {
82
+ const runner = new syncstorage_runner_1.SyncStorageRunner("run-new", makeConfig());
83
+ const internal = runner;
84
+ const bumpSpy = jest
85
+ .spyOn(syncstorage_runner_1.SyncStorageRunner, "resolvePortMaxBump")
86
+ .mockReturnValue(2);
87
+ internal.healthcheck = jest.fn().mockResolvedValue(true);
88
+ internal.fetchHealthTestRunId = jest.fn().mockResolvedValue("run-old");
89
+ const started = yield runner.start();
90
+ expect(started).toBe(false);
91
+ bumpSpy.mockRestore();
92
+ }));
51
93
  it("should send in-progress result only once", () => __awaiter(void 0, void 0, void 0, function* () {
52
94
  const runner = new syncstorage_runner_1.SyncStorageRunner("run-1", makeConfig());
53
95
  const internal = runner;
54
96
  internal.healthcheck = jest.fn().mockResolvedValue(true);
97
+ internal.fetchHealthTestRunId = jest.fn().mockResolvedValue("run-1");
55
98
  internal.workersApi = { registerPost: jest.fn().mockResolvedValue({ is_master: true }) };
56
99
  internal.testResultsApi = { inProgressTestResultPost: jest.fn().mockResolvedValue({ status: "ok" }) };
57
100
  internal.testResultCutModel = { constructFromObject: (obj) => obj };
@@ -77,6 +120,7 @@ describe("SyncStorageRunner", () => {
77
120
  const runner = new syncstorage_runner_1.SyncStorageRunner("run-1", makeConfig());
78
121
  const internal = runner;
79
122
  internal.healthcheck = jest.fn().mockResolvedValue(true);
123
+ internal.fetchHealthTestRunId = jest.fn().mockResolvedValue("run-1");
80
124
  internal.workersApi = { registerPost: jest.fn().mockResolvedValue({ is_master: true }) };
81
125
  internal.testResultsApi = { inProgressTestResultPost: jest.fn().mockResolvedValue({ status: "ok" }) };
82
126
  internal.testResultCutModel = { constructFromObject: (obj) => obj };
@@ -91,4 +135,24 @@ describe("SyncStorageRunner", () => {
91
135
  expect(ok).toBe(false);
92
136
  expect(internal.testResultsApi.inProgressTestResultPost).not.toHaveBeenCalled();
93
137
  }));
138
+ it("starts keep-alive after register and stops on completed", () => __awaiter(void 0, void 0, void 0, function* () {
139
+ const runner = new syncstorage_runner_1.SyncStorageRunner("run-1", makeConfig());
140
+ const internal = runner;
141
+ internal.healthcheck = jest.fn().mockResolvedValue(true);
142
+ internal.fetchHealthTestRunId = jest.fn().mockResolvedValue("run-1");
143
+ internal.workersApi = {
144
+ registerPost: jest.fn().mockResolvedValue({ is_master: true }),
145
+ setWorkerStatusPost: jest.fn().mockResolvedValue({}),
146
+ };
147
+ internal.setWorkerStatusRequestModel = { constructFromObject: (obj) => obj };
148
+ const startKa = jest.spyOn(internal, "startKeepAlive");
149
+ const stopKa = jest.spyOn(internal, "stopKeepAlive");
150
+ yield runner.start();
151
+ expect(startKa).toHaveBeenCalled();
152
+ yield runner.setWorkerStatus("completed");
153
+ expect(stopKa).toHaveBeenCalled();
154
+ }));
155
+ it("pins sync-storage to 0.4.x with keep_alive support", () => {
156
+ expect(syncstorage_runner_1.SyncStorageRunner.VERSION).toMatch(/^v0\.4\./);
157
+ });
94
158
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testit-js-commons",
3
- "version": "5.1.2",
3
+ "version": "5.1.3-TMS-6.0",
4
4
  "description": "JavaScript commons for Test IT",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",