Skip to content

Commit

Permalink
chore: add test for concurrent closes
Browse files Browse the repository at this point in the history
Reviewers: 

Pull Request: #99
  • Loading branch information
willruggiano authored Feb 11, 2025
1 parent 835d8d4 commit d409259
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 7 deletions.
90 changes: 89 additions & 1 deletion schema/application/__snapshots__/runtime.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2168,7 +2168,7 @@ exports[`runtime demo apply field edits retroactively 1`] = `
}
`;

exports[`runtime demo no_associated_fsm 1`] = `
exports[`runtime demo garbage 1`] = `
{
"advance": {
"__typename": "AdvanceTaskStateMachineResult",
Expand All @@ -2186,3 +2186,91 @@ exports[`runtime demo no_associated_fsm 1`] = `
},
}
`;

exports[`runtime demo end run 2`] = `
{
"advance": {
"__typename": "AdvanceTaskStateMachineResult",
"diagnostics": [
{
"__typename": "Diagnostic",
"code": "no_associated_fsm",
},
],
"instantiations": null,
"root": {
"__typename": "Task",
"chain": {
"__typename": "TaskConnection",
"edges": [
{
"__typename": "TaskEdge",
"node": {
"__typename": "Task",
"displayName": {
"__typename": "DisplayName",
"name": {
"__typename": "DynamicString",
"value": "Run",
},
},
"state": {
"__typename": "Closed",
},
},
},
{
"__typename": "TaskEdge",
"node": {
"__typename": "Task",
"displayName": {
"__typename": "DisplayName",
"name": {
"__typename": "DynamicString",
"value": "Idle Time",
},
},
"state": {
"__typename": "Closed",
},
},
},
{
"__typename": "TaskEdge",
"node": {
"__typename": "Task",
"displayName": {
"__typename": "DisplayName",
"name": {
"__typename": "DynamicString",
"value": "Downtime",
},
},
"state": {
"__typename": "Closed",
},
},
},
{
"__typename": "TaskEdge",
"node": {
"__typename": "Task",
"displayName": {
"__typename": "DisplayName",
"name": {
"__typename": "DynamicString",
"value": "Idle Time",
},
},
"state": {
"__typename": "Closed",
},
},
},
],
},
"fsm": null,
},
},
}
`;
37 changes: 31 additions & 6 deletions schema/application/runtime.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,26 +347,51 @@ describe.skipIf(!!process.env.CI)("runtime demo", () => {
test("end run", async () => {
const t = await mostRecentlyInProgress(FSM);
expect(t.id).toBe(FSM.id);
const h = (await t.hash()) as string;

const result = await execute(
const result0 = await execute(
schema,
TestRuntimeTransitionMutationDocument,
{
includeChain: true,
opts: {
fsm: {
id: t.id,
hash: (await t.hash()) as string,
hash: h,
},
task: {
id: t.id,
hash: (await t.hash()) as string,
hash: h,
},
},
},
);
expect(result.errors).toBeFalsy();
expect(result.data).toMatchSnapshot();
expect(result0.errors).toBeFalsy();
expect(result0.data).toMatchSnapshot();

// Concurrency time! This time let's try to end and already closed task.
// FIXME: currently this will return a no_associated_fsm diagnostic which
// is sort of a lie. Really what we want here is a hash_mismatch diagnostic
// because that is the real root cause here.
const result1 = await execute(
schema,
TestRuntimeTransitionMutationDocument,
{
includeChain: true,
opts: {
fsm: {
id: t.id,
hash: h,
},
task: {
id: t.id,
hash: h,
},
},
},
);
expect(result1.errors).toBeFalsy();
expect(result1.data).toMatchSnapshot();
});

test("apply field edits retroactively", async () => {
Expand Down Expand Up @@ -533,7 +558,7 @@ describe.skipIf(!!process.env.CI)("runtime demo", () => {
expect(r2.data?.trackables?.totalCount).toBe(1);
});

test("no_associated_fsm", async () => {
test("garbage", async () => {
const result = await execute(
schema,
TestRuntimeTransitionMutationDocument,
Expand Down

0 comments on commit d409259

Please sign in to comment.