Skip to content

Commit 4310c4c

Browse files
committed
Add some delays to prevent rate limiting
1 parent 401bb32 commit 4310c4c

File tree

1 file changed

+29
-24
lines changed

1 file changed

+29
-24
lines changed

tests/integration/pagination.serial.test.ts

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import {
77
newTestUuid,
88
} from "./helpers";
99

10+
// Add a sleep helper function
11+
const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));
12+
1013
type TestClient = Customers | Catalog;
1114

1215
describe("Pagination", () => {
@@ -29,11 +32,11 @@ describe("Pagination", () => {
2932
perPage: 1,
3033
greaterThan: 4,
3134
async setup() {
32-
await Promise.all(
33-
Array(5)
34-
.fill(null)
35-
.map(() => createTestCustomer(client)),
36-
);
35+
// Add sequential processing with delays instead of Promise.all
36+
for (let i = 0; i < 5; i++) {
37+
await createTestCustomer(client);
38+
await sleep(1000); // Wait 1 second between customer creations
39+
}
3740
},
3841
},
3942
{
@@ -42,23 +45,21 @@ describe("Pagination", () => {
4245
limit: 5,
4346
greaterThan: 4,
4447
async setup() {
45-
await Promise.all(
46-
Array(5)
47-
.fill(null)
48-
.map(() => createTestCatalogItem())
49-
.map((item) =>
50-
client.catalog.object.upsert(
51-
{
52-
idempotencyKey: newTestUuid(),
53-
object: item,
54-
},
55-
{
56-
maxRetries: 5,
57-
timeoutInSeconds: 60,
58-
},
59-
),
60-
),
61-
);
48+
// Create items sequentially with delays instead of in parallel
49+
for (let i = 0; i < 5; i++) {
50+
const item = createTestCatalogItem();
51+
await client.catalog.object.upsert(
52+
{
53+
idempotencyKey: newTestUuid(),
54+
object: item,
55+
},
56+
{
57+
maxRetries: 5,
58+
timeoutInSeconds: 60,
59+
},
60+
);
61+
await sleep(2000); // Wait 2 seconds between catalog operations
62+
}
6263
},
6364
},
6465
];
@@ -93,6 +94,7 @@ describe("Pagination", () => {
9394
break;
9495
}
9596

97+
await sleep(1000); // Add delay before fetching next page
9698
currentPage = await currentPage.getNextPage();
9799
}
98100

@@ -113,6 +115,7 @@ describe("Pagination", () => {
113115

114116
let count = pager.data.length;
115117
while (pager.hasNextPage()) {
118+
await sleep(1000); // Add delay before fetching next page
116119
await pager.getNextPage();
117120
count += pager.data.length;
118121

@@ -132,17 +135,19 @@ describe("Pagination", () => {
132135
await setup();
133136
}
134137

138+
// Add delay between iterator and pager tests
135139
const iteratorCount = await testIterator({ client, limit, params: { ...params } });
140+
await sleep(2000); // Wait 2 seconds between major operations
136141
const pagerCount = await testPager({ client, limit, params: { ...params } });
142+
137143
expect(iteratorCount).toBeGreaterThan(greaterThan);
138144
expect(pagerCount).toBeGreaterThan(greaterThan);
139145

140146
if (perPage != null) {
141-
// Confirm iterator and pager return same count.
142147
expect(pagerCount).toEqual(iteratorCount);
143148
}
144149
},
145150
60_000,
146151
);
147152
});
148-
});
153+
});

0 commit comments

Comments
 (0)