mirror of
https://github.com/stablyai/orca.git
synced 2026-10-20 08:03:28 +00:00
fix(ssh): fix flaky test sync and add error code safety check
Test was using tick-based Promise.resolve() loops which don't guarantee the async operation has started. Replace with signal-based synchronization that waits for the actual lease flush. Also add nullish-coalescing to error code check to prevent crashes if error is null or undefined.
This commit is contained in:
@@ -618,13 +618,19 @@ describe('SSH IPC handlers', () => {
|
||||
const detachFlush = new Promise<void>((resolve) => {
|
||||
releaseDetach = resolve
|
||||
})
|
||||
mockStore.markSshRemotePtyLeasesAsync.mockImplementationOnce(() => detachFlush)
|
||||
let signalEnteredDetach = (): void => {}
|
||||
const enteredDetach = new Promise<void>((resolve) => {
|
||||
signalEnteredDetach = resolve
|
||||
})
|
||||
mockStore.markSshRemotePtyLeasesAsync.mockImplementationOnce(() => {
|
||||
signalEnteredDetach()
|
||||
return detachFlush
|
||||
})
|
||||
|
||||
const replacement = handlers.get('ssh:connect')!(null, { targetId: 'ssh-1' })
|
||||
// Why: let the replacement connect reach the flush before shutdown snapshots what to drain.
|
||||
for (let tick = 0; tick < 10; tick++) {
|
||||
await Promise.resolve()
|
||||
}
|
||||
// Why await the flush entry and not ticks: shutdown must not snapshot what to drain until the
|
||||
// replacement connect is parked in the lease flush.
|
||||
await enteredDetach
|
||||
expect(mockStore.markSshRemotePtyLeasesAsync).toHaveBeenCalledWith('ssh-1', 'detached')
|
||||
|
||||
mockConnectionManager.disconnectAll.mockClear()
|
||||
|
||||
@@ -46,7 +46,8 @@ export async function retrySshOwnerRecoveryWhilePublicationPending<T>(
|
||||
return await attempt()
|
||||
} catch (error) {
|
||||
if (
|
||||
(error as { code?: unknown }).code !== PTY_CONSUMER_OWNER_RECOVERY_PENDING_ERROR ||
|
||||
(error as { code?: unknown } | null | undefined)?.code !==
|
||||
PTY_CONSUMER_OWNER_RECOVERY_PENDING_ERROR ||
|
||||
!gate.isCurrent()
|
||||
) {
|
||||
throw error
|
||||
|
||||
Reference in New Issue
Block a user