Skip to content

Commit

Permalink
EPMRPP-82648 || rename map name
Browse files Browse the repository at this point in the history
  • Loading branch information
AliakseiLiasnitski committed Feb 20, 2024
1 parent 3481a7e commit 5bcb92c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 35 deletions.
43 changes: 16 additions & 27 deletions lib/report-portal-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -68,7 +68,7 @@ class RPClient {
}
}

calculateExecutableItemMapKey(launchId, parentId, name, itemId = '') {
calculateItemRetriesChainMapKey(launchId, parentId, name, itemId = '') {
return `${launchId}__${parentId}__${name}__${itemId}`;
}

Expand All @@ -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);
});
}

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

Expand All @@ -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',
Expand All @@ -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__');
});
});

Expand Down

0 comments on commit 5bcb92c

Please sign in to comment.