Skip to content

Commit 90f5efc

Browse files
committed
test: enhance E2E tests for stream routes with timeout adjustments
1 parent 70b8c7d commit 90f5efc

File tree

2 files changed

+41
-19
lines changed

2 files changed

+41
-19
lines changed

e2e/pom/stream_routes.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,30 @@ const locator = {
2424

2525
const assert = {
2626
isIndexPage: async (page: Page) => {
27-
await expect(page).toHaveURL((url) =>
28-
url.pathname.endsWith('/stream_routes')
27+
await expect(page).toHaveURL(
28+
(url) => url.pathname.endsWith('/stream_routes'),
29+
{ timeout: 15000 }
2930
);
3031
const title = page.getByRole('heading', { name: 'Stream Routes' });
31-
await expect(title).toBeVisible();
32+
await expect(title).toBeVisible({ timeout: 15000 });
3233
},
3334
isAddPage: async (page: Page) => {
34-
await expect(page).toHaveURL((url) =>
35-
url.pathname.endsWith('/stream_routes/add')
36-
);
35+
await expect(
36+
page,
37+
{ timeout: 15000 }
38+
).toHaveURL((url) => url.pathname.endsWith('/stream_routes/add'));
3739
const title = page.getByRole('heading', { name: 'Add Stream Route' });
38-
await expect(title).toBeVisible();
40+
await expect(title).toBeVisible({ timeout: 15000 });
3941
},
4042
isDetailPage: async (page: Page) => {
41-
await expect(page).toHaveURL((url) =>
42-
url.pathname.includes('/stream_routes/detail')
43-
);
43+
await expect(
44+
page,
45+
{ timeout: 20000 }
46+
).toHaveURL((url) => url.pathname.includes('/stream_routes/detail'));
4447
const title = page.getByRole('heading', {
4548
name: 'Stream Route Detail',
4649
});
47-
await expect(title).toBeVisible();
50+
await expect(title).toBeVisible({ timeout: 20000 });
4851
},
4952
};
5053

src/apis/upstreams.ts

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,36 @@ export const putUpstreamReq = (
5555
};
5656

5757
export const deleteAllUpstreams = async (req: AxiosInstance) => {
58-
const totalRes = await getUpstreamListReq(req, {
59-
page: 1,
60-
page_size: PAGE_SIZE_MIN,
61-
});
58+
const retry = async <T>(fn: () => Promise<T>, times = 3, delay = 500) => {
59+
let lastErr: unknown;
60+
for (let i = 0; i < times; i++) {
61+
try {
62+
return await fn();
63+
} catch (err) {
64+
lastErr = err;
65+
// small backoff
66+
67+
await new Promise((r) => setTimeout(r, delay));
68+
}
69+
}
70+
throw lastErr;
71+
};
72+
73+
const totalRes = await retry(() =>
74+
getUpstreamListReq(req, {
75+
page: 1,
76+
page_size: PAGE_SIZE_MIN,
77+
})
78+
);
6279
const total = totalRes.total;
6380
if (total === 0) return;
6481
for (let times = Math.ceil(total / PAGE_SIZE_MAX); times > 0; times--) {
65-
const res = await getUpstreamListReq(req, {
66-
page: 1,
67-
page_size: PAGE_SIZE_MAX,
68-
});
82+
const res = await retry(() =>
83+
getUpstreamListReq(req, {
84+
page: 1,
85+
page_size: PAGE_SIZE_MAX,
86+
})
87+
);
6988
await Promise.all(
7089
res.list.map((d) => req.delete(`${API_UPSTREAMS}/${d.value.id}`))
7190
);

0 commit comments

Comments
 (0)