Merge pull request #34444 from backstage/freben/fix-ci-timing-flakes

fix: increase timing thresholds in CI-flaky database tests
This commit is contained in:
Fredrik Adelöw
2026-05-29 17:36:39 +02:00
committed by GitHub
2 changed files with 11 additions and 9 deletions
@@ -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' },