Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EPMRPP-82648 || Fix execution sequence for retry tests #192

Merged
merged 4 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading