Skip to content

Commit 367cacf

Browse files
committed
refactor(tests): replace fixed wait with polling in internal metrics test
- Updated the internal metrics test for anonymous users to utilize a polling mechanism instead of a fixed wait time, improving reliability in asynchronous data verification. - The new approach ensures that the test accurately checks for user activity and metrics without relying on arbitrary delays.
1 parent 6c3c1f2 commit 367cacf

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

apps/e2e/tests/backend/endpoints/api/v1/internal-metrics.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,11 @@ it("should handle anonymous users with activity correctly", async ({ expect }) =
297297
await Auth.Anonymous.signUp();
298298
}
299299

300-
await wait(3000); // the event log is async, so let's give it some time to be written to the DB
301-
302-
const response = await niceBackendFetch("/api/v1/internal/metrics", { accessType: 'admin' });
300+
const response = await waitForMetricsMatch(false, (r) => {
301+
if (r.body?.total_users !== 1) return false;
302+
const dau = r.body?.daily_active_users?.[r.body.daily_active_users.length - 1];
303+
return dau?.activity === 1 && r.body?.users_by_country?.["CA"] === 1;
304+
});
303305

304306
// Should only count 1 regular user
305307
expect(response.body.total_users).toBe(1);

0 commit comments

Comments
 (0)