Skip to content

Commit 29f840a

Browse files
committed
fix(functions): failing test
1 parent 021be1b commit 29f840a

File tree

5 files changed

+249
-69
lines changed

5 files changed

+249
-69
lines changed

package-lock.json

Lines changed: 197 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/core/functions-js/test/functions/hijack/index.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
import { serve } from 'https://deno.land/[email protected]/http/server.ts'
22

33
serve((req) => {
4+
// Decode JWT to check if this is a health check
5+
const authHeader = req.headers.get('authorization')
6+
if (authHeader) {
7+
try {
8+
const token = authHeader.replace('Bearer ', '')
9+
const payload = JSON.parse(atob(token.split('.')[1]))
10+
// Health check uses { name: 'check' }
11+
if (payload.name === 'check') {
12+
return new Response('OK', { status: 200 })
13+
}
14+
} catch (e) {
15+
// If JWT decode fails, continue to upgrade attempt
16+
}
17+
}
18+
19+
// For actual test invocations, attempt WebSocket upgrade
420
const p = Deno.upgradeHttp(req)
521

622
// Run this async IIFE concurrently, first packet won't arrive

packages/core/functions-js/test/relay/container.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,18 @@ export async function runRelay(
116116
await new Promise((resolve) => setTimeout(resolve, 1000))
117117
return new Relay(startedRelay, id, execCache, execRun)
118118
}
119-
} catch {
120-
/* we actually don't care about errors here */
119+
} catch (error) {
120+
// Native fetch throws an error when it encounters HTTP 101 (WebSocket upgrade)
121+
// If we get a TypeError (which fetch throws for protocol errors like 101),
122+
// we consider the function ready to serve
123+
if (error instanceof TypeError) {
124+
// This likely means we got a 101 response that native fetch couldn't handle
125+
// The server is responding, so consider it ready
126+
log(`function started to serve (detected via error): ${slug + '-' + id}`)
127+
await new Promise((resolve) => setTimeout(resolve, 1000))
128+
return new Relay(startedRelay, id, execCache, execRun)
129+
}
130+
// For other errors (connection refused, etc.), continue retrying
121131
}
122132
await new Promise((resolve) => setTimeout(resolve, 500))
123133
}

packages/core/postgrest-js/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ The `wrapper.mjs` file simply re-exports the CommonJS build, allowing the packag
116116

117117
```bash
118118
# Run all tests (from monorepo root)
119-
npx nx test postgrest-js
119+
npx nx test:ci:postgrest postgrest-js
120120
```
121121

122122
This single command automatically:
@@ -196,4 +196,4 @@ For major changes or if you're unsure about something, please open an issue firs
196196

197197
## License
198198

199-
This repo is licensed under MIT License.
199+
This repo is licensed under MIT License.

0 commit comments

Comments
 (0)