attempt test fixes

This commit is contained in:
Bilal Godil 2026-01-30 14:22:02 -08:00
parent bd788b4761
commit 4b7dd53bf8
9 changed files with 41 additions and 2 deletions

View File

@ -19,6 +19,7 @@ jobs:
NODE_ENV: test
STACK_ENABLE_HARDCODED_PASSKEY_CHALLENGE_FOR_TESTING: yes
STACK_DATABASE_CONNECTION_STRING: "postgres://postgres:PASSWORD-PLACEHOLDER--uqfEC1hmmv@localhost:8128/stackframe"
STACK_FORCE_EXTERNAL_DB_SYNC: "true"
strategy:
matrix:

View File

@ -19,6 +19,7 @@ jobs:
STACK_ENABLE_HARDCODED_PASSKEY_CHALLENGE_FOR_TESTING: yes
STACK_DATABASE_CONNECTION_STRING: "postgres://postgres:PASSWORD-PLACEHOLDER--uqfEC1hmmv@localhost:6728/stackframe"
NEXT_PUBLIC_STACK_PORT_PREFIX: "67"
STACK_FORCE_EXTERNAL_DB_SYNC: "true"
strategy:
matrix:

View File

@ -21,6 +21,7 @@ jobs:
STACK_OVERRIDE_SOURCE_OF_TRUTH: '{"type": "postgres", "connectionString": "postgres://postgres:PASSWORD-PLACEHOLDER--uqfEC1hmmv@localhost:8128/source-of-truth-db?schema=sot-schema"}'
STACK_TEST_SOURCE_OF_TRUTH: true
STACK_DATABASE_CONNECTION_STRING: "postgres://postgres:PASSWORD-PLACEHOLDER--uqfEC1hmmv@localhost:8128/stackframe"
STACK_FORCE_EXTERNAL_DB_SYNC: "true"
strategy:
matrix:

View File

@ -19,6 +19,7 @@ jobs:
runs-on: ubicloud-standard-16
env:
NEXT_PUBLIC_STACK_PORT_PREFIX: "69"
STACK_FORCE_EXTERNAL_DB_SYNC: "true"
steps:
- uses: actions/checkout@v6

View File

@ -17,6 +17,8 @@ env:
jobs:
restart-dev-and-test:
runs-on: ubicloud-standard-16
env:
STACK_FORCE_EXTERNAL_DB_SYNC: "true"
steps:
- uses: actions/checkout@v6

View File

@ -19,6 +19,7 @@ jobs:
runs-on: ubicloud-standard-16
env:
NEXT_PUBLIC_STACK_PORT_PREFIX: "69"
STACK_FORCE_EXTERNAL_DB_SYNC: "true"
steps:
- uses: actions/checkout@v6

View File

@ -17,6 +17,8 @@ env:
jobs:
setup-tests:
runs-on: ubicloud-standard-16
env:
STACK_FORCE_EXTERNAL_DB_SYNC: "true"
steps:
- uses: actions/checkout@v6

View File

@ -10,3 +10,5 @@ STACK_INBUCKET_API_URL=http://localhost:${NEXT_PUBLIC_STACK_PORT_PREFIX:-81}05
STACK_SVIX_SERVER_URL=http://localhost:${NEXT_PUBLIC_STACK_PORT_PREFIX:-81}13
STACK_EMAIL_MONITOR_SECRET_TOKEN=this-secret-token-is-for-local-development-only
CRON_SECRET=mock_cron_secret

View File

@ -10,6 +10,9 @@ export const POSTGRES_USER = process.env.EXTERNAL_DB_TEST_USER || 'postgres';
export const POSTGRES_PASSWORD = process.env.EXTERNAL_DB_TEST_PASSWORD || 'PASSWORD-PLACEHOLDER--uqfEC1hmmv';
export const TEST_TIMEOUT = 120000;
export const HIGH_VOLUME_TIMEOUT = 600000; // 10 minutes for 1500+ users
const SHOULD_FORCE_EXTERNAL_DB_SYNC = process.env.STACK_FORCE_EXTERNAL_DB_SYNC === 'true';
const FORCE_SYNC_INTERVAL_MS = 2000;
let lastForcedSyncAt = -Infinity;
// Connection settings to prevent connection leaks
const CLIENT_CONFIG: Partial<ClientConfig> = {
@ -126,10 +129,11 @@ export async function waitForCondition(
options: { timeoutMs?: number, intervalMs?: number, description?: string } = {}
): Promise<void> {
const { timeoutMs = 10000, intervalMs = 100, description = 'condition' } = options;
const startTime = Date.now();
const startTime = performance.now();
while (Date.now() - startTime < timeoutMs) {
while (performance.now() - startTime < timeoutMs) {
try {
await maybeForceExternalDbSync();
if (await checkFn()) {
return;
}
@ -148,6 +152,30 @@ export async function waitForCondition(
throw new Error(`Timeout waiting for ${description} after ${timeoutMs}ms`);
}
async function maybeForceExternalDbSync() {
if (!SHOULD_FORCE_EXTERNAL_DB_SYNC) return;
const now = performance.now();
if (now - lastForcedSyncAt < FORCE_SYNC_INTERVAL_MS) return;
lastForcedSyncAt = now;
const cronSecret = process.env.CRON_SECRET;
if (!cronSecret) {
throw new Error('CRON_SECRET is required when STACK_FORCE_EXTERNAL_DB_SYNC=true');
}
await niceFetch(new URL('/api/latest/internal/external-db-sync/sequencer', STACK_BACKEND_BASE_URL), {
headers: {
Authorization: `Bearer ${cronSecret}`,
},
});
await niceFetch(new URL('/api/latest/internal/external-db-sync/poller', STACK_BACKEND_BASE_URL), {
headers: {
Authorization: `Bearer ${cronSecret}`,
},
});
}
/**
* Wait for data to appear in external DB (relies on automatic cron job)
*/