Remove obsolete pairing connection attempt (#13460)

This commit is contained in:
Neil
2026-08-10 20:25:51 -07:00
committed by GitHub
parent f9f8d7a8bf
commit 75c6efd48b
2 changed files with 0 additions and 91 deletions
@@ -1,41 +0,0 @@
import { afterEach, describe, expect, it, vi } from 'vitest'
import { startPairingConnectionAttempt } from './pairing-connection-attempt'
describe('pairing connection attempt cleanup', () => {
afterEach(() => {
vi.useRealTimers()
})
it('closes the temporary client when the overall pairing timeout fires', () => {
vi.useFakeTimers()
const closeClient = vi.fn()
const attempt = startPairingConnectionAttempt({ timeoutMs: 25_000, closeClient })
expect(attempt.timedOut).toBe(false)
vi.advanceTimersByTime(24_999)
expect(closeClient).not.toHaveBeenCalled()
vi.advanceTimersByTime(1)
expect(attempt.timedOut).toBe(true)
expect(closeClient).toHaveBeenCalledTimes(1)
attempt.dispose()
expect(closeClient).toHaveBeenCalledTimes(1)
})
it('clears the timeout and closes the temporary client when disposed early', () => {
vi.useFakeTimers()
const closeClient = vi.fn()
const attempt = startPairingConnectionAttempt({ timeoutMs: 25_000, closeClient })
attempt.dispose()
expect(attempt.timedOut).toBe(false)
expect(closeClient).toHaveBeenCalledTimes(1)
vi.advanceTimersByTime(25_000)
expect(attempt.timedOut).toBe(false)
expect(closeClient).toHaveBeenCalledTimes(1)
})
})
@@ -1,50 +0,0 @@
export type PairingConnectionAttempt = {
readonly timedOut: boolean
dispose: () => void
}
export function startPairingConnectionAttempt({
timeoutMs,
closeClient
}: {
timeoutMs: number
closeClient: () => void
}): PairingConnectionAttempt {
let disposed = false
let clientClosed = false
let timedOut = false
let timer: ReturnType<typeof setTimeout> | null = null
function closeClientOnce() {
if (clientClosed) {
return
}
clientClosed = true
closeClient()
}
function dispose() {
if (disposed) {
return
}
disposed = true
if (timer) {
clearTimeout(timer)
timer = null
}
closeClientOnce()
}
timer = setTimeout(() => {
timer = null
timedOut = true
dispose()
}, timeoutMs)
return {
get timedOut() {
return timedOut
},
dispose
}
}