fix: fix CI-flaky database test timing
DatabaseEventBusStore: 500ms → 2000ms for the performance threshold when cleaning 100k rows — this is intentionally a perf test so a real time assertion is correct, it just needs more headroom for CI. DatabaseKeyStore: replace fixed 500ms sleep with waitForExpect polling so the test adapts to however long the async deletion actually takes. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
@@ -19,6 +19,7 @@ import {
|
||||
TestDatabases,
|
||||
mockServices,
|
||||
} from '@backstage/backend-test-utils';
|
||||
import waitForExpect from 'wait-for-expect';
|
||||
import { DatabaseKeyStore, TABLE } from './DatabaseKeyStore';
|
||||
|
||||
const testKey = {
|
||||
@@ -104,12 +105,13 @@ describe('DatabaseKeyStore', () => {
|
||||
"Removing expired plugin service keys, 'test-key-2'",
|
||||
);
|
||||
|
||||
// Key deletion happens async, so give it a bit of time to complete
|
||||
await new Promise(resolve => setTimeout(resolve, 500));
|
||||
|
||||
await expect(knex(TABLE).select('id')).resolves.toEqual([
|
||||
{ id: testKey.kid },
|
||||
]);
|
||||
// Key deletion happens async — poll until it completes rather than
|
||||
// relying on a fixed sleep that can flake in slow CI environments.
|
||||
await waitForExpect(async () => {
|
||||
await expect(knex(TABLE).select('id')).resolves.toEqual([
|
||||
{ id: testKey.kid },
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
it('should fail to insert with invalid date', async () => {
|
||||
|
||||
@@ -178,9 +178,9 @@ describe.each(databases.eachSupportedId())(
|
||||
|
||||
await store.clean();
|
||||
|
||||
// Local testing shows this takes about 80ms, but if this is flaky we can
|
||||
// reduce the count down to 10_000.
|
||||
expect(Date.now() - start).toBeLessThan(500);
|
||||
// Local testing shows this takes about 80ms, but CI containers can
|
||||
// be significantly slower under load.
|
||||
expect(Date.now() - start).toBeLessThan(2000);
|
||||
|
||||
await expect(db('event_bus_events').count()).resolves.toEqual([
|
||||
{ count: '5' },
|
||||
|
||||
Reference in New Issue
Block a user