service-status.test.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { expect } from "bun:test"
  2. import { Effect } from "effect"
  3. import { it } from "../../core/test/lib/effect"
  4. import { Status } from "../src/service-status"
  5. it.effect("moves from starting to ready", () =>
  6. Effect.gen(function* () {
  7. const status = yield* Status.make({ instanceID: "one", managed: false })
  8. expect(yield* status.current).toEqual({ type: "starting" })
  9. yield* status.ready
  10. expect(yield* status.current).toEqual({ type: "ready" })
  11. }),
  12. )
  13. it.effect("keeps a startup failure until shutdown", () =>
  14. Effect.gen(function* () {
  15. const status = yield* Status.make({ instanceID: "one", managed: true })
  16. yield* status.fail
  17. yield* status.ready
  18. yield* status.fail
  19. expect(yield* status.current).toEqual({ type: "failed" })
  20. }),
  21. )
  22. it.effect("stops only the addressed managed instance", () =>
  23. Effect.gen(function* () {
  24. const status = yield* Status.make({ instanceID: "one", managed: true })
  25. expect(yield* status.requestStop({ instanceID: "other" })).toBe(false)
  26. expect(yield* status.current).toEqual({ type: "starting" })
  27. expect(yield* status.requestStop({ instanceID: "one" })).toBe(true)
  28. expect(yield* status.current).toEqual({ type: "stopping" })
  29. }),
  30. )
  31. it.effect("keeps stopping after shutdown begins", () =>
  32. Effect.gen(function* () {
  33. const status = yield* Status.make({ instanceID: "one", managed: true })
  34. yield* status.beginStopping
  35. expect(yield* status.current).toEqual({ type: "stopping" })
  36. expect(yield* status.requestStop({ instanceID: "one" })).toBe(true)
  37. expect(yield* status.current).toEqual({ type: "stopping" })
  38. }),
  39. )