From 770fc252348dc6e137771dcdad1903ad165d5c63 Mon Sep 17 00:00:00 2001 From: AliakseiLiasnitski Date: Fri, 16 Feb 2024 17:33:15 +0300 Subject: [PATCH 1/4] EPMRPP-82648 || Fix execution sequence for retry tests --- lib/report-portal-client.js | 49 +++++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 13 deletions(-) diff --git a/lib/report-portal-client.js b/lib/report-portal-client.js index 888165c..229654c 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.executableItemMap = new Map(); + this.executableItemKeyMapByTempId = new Map(); } // eslint-disable-next-line valid-jsdoc @@ -67,10 +68,32 @@ class RPClient { } } - calculateNonRetriedItemMapKey(launchId, parentId, name, itemId = '') { + calculateExecutableItemMapKey(launchId, parentId, name, itemId = '') { return `${launchId}__${parentId}__${name}__${itemId}`; } + // eslint-disable-next-line valid-jsdoc + /** + * + * @Private + */ + cleanExecutableItemKeyMapByTempId(ids) { + ids.forEach((id) => { + this.executableItemKeyMapByTempId.delete(id); + }); + } + + // eslint-disable-next-line valid-jsdoc + /** + * + * @Private + */ + cleanExecutableItemMap(ids) { + ids.forEach((id) => { + this.executableItemMap.delete(id); + }); + } + getUniqId() { return UniqId(); } @@ -488,20 +511,17 @@ class RPClient { parentPromise = parentObj.promiseStart; } - const itemKey = this.calculateNonRetriedItemMapKey( + const itemKey = this.calculateExecutableItemMapKey( 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.executableItemMap.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 +535,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 +550,8 @@ class RPClient { ); }); this.map[parentMapId].children.push(tempId); - - if (!testItemDataRQ.retry) { - this.nonRetriedItemMap.set(itemKey, this.map[tempId].promiseStart); - } + this.executableItemKeyMapByTempId.set(tempId, itemKey); + this.executableItemMap.set(itemKey, this.map[tempId].promiseStart); return { tempId, @@ -603,6 +620,12 @@ class RPClient { }); } + const executableItemKeys = itemObj.children.map((tempId) => + this.executableItemKeyMapByTempId.get(tempId), + ); + + this.cleanExecutableItemMap(executableItemKeys); + this.cleanExecutableItemKeyMapByTempId(itemObj.children); this.cleanMap(itemObj.children); this.logDebug(`Finish test item with tempId ${itemTempId}`, finishTestItemRQ); From 1ea1f7551abf3885c78b873f3bb353fa1b854724 Mon Sep 17 00:00:00 2001 From: AliakseiLiasnitski Date: Mon, 19 Feb 2024 14:41:09 +0300 Subject: [PATCH 2/4] EPMRPP-82648 || update tests --- spec/report-portal-client.spec.js | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/spec/report-portal-client.spec.js b/spec/report-portal-client.spec.js index 54db15f..fbf51c0 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('calculateExecutableItemMapKey', () => { 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.calculateExecutableItemMapKey('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.calculateExecutableItemMapKey('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.executableItemMap, '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 executableItemMap 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, 'calculateExecutableItemMapKey').and.returnValue('id1__name__'); spyOn(client, 'getUniqId').and.returnValue('4n5pxq24kpiob12og9'); spyOn(client.map['4n5pxq24kpiob12og9'], 'promiseStart').and.resolveTo(); - spyOn(client.nonRetriedItemMap, 'set'); + spyOn(client.executableItemMap, 'get'); - client.startTestItem({ retry: false }, 'id1'); + client.startTestItem({ retry: true }, 'id1'); - expect(client.nonRetriedItemMap.set).toHaveBeenCalledWith( - 'id1__name__', - client.map['4n5pxq24kpiob12og9'].promiseStart, - ); + expect(client.executableItemMap.get).toHaveBeenCalledWith('id1__name__'); }); }); From 3481a7e134e920544d6575c13e2f609ced5ebc77 Mon Sep 17 00:00:00 2001 From: AliakseiLiasnitski Date: Tue, 20 Feb 2024 15:23:14 +0300 Subject: [PATCH 3/4] EPMRPP-82648 || Remove duplicates in executableItemKeys --- lib/report-portal-client.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/report-portal-client.js b/lib/report-portal-client.js index 229654c..e8fc193 100644 --- a/lib/report-portal-client.js +++ b/lib/report-portal-client.js @@ -620,8 +620,8 @@ class RPClient { }); } - const executableItemKeys = itemObj.children.map((tempId) => - this.executableItemKeyMapByTempId.get(tempId), + const executableItemKeys = Array.from( + new Set(itemObj.children.map((tempId) => this.executableItemKeyMapByTempId.get(tempId))), ); this.cleanExecutableItemMap(executableItemKeys); From 5bcb92c3bf76973ce58c1660c797a20345728519 Mon Sep 17 00:00:00 2001 From: AliakseiLiasnitski Date: Tue, 20 Feb 2024 16:59:56 +0300 Subject: [PATCH 4/4] EPMRPP-82648 || rename map name --- lib/report-portal-client.js | 43 ++++++++++++------------------- spec/report-portal-client.spec.js | 16 ++++++------ 2 files changed, 24 insertions(+), 35 deletions(-) diff --git a/lib/report-portal-client.js b/lib/report-portal-client.js index e8fc193..659294b 100644 --- a/lib/report-portal-client.js +++ b/lib/report-portal-client.js @@ -53,8 +53,8 @@ class RPClient { }); this.statistics = new Statistics(EVENT_NAME, agentParams); this.launchUuid = ''; - this.executableItemMap = new Map(); - this.executableItemKeyMapByTempId = new Map(); + this.itemRetriesChainMap = new Map(); + this.itemRetriesChainKeyMapByTempId = new Map(); } // eslint-disable-next-line valid-jsdoc @@ -68,7 +68,7 @@ class RPClient { } } - calculateExecutableItemMapKey(launchId, parentId, name, itemId = '') { + calculateItemRetriesChainMapKey(launchId, parentId, name, itemId = '') { return `${launchId}__${parentId}__${name}__${itemId}`; } @@ -77,20 +77,15 @@ class RPClient { * * @Private */ - cleanExecutableItemKeyMapByTempId(ids) { - ids.forEach((id) => { - this.executableItemKeyMapByTempId.delete(id); - }); - } + cleanItemRetriesChain(tempIds) { + tempIds.forEach((id) => { + const key = this.itemRetriesChainKeyMapByTempId.get(id); - // eslint-disable-next-line valid-jsdoc - /** - * - * @Private - */ - cleanExecutableItemMap(ids) { - ids.forEach((id) => { - this.executableItemMap.delete(id); + if (key) { + this.itemRetriesChainMap.delete(key); + } + + this.itemRetriesChainKeyMapByTempId.delete(id); }); } @@ -511,13 +506,13 @@ class RPClient { parentPromise = parentObj.promiseStart; } - const itemKey = this.calculateExecutableItemMapKey( + const itemKey = this.calculateItemRetriesChainMapKey( launchTempId, parentTempId, testItemDataRQ.name, testItemDataRQ.uniqueId, ); - const executionItemPromise = testItemDataRQ.retry && this.executableItemMap.get(itemKey); + const executionItemPromise = testItemDataRQ.retry && this.itemRetriesChainMap.get(itemKey); const tempId = this.getUniqId(); this.map[tempId] = this.getNewItemObj((resolve, reject) => { @@ -550,8 +545,8 @@ class RPClient { ); }); this.map[parentMapId].children.push(tempId); - this.executableItemKeyMapByTempId.set(tempId, itemKey); - this.executableItemMap.set(itemKey, this.map[tempId].promiseStart); + this.itemRetriesChainKeyMapByTempId.set(tempId, itemKey); + this.itemRetriesChainMap.set(itemKey, this.map[tempId].promiseStart); return { tempId, @@ -619,13 +614,7 @@ class RPClient { } }); } - - const executableItemKeys = Array.from( - new Set(itemObj.children.map((tempId) => this.executableItemKeyMapByTempId.get(tempId))), - ); - - this.cleanExecutableItemMap(executableItemKeys); - this.cleanExecutableItemKeyMapByTempId(itemObj.children); + 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 fbf51c0..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('calculateExecutableItemMapKey', () => { + 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.calculateExecutableItemMapKey('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.calculateExecutableItemMapKey('lId', 'pId', 'name'); + const str = client.calculateItemRetriesChainMapKey('lId', 'pId', 'name'); expect(str).toEqual('lId__pId__name__'); }); @@ -725,7 +725,7 @@ describe('ReportPortal javascript client', () => { promiseStart: Promise.resolve(), }, }; - spyOn(client.executableItemMap, 'get').and.resolveTo(); + spyOn(client.itemRetriesChainMap, 'get').and.resolveTo(); spyOn(client.restClient, 'create').and.resolveTo({}); spyOn(client, 'getUniqId').and.returnValue('4n5pxq24kpiob12og9'); @@ -735,7 +735,7 @@ describe('ReportPortal javascript client', () => { return expectAsync(result.promise).toBeResolved(); }); - it('should get previous try promise from executableItemMap if retry is true', () => { + 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,14 +754,14 @@ describe('ReportPortal javascript client', () => { promiseStart: Promise.resolve(), }, }; - spyOn(client, 'calculateExecutableItemMapKey').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.executableItemMap, 'get'); + spyOn(client.itemRetriesChainMap, 'get'); client.startTestItem({ retry: true }, 'id1'); - expect(client.executableItemMap.get).toHaveBeenCalledWith('id1__name__'); + expect(client.itemRetriesChainMap.get).toHaveBeenCalledWith('id1__name__'); }); });