Files
orca/cloud/apps/push/src/host-proof-concurrency.test.ts
T
Jinwoo Hong eb2f2d52ae feat(cloud): native push gateway and dedicated infrastructure (1/3) (#19912)
* refactor(cloud): share PostgreSQL schema startup between services

* feat(cloud): add durable native push notification gateway

* infra(push): define dedicated gateway resources and operational checks

* fix(push): bound cross-host admission and simplify gateway configuration

* fix(push): validate deploy configuration and preserve topic-error registrations
2026-09-10 17:59:46 -04:00

48 lines
1.9 KiB
TypeScript

import { expect, it } from 'vitest'
import { openInMemoryPushDatabase, openPushDatabase } from './push-database.js'
import { PushHostChallengeStore } from './host-challenge-store.js'
import {
answerPushHostChallenge,
createPushHostKeypair,
hostPublicKeyB64
} from './host-challenge-answering.test-fixture.js'
it('accepts independent proofs but consumes each challenge only once under concurrency', async () => {
const databaseUrl = process.env.ORCA_PUSH_TEST_DATABASE_URL
if (databaseUrl && !process.env.CI && new URL(databaseUrl).port !== '55440') {
throw new Error('isolated_postgres_port_required')
}
const db = databaseUrl
? await openPushDatabase({ databaseUrl, dataDir: '', poolMax: 4 })
: await openInMemoryPushDatabase()
const host = createPushHostKeypair()
const origin = 'https://push.onorca.dev'
const store = new PushHostChallengeStore(db, origin)
const challenges = await Promise.all([
store.issue(hostPublicKeyB64(host)),
store.issue(hostPublicKeyB64(host))
])
try {
const proofs = challenges.map((challenge) =>
answerPushHostChallenge(challenge!, { gatewayOrigin: origin, keypair: host })!
)
const results = await Promise.all(
challenges.flatMap((challenge, index) =>
Array.from({ length: 5 }, () => store.verify(challenge!.challengeId, proofs[index]!))
)
)
expect(results.filter((result) => result.ok)).toEqual([
{ ok: true, hostFingerprint: challenges[0]!.hostFingerprint },
{ ok: true, hostFingerprint: challenges[0]!.hostFingerprint }
])
expect(results.filter((result) => !result.ok)).toEqual(
Array.from({ length: 8 }, () => ({ ok: false, reason: 'already_consumed' }))
)
} finally {
for (const challenge of challenges) {
await db.query('DELETE FROM push_challenges WHERE challenge_id = ?', [challenge!.challengeId])
}
await db.close()
}
})