fix tests

This commit is contained in:
Bilal Godil 2026-01-30 15:05:17 -08:00
parent 4b7dd53bf8
commit 044377e087
10 changed files with 32 additions and 6 deletions

View File

@ -20,6 +20,7 @@ jobs:
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"
STACK_EXTERNAL_DB_SYNC_MAX_DURATION_MS: "5000"
strategy:
matrix:

View File

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

View File

@ -22,6 +22,7 @@ jobs:
STACK_TEST_SOURCE_OF_TRUTH: true
STACK_DATABASE_CONNECTION_STRING: "postgres://postgres:PASSWORD-PLACEHOLDER--uqfEC1hmmv@localhost:8128/stackframe"
STACK_FORCE_EXTERNAL_DB_SYNC: "true"
STACK_EXTERNAL_DB_SYNC_MAX_DURATION_MS: "5000"
strategy:
matrix:

View File

@ -20,6 +20,7 @@ jobs:
env:
NEXT_PUBLIC_STACK_PORT_PREFIX: "69"
STACK_FORCE_EXTERNAL_DB_SYNC: "true"
STACK_EXTERNAL_DB_SYNC_MAX_DURATION_MS: "5000"
steps:
- uses: actions/checkout@v6

View File

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

View File

@ -20,6 +20,7 @@ jobs:
env:
NEXT_PUBLIC_STACK_PORT_PREFIX: "69"
STACK_FORCE_EXTERNAL_DB_SYNC: "true"
STACK_EXTERNAL_DB_SYNC_MAX_DURATION_MS: "5000"
steps:
- uses: actions/checkout@v6

View File

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

View File

@ -28,7 +28,9 @@ export const GET = createSmartRouteHandler({
headers: yupObject({
authorization: yupTuple([yupString()]).defined(),
}).defined(),
query: yupObject({}).defined(),
query: yupObject({
maxDurationMs: yupNumber().integer().min(1).optional(),
}).defined(),
}),
response: yupObject({
statusCode: yupNumber().oneOf([200]).defined(),
@ -38,14 +40,14 @@ export const GET = createSmartRouteHandler({
requests_processed: yupNumber().defined(),
}).defined(),
}),
handler: async ({ headers }) => {
handler: async ({ headers, query }) => {
const authHeader = headers.authorization[0];
if (authHeader !== `Bearer ${getEnvVariable("CRON_SECRET")}`) {
throw new StatusError(401, "Unauthorized");
}
const startTime = performance.now();
const maxDurationMs = 3 * 60 * 1000;
const maxDurationMs = query.maxDurationMs ?? 3 * 60 * 1000;
const pollIntervalMs = 50;
const staleClaimIntervalMinutes = 5;

View File

@ -246,7 +246,9 @@ export const GET = createSmartRouteHandler({
headers: yupObject({
authorization: yupTuple([yupString()]).defined(),
}).defined(),
query: yupObject({}).defined(),
query: yupObject({
maxDurationMs: yupNumber().integer().min(1).optional(),
}).defined(),
}),
response: yupObject({
statusCode: yupNumber().oneOf([200]).defined(),
@ -256,7 +258,7 @@ export const GET = createSmartRouteHandler({
iterations: yupNumber().defined(),
}).defined(),
}),
handler: async ({ headers }) => {
handler: async ({ headers, query }) => {
const authHeader = headers.authorization[0];
if (authHeader !== `Bearer ${getEnvVariable("CRON_SECRET")}`) {
throw new StatusError(401, "Unauthorized");
@ -267,7 +269,7 @@ export const GET = createSmartRouteHandler({
const tenancyRefreshIntervalMs = 5_000;
const startTime = performance.now();
const maxDurationMs = 3 * 60 * 1000;
const maxDurationMs = query.maxDurationMs ?? 3 * 60 * 1000;
const pollIntervalMs = 50;
let iterations = 0;

View File

@ -11,6 +11,15 @@ export const POSTGRES_PASSWORD = process.env.EXTERNAL_DB_TEST_PASSWORD || 'PASSW
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_MAX_DURATION_MS = (() => {
const raw = process.env.STACK_EXTERNAL_DB_SYNC_MAX_DURATION_MS;
if (!raw) return 5000;
const parsed = Number.parseInt(raw, 10);
if (!Number.isFinite(parsed) || parsed <= 0) {
throw new Error('STACK_EXTERNAL_DB_SYNC_MAX_DURATION_MS must be a positive integer');
}
return parsed;
})();
const FORCE_SYNC_INTERVAL_MS = 2000;
let lastForcedSyncAt = -Infinity;
@ -165,11 +174,17 @@ async function maybeForceExternalDbSync() {
}
await niceFetch(new URL('/api/latest/internal/external-db-sync/sequencer', STACK_BACKEND_BASE_URL), {
query: {
maxDurationMs: String(FORCE_SYNC_MAX_DURATION_MS),
},
headers: {
Authorization: `Bearer ${cronSecret}`,
},
});
await niceFetch(new URL('/api/latest/internal/external-db-sync/poller', STACK_BACKEND_BASE_URL), {
query: {
maxDurationMs: String(FORCE_SYNC_MAX_DURATION_MS),
},
headers: {
Authorization: `Bearer ${cronSecret}`,
},