Skip to content

Commit

Permalink
EPMRPP-82648 || Fix execution sequence for retry tests (#192)
Browse files Browse the repository at this point in the history
* EPMRPP-82648 || Fix execution sequence for retry tests

* EPMRPP-82648 || update tests

* EPMRPP-82648 || Remove duplicates in executableItemKeys

* EPMRPP-82648 || rename map name
  • Loading branch information
AliakseiLiasnitski authored Feb 20, 2024
1 parent 5c841ca commit 7ae3a6f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 27 deletions.
40 changes: 26 additions & 14 deletions lib/report-portal-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
}
Expand Down Expand Up @@ -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/';
Expand All @@ -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) => {
Expand All @@ -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,
Expand Down Expand Up @@ -602,7 +614,7 @@ class RPClient {
}
});
}

this.cleanItemRetriesChain(itemObj.children);
this.cleanMap(itemObj.children);

this.logDebug(`Finish test item with tempId ${itemTempId}`, finishTestItemRQ);
Expand Down
23 changes: 10 additions & 13 deletions spec/report-portal-client.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ describe('ReportPortal javascript client', () => {
});
});

describe('calculateNonRetriedItemMapKey', () => {
describe('calculateItemRetriesChainMapKey', () => {
it("should return correct parameter's string", () => {
const client = new RPClient({
apiKey: 'test',
project: 'test',
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');
});
Expand All @@ -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__');
});
Expand Down Expand Up @@ -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',
Expand All @@ -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__');
});
});

Expand Down

0 comments on commit 7ae3a6f

Please sign in to comment.