Skip to content

Commit ce5a1bb

Browse files
committed
fix tests
1 parent 74c634b commit ce5a1bb

8 files changed

Lines changed: 67 additions & 12 deletions

File tree

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ jobs:
2020
STACK_ENABLE_HARDCODED_PASSKEY_CHALLENGE_FOR_TESTING: yes
2121
STACK_DATABASE_CONNECTION_STRING: "postgres://postgres:PASSWORD-PLACEHOLDER--uqfEC1hmmv@localhost:8128/stackframe"
2222
STACK_FORCE_EXTERNAL_DB_SYNC: "true"
23-
STACK_EXTERNAL_DB_SYNC_MAX_DURATION_MS: "5000"
23+
STACK_EXTERNAL_DB_SYNC_MAX_DURATION_MS: "20000"
24+
STACK_EXTERNAL_DB_SYNC_DIRECT: "true"
25+
NEXT_PUBLIC_STACK_API_URL: "http://host.docker.internal:8102"
2426

2527
strategy:
2628
matrix:
@@ -50,6 +52,9 @@ jobs:
5052
wait-for: 3s
5153
log-output-if: true
5254

55+
- name: Wait for QStash
56+
run: pnpx wait-on tcp:localhost:8125 -t 60000
57+
5358
- name: Install dependencies
5459
run: pnpm install --frozen-lockfile
5560

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ jobs:
2020
STACK_DATABASE_CONNECTION_STRING: "postgres://postgres:PASSWORD-PLACEHOLDER--uqfEC1hmmv@localhost:6728/stackframe"
2121
NEXT_PUBLIC_STACK_PORT_PREFIX: "67"
2222
STACK_FORCE_EXTERNAL_DB_SYNC: "true"
23-
STACK_EXTERNAL_DB_SYNC_MAX_DURATION_MS: "5000"
23+
STACK_EXTERNAL_DB_SYNC_MAX_DURATION_MS: "20000"
24+
STACK_EXTERNAL_DB_SYNC_DIRECT: "true"
25+
NEXT_PUBLIC_STACK_API_URL: "http://host.docker.internal:6702"
2426

2527
strategy:
2628
matrix:
@@ -49,6 +51,9 @@ jobs:
4951
wait-for: 3s
5052
log-output-if: true
5153

54+
- name: Wait for QStash
55+
run: pnpx wait-on tcp:localhost:6725 -t 60000
56+
5257
- name: Install dependencies
5358
run: pnpm install --frozen-lockfile
5459

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ jobs:
2222
STACK_TEST_SOURCE_OF_TRUTH: true
2323
STACK_DATABASE_CONNECTION_STRING: "postgres://postgres:PASSWORD-PLACEHOLDER--uqfEC1hmmv@localhost:8128/stackframe"
2424
STACK_FORCE_EXTERNAL_DB_SYNC: "true"
25-
STACK_EXTERNAL_DB_SYNC_MAX_DURATION_MS: "5000"
25+
STACK_EXTERNAL_DB_SYNC_MAX_DURATION_MS: "20000"
26+
STACK_EXTERNAL_DB_SYNC_DIRECT: "true"
27+
NEXT_PUBLIC_STACK_API_URL: "http://host.docker.internal:8102"
2628

2729
strategy:
2830
matrix:
@@ -51,6 +53,9 @@ jobs:
5153
wait-for: 3s
5254
log-output-if: true
5355

56+
- name: Wait for QStash
57+
run: pnpx wait-on tcp:localhost:8125 -t 60000
58+
5459
- name: Install dependencies
5560
run: pnpm install --frozen-lockfile
5661

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ jobs:
2020
env:
2121
NEXT_PUBLIC_STACK_PORT_PREFIX: "69"
2222
STACK_FORCE_EXTERNAL_DB_SYNC: "true"
23-
STACK_EXTERNAL_DB_SYNC_MAX_DURATION_MS: "5000"
23+
STACK_EXTERNAL_DB_SYNC_MAX_DURATION_MS: "20000"
24+
STACK_EXTERNAL_DB_SYNC_DIRECT: "true"
25+
NEXT_PUBLIC_STACK_API_URL: "http://host.docker.internal:6902"
2426

2527
steps:
2628
- uses: actions/checkout@v6
@@ -39,6 +41,9 @@ jobs:
3941
- name: Start dev environment
4042
run: pnpm run restart-dev-environment
4143

44+
- name: Wait for QStash
45+
run: pnpx wait-on tcp:localhost:6925 -t 60000
46+
4247
- name: Run tests
4348
run: pnpm run test run --reporter=verbose
4449

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ jobs:
1919
runs-on: ubicloud-standard-16
2020
env:
2121
STACK_FORCE_EXTERNAL_DB_SYNC: "true"
22-
STACK_EXTERNAL_DB_SYNC_MAX_DURATION_MS: "5000"
22+
STACK_EXTERNAL_DB_SYNC_MAX_DURATION_MS: "20000"
23+
STACK_EXTERNAL_DB_SYNC_DIRECT: "true"
24+
NEXT_PUBLIC_STACK_API_URL: "http://host.docker.internal:8102"
2325

