diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /services/sync/tests/unit/test_engine_abort.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-upstream.tar.xz firefox-esr-upstream.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'services/sync/tests/unit/test_engine_abort.js')
-rw-r--r-- | services/sync/tests/unit/test_engine_abort.js | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/services/sync/tests/unit/test_engine_abort.js b/services/sync/tests/unit/test_engine_abort.js new file mode 100644 index 0000000000..84a92d5b00 --- /dev/null +++ b/services/sync/tests/unit/test_engine_abort.js @@ -0,0 +1,77 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +const { WBORecord } = ChromeUtils.importESModule( + "resource://services-sync/record.sys.mjs" +); +const { Service } = ChromeUtils.importESModule( + "resource://services-sync/service.sys.mjs" +); +const { RotaryEngine } = ChromeUtils.importESModule( + "resource://testing-common/services/sync/rotaryengine.sys.mjs" +); + +add_task(async function test_processIncoming_abort() { + _( + "An abort exception, raised in applyIncoming, will abort _processIncoming." + ); + let engine = new RotaryEngine(Service); + + let collection = new ServerCollection(); + let id = Utils.makeGUID(); + let payload = encryptPayload({ id, denomination: "Record No. " + id }); + collection.insert(id, payload); + + let server = sync_httpd_setup({ + "/1.1/foo/storage/rotary": collection.handler(), + }); + + await SyncTestingInfrastructure(server); + await generateNewKeys(Service.collectionKeys); + + _("Create some server data."); + let syncID = await engine.resetLocalSyncID(); + let meta_global = Service.recordManager.set( + engine.metaURL, + new WBORecord(engine.metaURL) + ); + meta_global.payload.engines = { rotary: { version: engine.version, syncID } }; + _("Fake applyIncoming to abort."); + engine._store.applyIncoming = async function (record) { + let ex = { + code: SyncEngine.prototype.eEngineAbortApplyIncoming, + cause: "Nooo", + }; + _("Throwing: " + JSON.stringify(ex)); + throw ex; + }; + + _("Trying _processIncoming. It will throw after aborting."); + let err; + try { + await engine._syncStartup(); + await engine._processIncoming(); + } catch (ex) { + err = ex; + } + + Assert.equal(err, "Nooo"); + err = undefined; + + _("Trying engine.sync(). It will abort without error."); + try { + // This will quietly fail. + await engine.sync(); + } catch (ex) { + err = ex; + } + + Assert.equal(err, undefined); + + await promiseStopServer(server); + Svc.Prefs.resetBranch(""); + Service.recordManager.clearCache(); + + await engine._tracker.clearChangedIDs(); + await engine.finalize(); +}); |