Skip to content

Commit

Permalink
don't track dev build socket events
Browse files Browse the repository at this point in the history
  • Loading branch information
tudddorrr committed Jan 9, 2025
1 parent 6a6be1d commit ba0f8b8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 29 deletions.
4 changes: 4 additions & 0 deletions src/socket/socketEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ function getInsertableData(event: SocketEventData): ClickhouseSocketEvent {

export function createSocketEventQueue(clickhouse: ClickHouseClient): Queue<SocketEventData> {
return createQueue<SocketEventData>('socketEvents', async (job) => {
if (job.data.devBuild) {
return
}

await clickhouse.insert({
table: 'socket_events',
values: [getInsertableData(job.data)],
Expand Down
35 changes: 6 additions & 29 deletions tests/socket/socketEvents.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,42 +170,19 @@ describe('Socket events', () => {
expect(events[4].dev_build).toBe(false)
})

it('should track dev build events', async () => {
it('should not track dev build events', async () => {
const [apiKey] = await createAPIKeyAndToken([])
const redis = new Redis(redisConfig)
const ticket = await createSocketTicket(redis, apiKey, true)
await redis.quit()

await createTestSocket(`/?ticket=${ticket}`, async () => {})

let events: ClickhouseSocketEvent[] = []
await vi.waitUntil(async () => {
events = await (<ClickHouseClient>global.clickhouse).query({
query: `SELECT * FROM socket_events WHERE game_id = ${apiKey.game.id} ORDER BY created_at`,
format: 'JSONEachRow'
}).then((res) => res.json<ClickhouseSocketEvent>())
return events.length === 3
})
const events = await (<ClickHouseClient>global.clickhouse).query({
query: `SELECT * FROM socket_events WHERE game_id = ${apiKey.game.id} ORDER BY created_at`,
format: 'JSONEachRow'
}).then((res) => res.json<ClickhouseSocketEvent>())

expect(events[0].event_type).toBe('open')
expect(events[0].req_or_res).toBe('req')
expect(events[0].code).toBeNull()
expect(events[0].game_id).toBe(apiKey.game.id)
expect(events[0].player_alias_id).toBeNull()
expect(events[0].dev_build).toBe(true)

expect(events[1].event_type).toBe('v1.connected')
expect(events[1].req_or_res).toBe('res')
expect(events[1].code).toBeNull()
expect(events[1].game_id).toBe(apiKey.game.id)
expect(events[1].player_alias_id).toBeNull()
expect(events[1].dev_build).toBe(true)

expect(events[2].event_type).toBe('close')
expect(events[2].req_or_res).toBe('req')
expect(events[2].code).toBeNull()
expect(events[2].game_id).toBe(apiKey.game.id)
expect(events[2].player_alias_id).toBeNull()
expect(events[2].dev_build).toBe(true)
expect(events.length).toBe(0)
})
})

0 comments on commit ba0f8b8

Please sign in to comment.