Skip to content

Commit d7c33db

Browse files
authored
Merge pull request #186 from fireblocks/PIK-10232-timeout-and-pagination-guards
PIK-10232 fixed tmouts due to duplications and infinite loops in pagi…
2 parents 66d3bd0 + 4c0cbc1 commit d7c33db

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

v2/api-validator/src/client/SecureClient.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,9 @@ export class HttpRequestWithSecurityHeaders extends BaseHttpRequest {
168168
) {
169169
super(openAPIConfig);
170170

171-
this.axiosClient = axios.create();
171+
this.axiosClient = axios.create({
172+
timeout: 30000,
173+
});
172174

173175
this.axiosClient.interceptors.request.use((request) => {
174176
log.debug('Sending HTTP request', { request });

v2/api-validator/tests/server-tests/withdrawals.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ describe.skipIf(noTransfersCapability)('Withdrawals', () => {
9393
const accounts = await arrayFromAsyncGenerator(paginated(getAccounts));
9494
accountsMap = new Map<string, Account>();
9595
accounts.forEach((account) => accountsMap.set(account.id, account));
96-
});
96+
}, 60000);
9797

9898
describe('Capabilities', () => {
9999
it('should return only known assets in response', () => {
@@ -205,7 +205,7 @@ describe.skipIf(noTransfersCapability)('Withdrawals', () => {
205205
getSubAccountWithdrawals,
206206
transfersCapableAccountIds
207207
);
208-
});
208+
}, 60000);
209209

210210
it('should be sorted by creation time in a descending order', () => {
211211
const allWithdrawalResponses = [

v2/api-validator/tests/utils/pagination.ts

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,38 @@
11
import config from '../../src/config';
22

33
const LIMIT = config.get('paginationLimit');
4-
54
// Function supporting pagination
65
export type Pageable<T> = (limit: number, startingAfter?: string) => Promise<T[]>;
7-
86
/**
97
* Wraps a pageable function with a generator function, returning all the items
108
* one by one while automagically managing the pagination behind the scene.
119
*/
1210
export async function* paginated<T>(f: Pageable<T>, idPropName = 'id'): AsyncGenerator<T> {
13-
let page = await f(LIMIT);
14-
while (page.length > 0) {
15-
for (const item of page) {
11+
const MAX_PAGES = 1000;
12+
let pageCount = 0;
13+
let startingAfter: string | undefined;
14+
15+
while (pageCount < MAX_PAGES) {
16+
const currentPage = await f(LIMIT, startingAfter);
17+
18+
if (currentPage.length === 0) {
19+
break;
20+
}
21+
22+
pageCount++;
23+
24+
for (const item of currentPage) {
1625
yield item;
1726
}
18-
const startingAfter = page.at(-1)?.[idPropName];
19-
page = await f(LIMIT, startingAfter);
27+
28+
const lastItem = currentPage[currentPage.length - 1];
29+
const lastItemId = lastItem?.[idPropName];
30+
31+
if (!lastItemId || lastItemId === startingAfter) {
32+
break;
33+
}
34+
35+
startingAfter = lastItemId;
2036
}
2137
}
2238

0 commit comments

Comments
 (0)