@itwin/core-backend 5.5.0-dev.16 → 5.5.0-dev.18

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.
@@ -776,7 +776,7 @@ describe("rebase changes & stashing api", function () {
776
776
  });
777
777
  it("getStash() should throw exception", async () => {
778
778
  const b1 = await testIModel.openBriefcase();
779
- chai.expect(() => StashManager.getStash({ db: b1, stash: "invalid_stash" })).to.throw("Invalid stash");
779
+ chai.expect(() => StashManager.getStash({ db: b1, stash: "invalid_stash" })).to.throw("No stashes exist for this briefcase");
780
780
  chai.expect(StashManager.tryGetStash({ db: b1, stash: "invalid_stash" })).to.be.undefined;
781
781
  });
782
782
  it("edge case: a indirect update can cause FK violation", async () => {
@@ -1266,5 +1266,88 @@ describe("rebase changes & stashing api", function () {
1266
1266
  chai.expect(b1.relationships.tryGetInstanceProps(ElementGroupsMembers.classFullName, r1)).to.be.undefined;
1267
1267
  chai.expect(b1.relationships.tryGetInstanceProps(ElementGroupsMembers.classFullName, r2)).to.exist;
1268
1268
  });
1269
+ it("aborting rebaser in middle of rebase session where at least one txn is successfully rebased (used to cause crash)", async () => {
1270
+ const b1 = await testIModel.openBriefcase();
1271
+ const b2 = await testIModel.openBriefcase();
1272
+ const createTxn = async (b) => {
1273
+ const id = await testIModel.insertElement(b);
1274
+ chai.expect(id).is.exist;
1275
+ b.saveChanges(`created element ${id}`);
1276
+ return id;
1277
+ };
1278
+ const e1 = await createTxn(b1);
1279
+ await b1.pushChanges({ description: `${e1} inserted` });
1280
+ const e2 = await createTxn(b2);
1281
+ const e3 = await createTxn(b2);
1282
+ const e4 = await createTxn(b2);
1283
+ let e5 = "";
1284
+ b2.txns.rebaser.setCustomHandler({
1285
+ shouldReinstate: (_txnProps) => {
1286
+ return true;
1287
+ },
1288
+ recompute: async (txnProps) => {
1289
+ chai.expect(BriefcaseManager.containsRestorePoint(b2, BriefcaseManager.PULL_MERGE_RESTORE_POINT_NAME)).is.true;
1290
+ if (txnProps.id === "0x100000001") {
1291
+ e5 = await testIModel.insertElement(b2);
1292
+ throw new Error("Rebase failed");
1293
+ }
1294
+ },
1295
+ });
1296
+ chai.expect(b2.elements.tryGetElementProps(e1)).to.be.undefined;
1297
+ chai.expect(b2.elements.tryGetElementProps(e2)).to.exist;
1298
+ chai.expect(b2.elements.tryGetElementProps(e3)).to.exist;
1299
+ chai.expect(b2.elements.tryGetElementProps(e4)).to.exist;
1300
+ chai.expect(b2.elements.tryGetElementProps(e5)).to.be.undefined;
1301
+ chai.expect(b2.changeset.index).to.equals(2);
1302
+ await chai.expect(b2.pullChanges()).to.be.rejectedWith("Rebase failed");
1303
+ await chai.expect(createTxn(b2)).to.be.rejectedWith(`Could not save changes (created element 0x40000000004)`);
1304
+ chai.expect(b2.changeset.index).to.equals(3);
1305
+ chai.expect(e3).to.exist;
1306
+ chai.expect(b2.elements.tryGetElementProps(e1)).to.exist;
1307
+ chai.expect(b2.elements.tryGetElementProps(e2)).to.exist;
1308
+ chai.expect(b2.elements.tryGetElementProps(e3)).to.undefined;
1309
+ chai.expect(b2.elements.tryGetElementProps(e4)).to.undefined;
1310
+ chai.expect(b2.elements.tryGetElementProps(e5)).to.exist;
1311
+ chai.expect(BriefcaseManager.containsRestorePoint(b2, BriefcaseManager.PULL_MERGE_RESTORE_POINT_NAME)).is.true;
1312
+ // make temp change
1313
+ b2.saveFileProperty({ name: "test", namespace: "testNamespace" }, "testValue");
1314
+ chai.expect(b2.txns.hasUnsavedChanges).is.true;
1315
+ chai.expect(b2.txns.rebaser.canAbort()).is.true;
1316
+ // should abort with unsaved local changes
1317
+ await b2.txns.rebaser.abort();
1318
+ chai.expect(b2.changeset.index).to.equals(2);
1319
+ chai.expect(b2.elements.tryGetElementProps(e1)).to.be.undefined;
1320
+ chai.expect(b2.elements.tryGetElementProps(e2)).to.exist;
1321
+ chai.expect(b2.elements.tryGetElementProps(e3)).to.exist;
1322
+ chai.expect(b2.elements.tryGetElementProps(e4)).to.exist;
1323
+ chai.expect(b2.elements.tryGetElementProps(e5)).to.be.undefined;
1324
+ chai.expect(BriefcaseManager.containsRestorePoint(b2, BriefcaseManager.PULL_MERGE_RESTORE_POINT_NAME)).is.false;
1325
+ b2.txns.rebaser.setCustomHandler({
1326
+ shouldReinstate: (_txnProps) => {
1327
+ return true;
1328
+ },
1329
+ recompute: async (_txnProps) => { },
1330
+ });
1331
+ const e6 = await createTxn(b2);
1332
+ b2.saveChanges(`created element ${e6}`);
1333
+ chai.expect(b2.txns.getCurrentTxnId()).to.equal("0x100000004");
1334
+ chai.expect(b2.txns.getLastSavedTxnProps()?.id).to.equal(`0x100000003`);
1335
+ await b2.pullChanges();
1336
+ chai.expect(b2.elements.tryGetElementProps(e1)).to.exist;
1337
+ chai.expect(b2.elements.tryGetElementProps(e2)).to.exist;
1338
+ chai.expect(b2.elements.tryGetElementProps(e3)).to.exist;
1339
+ chai.expect(b2.elements.tryGetElementProps(e4)).to.exist;
1340
+ const e7 = await createTxn(b2);
1341
+ b2.saveChanges(`created element ${e7}`);
1342
+ chai.expect(b2.txns.getCurrentTxnId()).to.equal("0x100000005");
1343
+ chai.expect(b2.txns.getLastSavedTxnProps()?.id).to.equal(`0x100000004`);
1344
+ await b2.pushChanges({ description: "pushed after rebase aborted" });
1345
+ await b1.pullChanges();
1346
+ chai.expect(b1.elements.tryGetElementProps(e1)).to.exist;
1347
+ chai.expect(b1.elements.tryGetElementProps(e2)).to.exist;
1348
+ chai.expect(b1.elements.tryGetElementProps(e3)).to.exist;
1349
+ chai.expect(b1.elements.tryGetElementProps(e4)).to.exist;
1350
+ chai.expect(b1.elements.tryGetElementProps(e7)).to.exist;
1351
+ });
1269
1352
  });
1270
1353
  //# sourceMappingURL=Rebase.test.js.map