services/sync/tests/unit/test_engine_abort.js

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 Cu.import("resource://services-sync/engines.js");
michael@0 5 Cu.import("resource://services-sync/record.js");
michael@0 6 Cu.import("resource://services-sync/service.js");
michael@0 7 Cu.import("resource://services-sync/util.js");
michael@0 8 Cu.import("resource://testing-common/services/sync/rotaryengine.js");
michael@0 9 Cu.import("resource://testing-common/services/sync/utils.js");
michael@0 10
michael@0 11 add_test(function test_processIncoming_abort() {
michael@0 12 _("An abort exception, raised in applyIncoming, will abort _processIncoming.");
michael@0 13 let engine = new RotaryEngine(Service);
michael@0 14
michael@0 15 let collection = new ServerCollection();
michael@0 16 let id = Utils.makeGUID();
michael@0 17 let payload = encryptPayload({id: id, denomination: "Record No. " + id});
michael@0 18 collection.insert(id, payload);
michael@0 19
michael@0 20 let server = sync_httpd_setup({
michael@0 21 "/1.1/foo/storage/rotary": collection.handler()
michael@0 22 });
michael@0 23
michael@0 24 new SyncTestingInfrastructure(server);
michael@0 25 generateNewKeys(Service.collectionKeys);
michael@0 26
michael@0 27 _("Create some server data.");
michael@0 28 let meta_global = Service.recordManager.set(engine.metaURL,
michael@0 29 new WBORecord(engine.metaURL));
michael@0 30 meta_global.payload.engines = {rotary: {version: engine.version,
michael@0 31 syncID: engine.syncID}};
michael@0 32 _("Fake applyIncoming to abort.");
michael@0 33 engine._store.applyIncoming = function (record) {
michael@0 34 let ex = {code: Engine.prototype.eEngineAbortApplyIncoming,
michael@0 35 cause: "Nooo"};
michael@0 36 _("Throwing: " + JSON.stringify(ex));
michael@0 37 throw ex;
michael@0 38 };
michael@0 39
michael@0 40 _("Trying _processIncoming. It will throw after aborting.");
michael@0 41 let err;
michael@0 42 try {
michael@0 43 engine._syncStartup();
michael@0 44 engine._processIncoming();
michael@0 45 } catch (ex) {
michael@0 46 err = ex;
michael@0 47 }
michael@0 48
michael@0 49 do_check_eq(err, "Nooo");
michael@0 50 err = undefined;
michael@0 51
michael@0 52 _("Trying engine.sync(). It will abort without error.");
michael@0 53 try {
michael@0 54 // This will quietly fail.
michael@0 55 engine.sync();
michael@0 56 } catch (ex) {
michael@0 57 err = ex;
michael@0 58 }
michael@0 59
michael@0 60 do_check_eq(err, undefined);
michael@0 61
michael@0 62 server.stop(run_next_test);
michael@0 63 Svc.Prefs.resetBranch("");
michael@0 64 Service.recordManager.clearCache();
michael@0 65 });
michael@0 66
michael@0 67 function run_test() {
michael@0 68 run_next_test();
michael@0 69 }

mercurial