mirror of
https://github.com/stablyai/orca.git
synced 2026-09-22 00:02:31 +00:00
Remove obsolete pairing connection attempt (#13460)
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user