mirror of
https://github.com/toeverything/AFFiNE.git
synced 2024-11-28 17:22:30 +03:00
test(server): fix flaky (#4088)
This commit is contained in:
parent
0f2223ddf0
commit
c937b88978
@ -36,15 +36,27 @@ test('should be able to increment counter', async () => {
|
||||
});
|
||||
|
||||
test('should be able to timer', async () => {
|
||||
const endTimer = metrics.socketIOEventTimer({ event: 'client-handshake' });
|
||||
await new Promise(resolve => setTimeout(resolve, 50));
|
||||
endTimer();
|
||||
let minimum: number;
|
||||
{
|
||||
const endTimer = metrics.socketIOEventTimer({ event: 'client-handshake' });
|
||||
const a = performance.now();
|
||||
await new Promise(resolve => setTimeout(resolve, 50));
|
||||
const b = performance.now();
|
||||
minimum = b - a;
|
||||
endTimer();
|
||||
}
|
||||
|
||||
const endTimer2 = metrics.socketIOEventTimer({ event: 'client-handshake' });
|
||||
await new Promise(resolve => setTimeout(resolve, 100));
|
||||
endTimer2();
|
||||
let maximum: number;
|
||||
{
|
||||
const a = performance.now();
|
||||
const endTimer = metrics.socketIOEventTimer({ event: 'client-handshake' });
|
||||
await new Promise(resolve => setTimeout(resolve, 100));
|
||||
endTimer();
|
||||
const b = performance.now();
|
||||
maximum = b - a;
|
||||
}
|
||||
|
||||
const socketIOTimerMetric = await register.getSingleMetric('socket_io_timer');
|
||||
const socketIOTimerMetric = register.getSingleMetric('socket_io_timer');
|
||||
ok(socketIOTimerMetric);
|
||||
|
||||
const observations = (await socketIOTimerMetric.get()).values;
|
||||
@ -54,8 +66,14 @@ test('should be able to timer', async () => {
|
||||
observation.labels.event === 'client-handshake' &&
|
||||
'quantile' in observation.labels
|
||||
) {
|
||||
ok(observation.value >= 0.05);
|
||||
ok(observation.value <= 0.2);
|
||||
ok(
|
||||
observation.value >= minimum / 1000,
|
||||
'observation.value should be greater than minimum'
|
||||
);
|
||||
ok(
|
||||
observation.value <= maximum / 1000,
|
||||
'observation.value should be less than maximum'
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -37,9 +37,14 @@ export const SettingPage: StoryFn = () => {
|
||||
};
|
||||
SettingPage.play = async ({ canvasElement, step }) => {
|
||||
const canvas = within(canvasElement);
|
||||
await waitFor(async () => {
|
||||
assertExists(canvasElement.querySelector('v-line'));
|
||||
});
|
||||
await waitFor(
|
||||
() => {
|
||||
assertExists(canvasElement.querySelector('v-line'));
|
||||
},
|
||||
{
|
||||
timeout: 10000,
|
||||
}
|
||||
);
|
||||
await step('click setting modal button', async () => {
|
||||
await userEvent.click(canvas.getByTestId('settings-modal-trigger'));
|
||||
});
|
||||
@ -111,9 +116,14 @@ export const SearchPage: StoryFn = () => {
|
||||
};
|
||||
SearchPage.play = async ({ canvasElement }) => {
|
||||
const canvas = within(canvasElement);
|
||||
await waitFor(async () => {
|
||||
assertExists(canvasElement.querySelector('v-line'));
|
||||
});
|
||||
await waitFor(
|
||||
() => {
|
||||
assertExists(canvasElement.querySelector('v-line'));
|
||||
},
|
||||
{
|
||||
timeout: 10000,
|
||||
}
|
||||
);
|
||||
await userEvent.click(canvas.getByTestId('slider-bar-quick-search-button'));
|
||||
};
|
||||
SearchPage.decorators = [withRouter];
|
||||
@ -131,9 +141,14 @@ export const ImportPage: StoryFn = () => {
|
||||
};
|
||||
ImportPage.play = async ({ canvasElement }) => {
|
||||
const canvas = within(canvasElement);
|
||||
await waitFor(() => {
|
||||
assertExists(canvasElement.querySelector('v-line'));
|
||||
});
|
||||
await waitFor(
|
||||
() => {
|
||||
assertExists(canvasElement.querySelector('v-line'));
|
||||
},
|
||||
{
|
||||
timeout: 10000,
|
||||
}
|
||||
);
|
||||
await waitFor(() => {
|
||||
assertExists(
|
||||
canvasElement.querySelector('[data-testid="header-dropDownButton"]')
|
||||
@ -165,7 +180,7 @@ OpenAppPage.parameters = {
|
||||
reactRouter: reactRouterParameters({
|
||||
routing: reactRouterOutlets(routes),
|
||||
location: {
|
||||
path: '/open-app',
|
||||
path: '/open-app/url',
|
||||
searchParams: {
|
||||
url: 'affine-beta://foo-bar.com',
|
||||
open: 'false',
|
||||
|
Loading…
Reference in New Issue
Block a user