qase-javascript-commons 2.2.11 → 2.2.12

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.
package/changelog.md CHANGED
@@ -1,3 +1,10 @@
1
+ # qase-javascript-commons@2.2.12
2
+
3
+ ## What's new
4
+
5
+ Added a mutex to ensure correct result submission when running tests in multiple threads, preventing potential
6
+ duplication.
7
+
1
8
  # qase-javascript-commons@2.2.11
2
9
 
3
10
  ## What's new
@@ -102,6 +102,7 @@ export declare class TestOpsReporter extends AbstractReporter {
102
102
  * @private
103
103
  */
104
104
  private isTestRunReady;
105
+ private mutex;
105
106
  /**
106
107
  * @param {LoggerInterface} logger
107
108
  * @param {ReporterOptionsType & TestOpsOptionsType} options
@@ -12,6 +12,7 @@ const models_1 = require("../models");
12
12
  const qase_error_1 = require("../utils/qase-error");
13
13
  const axios_1 = __importDefault(require("axios"));
14
14
  const state_1 = require("../state/state");
15
+ const async_mutex_1 = require("async-mutex");
15
16
  const defaultChunkSize = 200;
16
17
  /**
17
18
  * @class TestOpsReporter
@@ -109,6 +110,7 @@ class TestOpsReporter extends abstract_reporter_1.AbstractReporter {
109
110
  * @private
110
111
  */
111
112
  isTestRunReady = false;
113
+ mutex = new async_mutex_1.Mutex();
112
114
  /**
113
115
  * @param {LoggerInterface} logger
114
116
  * @param {ReporterOptionsType & TestOpsOptionsType} options
@@ -151,15 +153,21 @@ class TestOpsReporter extends abstract_reporter_1.AbstractReporter {
151
153
  this.showLink(id, result.title);
152
154
  }
153
155
  }
154
- await super.addTestResult(result);
155
- if (!this.isTestRunReady) {
156
- return;
156
+ const release = await this.mutex.acquire();
157
+ try {
158
+ await super.addTestResult(result);
159
+ if (!this.isTestRunReady) {
160
+ return;
161
+ }
162
+ const countOfResults = this.batchSize + this.firstIndex;
163
+ if (this.results.length >= countOfResults) {
164
+ const firstIndex = this.firstIndex;
165
+ this.firstIndex = countOfResults;
166
+ await this.publishResults(this.results.slice(firstIndex, countOfResults));
167
+ }
157
168
  }
158
- const countOfResults = this.batchSize + this.firstIndex;
159
- if (this.results.length >= countOfResults) {
160
- const firstIndex = this.firstIndex;
161
- this.firstIndex = countOfResults;
162
- await this.publishResults(this.results.slice(firstIndex, countOfResults));
169
+ finally {
170
+ release();
163
171
  }
164
172
  }
165
173
  /**
@@ -238,7 +246,13 @@ class TestOpsReporter extends abstract_reporter_1.AbstractReporter {
238
246
  * @returns {Promise<void>}
239
247
  */
240
248
  async publish() {
241
- await this.sendResults();
249
+ const release = await this.mutex.acquire();
250
+ try {
251
+ await this.sendResults();
252
+ }
253
+ finally {
254
+ release();
255
+ }
242
256
  await this.complete();
243
257
  }
244
258
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qase-javascript-commons",
3
- "version": "2.2.11",
3
+ "version": "2.2.12",
4
4
  "description": "Qase JS Reporters",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -34,7 +34,8 @@
34
34
  "mime-types": "^2.1.33",
35
35
  "qaseio": "~2.4.0",
36
36
  "strip-ansi": "^6.0.1",
37
- "uuid": "^9.0.0"
37
+ "uuid": "^9.0.0",
38
+ "async-mutex": "~0.5.0"
38
39
  },
39
40
  "devDependencies": {
40
41
  "@jest/globals": "^29.5.0",