Skip to content

Commit f0a6c63

Browse files
committed
fix: normalize timeout diagnostics
1 parent e9cf269 commit f0a6c63

3 files changed

Lines changed: 31 additions & 17 deletions

File tree

‎src/runtime.ts‎

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ export class SolidObjectsRuntime {
354354
options: { timeout: number; deadline: number },
355355
): Promise<DeepReadonly<Result>> {
356356
this.callerWorker ??= new Worker(this)
357-
while (performance.now() <= options.deadline) {
357+
while (performance.now() < options.deadline) {
358358
const message = await this.repository.findMessage(messageReference.id)
359359
if (!message || message.request_id !== messageReference.requestId) {
360360
throw new Error("message reference no longer identifies this invocation")
@@ -401,20 +401,21 @@ export class SolidObjectsRuntime {
401401
instance.activation_owner_id !== null &&
402402
instance.activation_expires_at_ms !== null &&
403403
Number(instance.activation_expires_at_ms) > diagnostics.nowMilliseconds
404-
const waitingOn = instance.paused
405-
? ("actorPaused" as const)
406-
: activationLive
407-
? ("activationHeld" as const)
408-
: blocker
409-
? ("earlierMessage" as const)
410-
: diagnostics.status === "claimed"
411-
? ("messageClaimed" as const)
412-
: diagnostics.readyAvailableAtMilliseconds !== undefined &&
413-
diagnostics.readyAvailableAtMilliseconds > diagnostics.nowMilliseconds
414-
? ("notYetAvailable" as const)
415-
: diagnostics.status === "ready"
416-
? ("readyUnclaimed" as const)
417-
: ("unknown" as const)
404+
const waitingOn =
405+
Number(instance.paused) !== 0
406+
? ("actorPaused" as const)
407+
: activationLive
408+
? ("activationHeld" as const)
409+
: blocker
410+
? ("earlierMessage" as const)
411+
: diagnostics.status === "claimed"
412+
? ("messageClaimed" as const)
413+
: diagnostics.readyAvailableAtMilliseconds !== undefined &&
414+
diagnostics.readyAvailableAtMilliseconds > diagnostics.nowMilliseconds
415+
? ("notYetAvailable" as const)
416+
: diagnostics.status === "ready"
417+
? ("readyUnclaimed" as const)
418+
: ("unknown" as const)
418419
const error = new SyncTimeout({
419420
details: {
420421
timeoutMilliseconds,

‎test/housekeeping.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ afterEach(async () => {
1919

2020
describe("scheduled housekeeping", () => {
2121
it("does not schedule disabled housekeeping", async () => {
22-
runtime = configuredRuntime()
22+
runtime = configuredRuntime({ workerCount: 1 })
2323
await runtime.install()
2424
const prune = vi.spyOn(runtime.repository, "pruneRetention")
2525
const cleanup = vi.spyOn(runtime.repository, "cleanupStaleProcesses")
@@ -170,7 +170,7 @@ function configuredRuntime(
170170
authorizeQuery: () => true,
171171
authorizeDestroy: () => true,
172172
authorizeAdministration: () => true,
173-
workerCount: 1,
173+
workerCount: 0,
174174
effectWorkerCount: 0,
175175
reminderSchedulerCount: 0,
176176
broadcastWorkerCount: 0,

‎test/sync-timeout.test.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,19 @@ describe("synchronous timeout diagnostics", () => {
123123
TimeoutActor.ref("invalid").with({ timeoutMilliseconds: -1 }).increment(),
124124
).rejects.toThrow("timeoutMilliseconds must be a non-negative number")
125125
})
126+
127+
it("does not assist execution when the timeout is zero", async () => {
128+
runtime = configuredRuntime()
129+
await runtime.install()
130+
131+
const error = await captureTimeout(() =>
132+
TimeoutActor.ref("immediate").with({ timeoutMilliseconds: 0 }).increment(),
133+
)
134+
135+
expect(error.details.waitingOn).toBe("readyUnclaimed")
136+
expect(await error.messageReference.status()).toBe("ready")
137+
expect(await error.messageReference.wait({ timeoutMilliseconds: 1_000 })).toBe(1)
138+
})
126139
})
127140

128141
function configuredRuntime(

0 commit comments

Comments
 (0)