Skip to content

Commit 4b7dd53

Browse files
committed
attempt test fixes
1 parent bd788b4 commit 4b7dd53

9 files changed

Lines changed: 41 additions & 2 deletions

.github/workflows/e2e-api-tests.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ jobs:
1919
NODE_ENV: test
2020
STACK_ENABLE_HARDCODED_PASSKEY_CHALLENGE_FOR_TESTING: yes
2121
STACK_DATABASE_CONNECTION_STRING: "postgres://postgres:PASSWORD-PLACEHOLDER--uqfEC1hmmv@localhost:8128/stackframe"
22+
STACK_FORCE_EXTERNAL_DB_SYNC: "true"
2223

2324
strategy:
2425
matrix:

.github/workflows/e2e-custom-base-port-api-tests.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ jobs:
1919
STACK_ENABLE_HARDCODED_PASSKEY_CHALLENGE_FOR_TESTING: yes
2020
STACK_DATABASE_CONNECTION_STRING: "postgres://postgres:PASSWORD-PLACEHOLDER--uqfEC1hmmv@localhost:6728/stackframe"
2121
NEXT_PUBLIC_STACK_PORT_PREFIX: "67"
22+
STACK_FORCE_EXTERNAL_DB_SYNC: "true"
2223

2324
strategy:
2425
matrix:

.github/workflows/e2e-source-of-truth-api-tests.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ jobs:
2121
STACK_OVERRIDE_SOURCE_OF_TRUTH: '{"type": "postgres", "connectionString": "postgres://postgres:PASSWORD-PLACEHOLDER--uqfEC1hmmv@localhost:8128/source-of-truth-db?schema=sot-schema"}'
2222
STACK_TEST_SOURCE_OF_TRUTH: true
2323
STACK_DATABASE_CONNECTION_STRING: "postgres://postgres:PASSWORD-PLACEHOLDER--uqfEC1hmmv@localhost:8128/stackframe"
24+
STACK_FORCE_EXTERNAL_DB_SYNC: "true"
2425

2526
strategy:
2627
matrix:

.github/workflows/restart-dev-and-test-with-custom-base-port.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ jobs:
1919
runs-on: ubicloud-standard-16
2020
env:
2121
NEXT_PUBLIC_STACK_PORT_PREFIX: "69"
22+
STACK_FORCE_EXTERNAL_DB_SYNC: "true"
2223

2324
steps:
2425
- uses: actions/checkout@v6

.github/workflows/restart-dev-and-test.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ env:
1717
jobs:
1818
restart-dev-and-test:
1919
runs-on: ubicloud-standard-16
20+
env:
21+
STACK_FORCE_EXTERNAL_DB_SYNC: "true"
2022

2123
steps:
2224
- uses: actions/checkout@v6

.github/workflows/setup-tests-with-custom-base-port.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ jobs:
1919
runs-on: ubicloud-standard-16
2020
env:
2121
NEXT_PUBLIC_STACK_PORT_PREFIX: "69"
22+
STACK_FORCE_EXTERNAL_DB_SYNC: "true"
2223

2324
steps:
2425
- uses: actions/checkout@v6

.github/workflows/setup-tests.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ env:
1717
jobs:
1818
setup-tests:
1919
runs-on: ubicloud-standard-16
20+
env:
21+
STACK_FORCE_EXTERNAL_DB_SYNC: "true"
2022
steps:
2123
- uses: actions/checkout@v6
2224

apps/e2e/.env.development

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ STACK_INBUCKET_API_URL=http://localhost:${NEXT_PUBLIC_STACK_PORT_PREFIX:-81}05
1010
STACK_SVIX_SERVER_URL=http://localhost:${NEXT_PUBLIC_STACK_PORT_PREFIX:-81}13
1111

1212
STACK_EMAIL_MONITOR_SECRET_TOKEN=this-secret-token-is-for-local-development-only
13+
14+
CRON_SECRET=mock_cron_secret

apps/e2e/tests/backend/endpoints/api/v1/external-db-sync-utils.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ export const POSTGRES_USER = process.env.EXTERNAL_DB_TEST_USER || 'postgres';
1010
export const POSTGRES_PASSWORD = process.env.EXTERNAL_DB_TEST_PASSWORD || 'PASSWORD-PLACEHOLDER--uqfEC1hmmv';
1111
export const TEST_TIMEOUT = 120000;
1212
export const HIGH_VOLUME_TIMEOUT = 600000; // 10 minutes for 1500+ users
13+
const SHOULD_FORCE_EXTERNAL_DB_SYNC = process.env.STACK_FORCE_EXTERNAL_DB_SYNC === 'true';
14+
const FORCE_SYNC_INTERVAL_MS = 2000;
15+
let lastForcedSyncAt = -Infinity;
1316

1417
// Connection settings to prevent connection leaks
1518
const CLIENT_CONFIG: Partial<ClientConfig> = {
@@ -126,10 +129,11 @@ export async function waitForCondition(
126129
options: { timeoutMs?: number, intervalMs?: number, description?: string } = {}
127130
): Promise<void> {
128131
const { timeoutMs = 10000, intervalMs = 100, description = 'condition' } = options;
129-
const startTime = Date.now();
132+
const startTime = performance.now();
130133

131-
while (Date.now() - startTime < timeoutMs) {
134+
while (performance.now() - startTime < timeoutMs) {
132135
try {
136+
await maybeForceExternalDbSync();
133137
if (await checkFn()) {
134138
return;
135139
}
@@ -148,6 +152,30 @@ export async function waitForCondition(
148152
throw new Error(`Timeout waiting for ${description} after ${timeoutMs}ms`);
149153
}
150154

155+
async function maybeForceExternalDbSync() {
156+
if (!SHOULD_FORCE_EXTERNAL_DB_SYNC) return;
157+
158+
const now = performance.now();
159+
if (now - lastForcedSyncAt < FORCE_SYNC_INTERVAL_MS) return;
160+
lastForcedSyncAt = now;
161+
162+
const cronSecret = process.env.CRON_SECRET;
163+
if (!cronSecret) {
164+
throw new Error('CRON_SECRET is required when STACK_FORCE_EXTERNAL_DB_SYNC=true');
165+
}
166+
167+
await niceFetch(new URL('/api/latest/internal/external-db-sync/sequencer', STACK_BACKEND_BASE_URL), {
168+
headers: {
169+
Authorization: `Bearer ${cronSecret}`,
170+
},
171+
});
172+
await niceFetch(new URL('/api/latest/internal/external-db-sync/poller', STACK_BACKEND_BASE_URL), {
173+
headers: {
174+
Authorization: `Bearer ${cronSecret}`,
175+
},
176+
});
177+
}
178+
151179
/**
152180
* Wait for data to appear in external DB (relies on automatic cron job)
153181
*/

0 commit comments

Comments
 (0)