Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Debug Mode Output Check #223

Merged
merged 5 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/debugger/debug_workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,13 @@ export class WorkflowContextDebug extends DBOSContextImpl implements WorkflowCon

const result = await this.#dbosExec.userDatabase.transaction(wrappedTransaction, txnInfo.config);

// If returned nothing and the recorded value is also null/undefined, we just return it
if (result === undefined && !check!.output) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the ! before check mean?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never mind, it's not. the use of ! for both not and "ignore maybe null" threw me

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe explicitly compare check!.output to false to make this clearer?

return result;
}

if (JSON.stringify(check!.output) !== JSON.stringify(result)) {
this.logger.error(`Detected different transaction output than the original one!\n Expected: ${JSON.stringify(result)}\n Received: ${JSON.stringify(check!.output)}`);
this.logger.error(`Detected different transaction output than the original one!\n Result: ${JSON.stringify(result)}\n Original: ${JSON.stringify(check!.output)}`);
qianl15 marked this conversation as resolved.
Show resolved Hide resolved
}
return check!.output; // Always return the recorded result.
}
Expand Down
27 changes: 27 additions & 0 deletions tests/testing/debugger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ describe("debugger-test", () => {
// TODO: connect to the real proxy.
debugRuntime = await createInternalTestRuntime([DebuggerTest], debugConfig);
testRuntime = await createInternalTestRuntime([DebuggerTest], config);
DebuggerTest.cnt = 0;
});

afterEach(async () => {
Expand Down Expand Up @@ -105,6 +106,16 @@ describe("debugger-test", () => {
}
return val1 + "-" + val2;
}

// eslint-disable-next-line @typescript-eslint/require-await
@Transaction()
static async voidFunction(_txnCtxt: TestTransactionContext) {
if (DebuggerTest.cnt > 0) {
return DebuggerTest.cnt;
}
DebuggerTest.cnt++;
return;
}
}

test("debug-workflow", async () => {
Expand Down Expand Up @@ -136,6 +147,22 @@ describe("debugger-test", () => {
await expect(debugRuntime.invoke(DebuggerTest).testWorkflow(username)).rejects.toThrow("Workflow UUID not found!");
});

test("debug-void-transaction", async () => {
const wfUUID = uuidv1();
// Execute the workflow and destroy the runtime
await expect(testRuntime.invoke(DebuggerTest, wfUUID).voidFunction()).resolves.toBeUndefined();
expect(DebuggerTest.cnt).toBe(1);
await testRuntime.destroy();

// Execute again in debug mode.
await expect(debugRuntime.invoke(DebuggerTest, wfUUID).voidFunction()).resolves.toBeUndefined();
expect(DebuggerTest.cnt).toBe(1);

// Execute again with the provided UUID.
await expect((debugRuntime as TestingRuntimeImpl).getDBOSExec().executeWorkflowUUID(wfUUID).then((x) => x.getResult())).resolves.toBeUndefined();
expect(DebuggerTest.cnt).toBe(1);
});

test("debug-transaction", async () => {
const wfUUID = uuidv1();
// Execute the workflow and destroy the runtime
Expand Down
Loading