Skip to content

Commit be5d2ac

Browse files
committed
Update abort for testing
1 parent 19dda3d commit be5d2ac

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

packages/vitest-pool-workers/src/worker/workflows.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { WORKFLOW_ENGINE_BINDING } from "../shared/workflows";
22
import { internalEnv } from "./env";
3-
// import type { InstanceStatus } from "@cloudflare/workflows-shared/src/instance";
43
import type { InstanceModifier } from "@cloudflare/workflows-shared/src/modifier";
54

65
export type StepSelector = {
@@ -36,13 +35,11 @@ export async function introspectWorkflowInstance(
3635
`[Vitest-Workflows] Introspecting workflow instance: ${instanceId}`
3736
);
3837

39-
//await workflow.create({ id: instanceId });
40-
4138
// @ts-expect-error getWorkflowName() not exposed
4239
const engineBindingName = `${WORKFLOW_ENGINE_BINDING}${(await workflow.getWorkflowName()).toUpperCase()}`;
43-
// @ts-expect-error binding created at in runner worker start
40+
// @ts-expect-error DO binding created in runner worker start
4441
const engineStubId = internalEnv[engineBindingName].idFromName(instanceId);
45-
// @ts-expect-error binding created at in runner worker start
42+
// @ts-expect-error DO binding created in runner worker start
4643
const engineStub = internalEnv[engineBindingName].get(engineStubId);
4744

4845
const instanceModifier = await engineStub.getInstanceModifier();
@@ -63,15 +60,15 @@ class WorkflowInstanceIntrospectorHandle
6360
this.instanceModifier = instanceModifier;
6461
}
6562

66-
public async modify(
63+
async modify(
6764
fn: (m: InstanceModifier) => Promise<void>
6865
): Promise<WorkflowInstanceIntrospector> {
6966
console.log("[Vitest-Workflows] I should go call a modifier");
7067
await fn(this.instanceModifier);
7168
return this;
7269
}
7370

74-
public async waitForStepResult(step: StepSelector): Promise<unknown> {
71+
async waitForStepResult(step: StepSelector): Promise<unknown> {
7572
console.log("waiting for step result of step", step.name);
7673
// @ts-expect-error waitForStepResult not exposed
7774
const stepResult = await this.engineStub.waitForStepResult(
@@ -83,18 +80,19 @@ class WorkflowInstanceIntrospectorHandle
8380
return stepResult;
8481
}
8582

86-
public async waitForStatus(status: string): Promise<void> {
83+
async waitForStatus(status: string): Promise<void> {
8784
console.log("[Vitest-Workflows] waiting for status");
8885
// @ts-expect-error waitForStatus not exposed
8986
await this.engineStub.waitForStatus(status);
9087

9188
console.log("[Vitest-Workflows] status awaited");
9289
}
9390

94-
public async cleanUp(): Promise<void> {
91+
async cleanUp(): Promise<void> {
9592
// works with isolatedStorage = false
9693
try {
97-
await this.engineStub.abort("user called delete");
94+
// @ts-expect-error DO binding created in runner worker start
95+
await this.engineStub.unsafeAbort("user called delete");
9896
} catch {
9997
// do nothing because we want to clean up this instance
10098
}

packages/workflows-shared/src/engine.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ export class Engine extends DurableObject<Env> {
291291
}
292292
}
293293

294-
// if it hasn't completed the step, create a new promise and add its resolver and rejecter to the waiters map
294+
// if it hasn't completed the step, create a new promise to later resolve/reject
295295
return new Promise<unknown>((resolve, reject) => {
296296
this.stepResultWaiters.set(cacheKey, { resolve, reject });
297297
});
@@ -317,14 +317,16 @@ export class Engine extends DurableObject<Env> {
317317
}
318318
}
319319

320-
async abort(reason?: string) {
321-
console.log("[Engine] Will abort because", reason);
320+
async abort(_reason: string) {
321+
// TODO: Maybe don't actually kill but instead check a flag and return early if true
322+
}
322323

323-
// TODO: have the grace period end somehow?
324+
async unsafeAbort(reason?: string) {
325+
console.log("[Engine] Will abort because", reason);
324326

325327
await this.ctx.storage.sync();
326-
await this.ctx.storage.deleteAlarm();
327-
await this.ctx.storage.deleteAll();
328+
await this.ctx.storage.deleteAll({ noCache: true });
329+
328330
this.ctx.abort(reason);
329331
}
330332

0 commit comments

Comments
 (0)