Skip to content

armgit / orca

Public Imported from GitHub
0

Orca is the place for working with a fleet of agents (e.g. Grok Bot, Claude Code). Run any coding agent with your own subscription. Available on desktop, mobile and remote runtime.

1.6 KB
Raw Blame
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { startRemoteRuntimeSocketLiveness } from './remote-runtime-socket-liveness'

describe('remote runtime socket liveness', () => {
  beforeEach(() => {
    vi.useFakeTimers()
  })

  afterEach(() => {
    vi.useRealTimers()
  })

  it('grants a fresh probe window after a suspended client resumes', async () => {
    let now = 1_000
    const ping = vi.fn()
    const onDead = vi.fn()
    const monitor = startRemoteRuntimeSocketLiveness({
      ping,
      onDead,
      options: { pingIntervalMs: 100, livenessTimeoutMs: 250 },
      now: () => now
    })

    now += 3_600_000
    await vi.advanceTimersByTimeAsync(100)

    expect(ping).toHaveBeenCalledTimes(1)
    expect(onDead).not.toHaveBeenCalled()

    for (const delta of [100, 100]) {
      now += delta
      await vi.advanceTimersByTimeAsync(100)
    }
    expect(onDead).not.toHaveBeenCalled()

    now += 100
    await vi.advanceTimersByTimeAsync(100)
    expect(onDead).toHaveBeenCalledTimes(1)
    monitor.stop()
  })

  it('clears the resumed probe when the socket answers', async () => {
    let now = 1_000
    const ping = vi.fn()
    const onDead = vi.fn()
    const monitor = startRemoteRuntimeSocketLiveness({
      ping,
      onDead,
      options: { pingIntervalMs: 100, livenessTimeoutMs: 250 },
      now: () => now
    })

    now += 3_600_000
    await vi.advanceTimersByTimeAsync(100)
    monitor.noteActivity()
    for (const delta of [100, 100, 100]) {
      now += delta
      await vi.advanceTimersByTimeAsync(100)
    }

    expect(onDead).not.toHaveBeenCalled()
    monitor.stop()
  })
})