@relaybus/testing 0.4.1 → 1.0.0-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +51 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +51 -0
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -1298,6 +1298,49 @@ function payloadFidelityContract(suite) {
|
|
|
1298
1298
|
});
|
|
1299
1299
|
});
|
|
1300
1300
|
}
|
|
1301
|
+
function transactionIsolationContract(suite) {
|
|
1302
|
+
let store;
|
|
1303
|
+
vitest.beforeEach(() => {
|
|
1304
|
+
store = suite.store();
|
|
1305
|
+
});
|
|
1306
|
+
vitest.describe("transaction isolation levels", () => {
|
|
1307
|
+
vitest.it("recognizes no unrelated error as a serialization failure", () => {
|
|
1308
|
+
for (const error of [new Error("boom"), void 0, null, "text", { code: "23505" }]) {
|
|
1309
|
+
vitest.expect(store.isSerializationFailure?.(error) ?? false).toBe(false);
|
|
1310
|
+
}
|
|
1311
|
+
});
|
|
1312
|
+
vitest.it("commits and rolls back at every level it lists", async () => {
|
|
1313
|
+
for (const isolationLevel of store.isolationLevels ?? []) {
|
|
1314
|
+
const committed = createEnvelope();
|
|
1315
|
+
await store.transaction(
|
|
1316
|
+
(transaction) => store.append(
|
|
1317
|
+
transaction,
|
|
1318
|
+
[{ event: committed, deliveries: [createDelivery("h")] }],
|
|
1319
|
+
/* @__PURE__ */ new Date(0)
|
|
1320
|
+
),
|
|
1321
|
+
{ timeoutMs: 5e3, isolationLevel }
|
|
1322
|
+
);
|
|
1323
|
+
const abandoned = createEnvelope();
|
|
1324
|
+
await vitest.expect(
|
|
1325
|
+
store.transaction(
|
|
1326
|
+
async (transaction) => {
|
|
1327
|
+
await store.append(
|
|
1328
|
+
transaction,
|
|
1329
|
+
[{ event: abandoned, deliveries: [createDelivery("h")] }],
|
|
1330
|
+
/* @__PURE__ */ new Date(0)
|
|
1331
|
+
);
|
|
1332
|
+
throw new Error(`rolled back at ${isolationLevel}`);
|
|
1333
|
+
},
|
|
1334
|
+
{ timeoutMs: 5e3, isolationLevel }
|
|
1335
|
+
)
|
|
1336
|
+
).rejects.toThrow(`rolled back at ${isolationLevel}`);
|
|
1337
|
+
const stored = (await store.listDeliveries({})).map((delivery) => delivery.event.id);
|
|
1338
|
+
vitest.expect(stored).toContain(committed.id);
|
|
1339
|
+
vitest.expect(stored).not.toContain(abandoned.id);
|
|
1340
|
+
}
|
|
1341
|
+
});
|
|
1342
|
+
});
|
|
1343
|
+
}
|
|
1301
1344
|
|
|
1302
1345
|
// src/event-store-contract.ts
|
|
1303
1346
|
function eventStoreContract(name, options) {
|
|
@@ -1347,6 +1390,7 @@ function eventStoreContract(name, options) {
|
|
|
1347
1390
|
completionContract(suite);
|
|
1348
1391
|
lostLeasesContract(suite);
|
|
1349
1392
|
payloadFidelityContract(suite);
|
|
1393
|
+
transactionIsolationContract(suite);
|
|
1350
1394
|
});
|
|
1351
1395
|
}
|
|
1352
1396
|
|
|
@@ -1415,6 +1459,8 @@ var FakeClock = class {
|
|
|
1415
1459
|
var InMemoryTransport = class {
|
|
1416
1460
|
name;
|
|
1417
1461
|
published = [];
|
|
1462
|
+
/** Wire names (event type to name) that routes and catalogs declared; the transport sends events as they are. */
|
|
1463
|
+
declaredWireTypes = {};
|
|
1418
1464
|
#subscribers = /* @__PURE__ */ new Map();
|
|
1419
1465
|
#failNextPublishes = 0;
|
|
1420
1466
|
connected = false;
|
|
@@ -1425,6 +1471,11 @@ var InMemoryTransport = class {
|
|
|
1425
1471
|
async connect() {
|
|
1426
1472
|
this.connected = true;
|
|
1427
1473
|
}
|
|
1474
|
+
declareWireTypes(wireTypes) {
|
|
1475
|
+
return () => {
|
|
1476
|
+
Object.assign(this.declaredWireTypes, wireTypes);
|
|
1477
|
+
};
|
|
1478
|
+
}
|
|
1428
1479
|
/** Makes the next `count` publishes reject, simulating a broker outage. */
|
|
1429
1480
|
failNextPublishes(count) {
|
|
1430
1481
|
this.#failNextPublishes = count;
|