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_412.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.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_412.js')
-rw-r--r-- | services/sync/tests/unit/test_412.js | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/services/sync/tests/unit/test_412.js b/services/sync/tests/unit/test_412.js new file mode 100644 index 0000000000..de0a2c087e --- /dev/null +++ b/services/sync/tests/unit/test_412.js @@ -0,0 +1,60 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +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_412_not_treated_as_failure() { + await Service.engineManager.register(RotaryEngine); + let engine = Service.engineManager.get("rotary"); + + let server = await serverForFoo(engine); + + await SyncTestingInfrastructure(server); + await generateNewKeys(Service.collectionKeys); + + // add an item to the server to the first sync advances lastModified. + let collection = server.getCollection("foo", "rotary"); + let payload = encryptPayload({ + id: "existing", + something: "existing record", + }); + collection.insert("existing", payload); + + let promiseObserved = promiseOneObserver("weave:engine:sync:finish"); + try { + // Do sync. + _("initial sync to initialize the world"); + await Service.sync(); + + // create a new record that should be uploaded and arrange for our lastSync + // timestamp to be wrong so we get a 412. + engine._store.items = { new: "new record" }; + await engine._tracker.addChangedID("new", 0); + + let saw412 = false; + let _uploadOutgoing = engine._uploadOutgoing; + engine._uploadOutgoing = async () => { + let lastSync = await engine.getLastSync(); + await engine.setLastSync(lastSync - 2); + try { + await _uploadOutgoing.call(engine); + } catch (ex) { + saw412 = ex.status == 412; + throw ex; + } + }; + _("Second sync - expecting a 412"); + await Service.sync(); + await promiseObserved; + ok(saw412, "did see a 412 error"); + // But service status should be OK as the 412 shouldn't be treated as an error. + equal(Service.status.service, STATUS_OK); + } finally { + await promiseStopServer(server); + } +}); |