mirror of
https://github.com/stablyai/orca.git
synced 2026-10-28 08:02:54 +00:00
* fix(ssh): time out stalled remote file streams * test(ssh): cover stream dispose-listener cleanup * fix(ssh): pause file stream deadlines during sleep * fix(ssh): replay suspended state to late streams * fix(ssh): allow slower file stream progress --------- Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com> Co-authored-by: Jinwoo-H <Jinwoo-H@users.noreply.github.com>
60 lines
1.8 KiB
TypeScript
60 lines
1.8 KiB
TypeScript
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
import {
|
|
publishSystemResume,
|
|
publishSystemSuspend,
|
|
subscribeSystemPowerLifecycle
|
|
} from './system-power-lifecycle'
|
|
|
|
afterEach(() => {
|
|
publishSystemResume()
|
|
vi.restoreAllMocks()
|
|
})
|
|
|
|
describe('system power lifecycle', () => {
|
|
it('replays suspended state to a late subscriber', () => {
|
|
publishSystemSuspend()
|
|
const listener = { onSuspend: vi.fn(), onResume: vi.fn() }
|
|
const unsubscribe = subscribeSystemPowerLifecycle(listener)
|
|
|
|
expect(listener.onSuspend).toHaveBeenCalledOnce()
|
|
expect(listener.onResume).not.toHaveBeenCalled()
|
|
unsubscribe()
|
|
})
|
|
|
|
it('atomically replays a transition to a subscriber added during publication', () => {
|
|
const lateListener = { onSuspend: vi.fn(), onResume: vi.fn() }
|
|
let unsubscribeLate: (() => void) | undefined
|
|
const unsubscribeFirst = subscribeSystemPowerLifecycle({
|
|
onSuspend: () => {
|
|
unsubscribeLate = subscribeSystemPowerLifecycle(lateListener)
|
|
},
|
|
onResume: vi.fn()
|
|
})
|
|
|
|
publishSystemSuspend()
|
|
|
|
expect(lateListener.onSuspend).toHaveBeenCalledOnce()
|
|
unsubscribeLate?.()
|
|
unsubscribeFirst()
|
|
})
|
|
|
|
it('isolates a failing listener from the remaining subscribers', () => {
|
|
vi.spyOn(console, 'error').mockImplementation(() => {})
|
|
const unsubscribeFailing = subscribeSystemPowerLifecycle({
|
|
onSuspend: () => {
|
|
throw new Error('listener failed')
|
|
},
|
|
onResume: vi.fn()
|
|
})
|
|
const healthyListener = { onSuspend: vi.fn(), onResume: vi.fn() }
|
|
const unsubscribeHealthy = subscribeSystemPowerLifecycle(healthyListener)
|
|
|
|
publishSystemSuspend()
|
|
|
|
expect(healthyListener.onSuspend).toHaveBeenCalledOnce()
|
|
expect(console.error).toHaveBeenCalledOnce()
|
|
unsubscribeHealthy()
|
|
unsubscribeFailing()
|
|
})
|
|
})
|