diff --git a/lib/report-portal-client.js b/lib/report-portal-client.js index 888165c..659294b 100644 --- a/lib/report-portal-client.js +++ b/lib/report-portal-client.js @@ -53,7 +53,8 @@ class RPClient { }); this.statistics = new Statistics(EVENT_NAME, agentParams); this.launchUuid = ''; - this.nonRetriedItemMap = new Map(); + this.itemRetriesChainMap = new Map(); + this.itemRetriesChainKeyMapByTempId = new Map(); } // eslint-disable-next-line valid-jsdoc @@ -67,10 +68,27 @@ class RPClient { } } - calculateNonRetriedItemMapKey(launchId, parentId, name, itemId = '') { + calculateItemRetriesChainMapKey(launchId, parentId, name, itemId = '') { return `${launchId}__${parentId}__${name}__${itemId}`; } + // eslint-disable-next-line valid-jsdoc + /** + * + * @Private + */ + cleanItemRetriesChain(tempIds) { + tempIds.forEach((id) => { + const key = this.itemRetriesChainKeyMapByTempId.get(id); + + if (key) { + this.itemRetriesChainMap.delete(key); + } + + this.itemRetriesChainKeyMapByTempId.delete(id); + }); + } + getUniqId() { return UniqId(); } @@ -488,20 +506,17 @@ class RPClient { parentPromise = parentObj.promiseStart; } - const itemKey = this.calculateNonRetriedItemMapKey( + const itemKey = this.calculateItemRetriesChainMapKey( launchTempId, parentTempId, testItemDataRQ.name, testItemDataRQ.uniqueId, ); - const firstNonRetriedItemPromise = testItemDataRQ.retry && this.nonRetriedItemMap.get(itemKey); - if (firstNonRetriedItemPromise) { - parentPromise = Promise.all([parentPromise, firstNonRetriedItemPromise]); - } + const executionItemPromise = testItemDataRQ.retry && this.itemRetriesChainMap.get(itemKey); const tempId = this.getUniqId(); this.map[tempId] = this.getNewItemObj((resolve, reject) => { - parentPromise.then( + (executionItemPromise || parentPromise).then( () => { const realLaunchId = this.map[launchTempId].realId; let url = 'item/'; @@ -515,7 +530,6 @@ class RPClient { (response) => { this.logDebug(`Success start item with tempId ${tempId}`, response); this.map[tempId].realId = response.id; - this.nonRetriedItemMap.delete(itemKey); resolve(response); }, (error) => { @@ -531,10 +545,8 @@ class RPClient { ); }); this.map[parentMapId].children.push(tempId); - - if (!testItemDataRQ.retry) { - this.nonRetriedItemMap.set(itemKey, this.map[tempId].promiseStart); - } + this.itemRetriesChainKeyMapByTempId.set(tempId, itemKey); + this.itemRetriesChainMap.set(itemKey, this.map[tempId].promiseStart); return { tempId, @@ -602,7 +614,7 @@ class RPClient { } }); } - + this.cleanItemRetriesChain(itemObj.children); this.cleanMap(itemObj.children); this.logDebug(`Finish test item with tempId ${itemTempId}`, finishTestItemRQ); diff --git a/spec/report-portal-client.spec.js b/spec/report-portal-client.spec.js index 54db15f..787d1a1 100644 --- a/spec/report-portal-client.spec.js +++ b/spec/report-portal-client.spec.js @@ -63,7 +63,7 @@ describe('ReportPortal javascript client', () => { }); }); - describe('calculateNonRetriedItemMapKey', () => { + describe('calculateItemRetriesChainMapKey', () => { it("should return correct parameter's string", () => { const client = new RPClient({ apiKey: 'test', @@ -71,7 +71,7 @@ describe('ReportPortal javascript client', () => { endpoint: 'https://abc.com', }); - const str = client.calculateNonRetriedItemMapKey('lId', 'pId', 'name', 'itemId'); + const str = client.calculateItemRetriesChainMapKey('lId', 'pId', 'name', 'itemId'); expect(str).toEqual('lId__pId__name__itemId'); }); @@ -83,7 +83,7 @@ describe('ReportPortal javascript client', () => { endpoint: 'https://abc.com', }); - const str = client.calculateNonRetriedItemMapKey('lId', 'pId', 'name'); + const str = client.calculateItemRetriesChainMapKey('lId', 'pId', 'name'); expect(str).toEqual('lId__pId__name__'); }); @@ -725,17 +725,17 @@ describe('ReportPortal javascript client', () => { promiseStart: Promise.resolve(), }, }; - spyOn(client.nonRetriedItemMap, 'get').and.resolveTo(); + spyOn(client.itemRetriesChainMap, 'get').and.resolveTo(); spyOn(client.restClient, 'create').and.resolveTo({}); spyOn(client, 'getUniqId').and.returnValue('4n5pxq24kpiob12og9'); - const result = client.startTestItem({ retry: true }, 'id1', 'id'); + const result = client.startTestItem({ retry: false }, 'id1', 'id'); expect(result.tempId).toEqual('4n5pxq24kpiob12og9'); return expectAsync(result.promise).toBeResolved(); }); - it('should call nonRetriedItemMap if retry is false', () => { + it('should get previous try promise from itemRetriesChainMap if retry is true', () => { const client = new RPClient({ apiKey: 'startLaunchTest', endpoint: 'https://rp.us/api/v1', @@ -754,17 +754,14 @@ describe('ReportPortal javascript client', () => { promiseStart: Promise.resolve(), }, }; - spyOn(client, 'calculateNonRetriedItemMapKey').and.returnValue('id1__name__'); + spyOn(client, 'calculateItemRetriesChainMapKey').and.returnValue('id1__name__'); spyOn(client, 'getUniqId').and.returnValue('4n5pxq24kpiob12og9'); spyOn(client.map['4n5pxq24kpiob12og9'], 'promiseStart').and.resolveTo(); - spyOn(client.nonRetriedItemMap, 'set'); + spyOn(client.itemRetriesChainMap, 'get'); - client.startTestItem({ retry: false }, 'id1'); + client.startTestItem({ retry: true }, 'id1'); - expect(client.nonRetriedItemMap.set).toHaveBeenCalledWith( - 'id1__name__', - client.map['4n5pxq24kpiob12og9'].promiseStart, - ); + expect(client.itemRetriesChainMap.get).toHaveBeenCalledWith('id1__name__'); }); });