2426
steps:
2527
- uses: actions/checkout@v6
@@ -38,6 +40,9 @@ jobs:
3840
- name: Start dev environment
3941
run: pnpm run restart-dev-environment
4042

43+
- name: Wait for QStash
44+
run: pnpx wait-on tcp:localhost:8125 -t 60000
45+
4146
- name: Run tests
4247
run: pnpm run test run --reporter=verbose
4348

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ jobs:
2020
env:
2121
NEXT_PUBLIC_STACK_PORT_PREFIX: "69"
2222
STACK_FORCE_EXTERNAL_DB_SYNC: "true"
23-
STACK_EXTERNAL_DB_SYNC_MAX_DURATION_MS: "5000"
23+
STACK_EXTERNAL_DB_SYNC_MAX_DURATION_MS: "20000"
24+
STACK_EXTERNAL_DB_SYNC_DIRECT: "true"
25+
NEXT_PUBLIC_STACK_API_URL: "http://host.docker.internal:6902"
2426

2527
steps:
2628
- uses: actions/checkout@v6
@@ -48,4 +50,5 @@ jobs:
4850
tail: true
4951
wait-for: 120s
5052
log-output-if: true
53+
- run: pnpx wait-on tcp:localhost:6925 -t 60000
5154
- run: pnpm run test run --reporter=verbose

.github/workflows/setup-tests.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ jobs:
1919
runs-on: ubicloud-standard-16
2020
env:
2121
STACK_FORCE_EXTERNAL_DB_SYNC: "true"
22-
STACK_EXTERNAL_DB_SYNC_MAX_DURATION_MS: "5000"
22+
STACK_EXTERNAL_DB_SYNC_MAX_DURATION_MS: "20000"
23+
STACK_EXTERNAL_DB_SYNC_DIRECT: "true"
24+
NEXT_PUBLIC_STACK_API_URL: "http://host.docker.internal:8102"
2325
steps:
2426
- uses: actions/checkout@v6
2527

@@ -46,4 +48,5 @@ jobs:
4648
tail: true
4749
wait-for: 120s
4850
log-output-if: true
51+
- run: pnpx wait-on tcp:localhost:8125 -t 60000
4952
- run: pnpm run test run --reporter=verbose

apps/backend/src/app/api/latest/internal/external-db-sync/poller/route.ts

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { captureError, StatusError } from "@stackframe/stack-shared/dist/utils/e
1414
import { wait } from "@stackframe/stack-shared/dist/utils/promises";
1515

1616
const DEFAULT_MAX_DURATION_MS = 3 * 60 * 1000;
17+
const DIRECT_SYNC_ENV = "STACK_EXTERNAL_DB_SYNC_DIRECT";
1718

1819
function parseMaxDurationMs(value: string | undefined): number {
1920
if (!value) return DEFAULT_MAX_DURATION_MS;
@@ -24,6 +25,15 @@ function parseMaxDurationMs(value: string | undefined): number {
2425
return parsed;
2526
}
2627

28+
function directSyncEnabled(): boolean {
29+
return getEnvVariable(DIRECT_SYNC_ENV, "") === "true";
30+
}
31+
32+
function getLocalApiBaseUrl(): string {
33+
const prefix = getEnvVariable("NEXT_PUBLIC_STACK_PORT_PREFIX", "81");
34+
return `http://localhost:${prefix}02`;
35+
}
36+
2737
export const GET = createSmartRouteHandler({
2838
metadata: {
2939
summary: "Poll outgoing requests and push to QStash",
@@ -113,11 +123,25 @@ export const GET = createSmartRouteHandler({
113123
}
114124
}
115125

116-
117-
await upstash.publishJSON({
118-
url: fullUrl,
119-
body: options.body,
120-
});
126+
if (directSyncEnabled()) {
127+
const directUrl = new URL(options.url, getLocalApiBaseUrl()).toString();
128+
const res = await fetch(directUrl, {
129+
method: "POST",
130+
headers: {
131+
"content-type": "application/json",
132+
"upstash-signature": "test-bypass",
133+
},
134+
body: JSON.stringify(options.body),
135+
});
136+
if (!res.ok) {
137+
throw new StatusError(res.status, `Direct sync failed: ${res.status} ${res.statusText}`);
138+
}
139+
} else {
140+
await upstash.publishJSON({
141+
url: fullUrl,
142+
body: options.body,
143+
});
144+
}
121145

122146
await deleteOutgoingRequest(request.id);
123147
}),

0 commit comments

Comments
 (0)