blob: de0a2c087e1e861ecd56172df9e52533cfe1ff02 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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);
}
});
|