Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/tests/src/test_suites/const.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export const BROADCAST_CONFIG = { config: { broadcast: { self: true } } }
export const LOAD_MESSAGES = 20
export const LOAD_DELIVERY_SLO = 99
export const FANOUT_SUBSCRIBERS = 15
export const FANOUT_DELIVERY_SLO = 100
36 changes: 35 additions & 1 deletion packages/tests/src/test_suites/load-postgres-changes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ import {
waitForPostgresChannel,
} from '../helpers'
import type { TestSuite } from '../types'
import { BROADCAST_CONFIG, LOAD_DELIVERY_SLO, LOAD_MESSAGES } from './const'
import {
BROADCAST_CONFIG,
FANOUT_DELIVERY_SLO,
FANOUT_SUBSCRIBERS,
LOAD_DELIVERY_SLO,
LOAD_MESSAGES,
} from './const'

export default {
'load-postgres-changes': [
Expand Down Expand Up @@ -136,5 +142,33 @@ export default {
return measureThroughput(latencies, LOAD_MESSAGES, LOAD_DELIVERY_SLO)
},
},
{
name: 'postgres changes fan-out to many concurrent filtered subscriptions on one table',
body: async (supabase, { email, password }) => {
await signInUser(supabase, email, password)
const value = randomId()
const latencies: number[] = []
let sentAt = 0

const channels = Array.from({ length: FANOUT_SUBSCRIBERS }, () =>
supabase
.channel(`topic:${randomId()}`, BROADCAST_CONFIG)
.on(
'postgres_changes',
{ event: 'INSERT', schema: 'public', table: 'pg_changes', filter: `value=eq.${value}` },
() => latencies.push(now() - sentAt),
)
.subscribe(),
)

await Promise.all(channels.map((channel) => waitForPostgresChannel(channel)))

sentAt = now()
const { error } = await supabase.from('pg_changes').insert([{ value }])
if (error) throw new Error(`Error inserting data: ${error.message}`)

return measureThroughput(latencies, FANOUT_SUBSCRIBERS, FANOUT_DELIVERY_SLO)
},
},
],
} satisfies TestSuite
Loading