Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions whtree/jssdk/whdb/src/impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ class Work implements WorkObject {
} catch (e) {
try {
await this.rollback();
} catch (ignore) {
//TODO a rollback finish handler might throw but we can't deal with that. Ignore that for now
} catch (rollbackError) {
throw new AggregateError([e, rollbackError], "Work preparation and rollback failed");
}
throw e;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import * as test from "@webhare/test";
import { CodeContext } from "@webhare/services/src/codecontexts";
import { query, runInWork, onFinishWork, isWorkOpen } from "@webhare/whdb";

async function commitPreparationAndRollbackFailuresRemainVisible() {
await using context = new CodeContext("commit preparation and rollback failures");
const preparation = new Error("Synthetic commit preparation failure");
const rollback = new Error("Synthetic first rollback preparation failure");
let rollbackAttempts = 0;
await context.run(async () => {
await test.throws(error => error instanceof AggregateError && error.errors.length === 2
&& error.errors[0] === preparation && error.errors[1] === rollback,
() => runInWork(async () => {
onFinishWork({
onBeforeCommit: () => { throw preparation; },
onBeforeRollback: () => { if (++rollbackAttempts === 1) throw rollback; },
});
}));
test.assert(rollbackAttempts >= 1, "Rollback preparation was attempted");
test.eq(false, isWorkOpen(), "The interrupted Work is fully rolled back");
test.eq(42, (await query<{ value: number }>("SELECT 42 AS value")).rows[0].value,
"The connection remains usable after rollback finishes");
});
}

test.runTests([commitPreparationAndRollbackFailuresRemainVisible]);
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<test script="test_node_regressions.ts" />
<test script="test_tests.ts" />
<test script="test_whdb.ts" />
<test script="test_work_prepare_errors.ts" />
<test script="test_manualcondition.ts" />
<test script="test_fifo.ts" />
<test script="test_waitabletimer.ts" />
Expand Down