michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: Cu.import("resource://services-sync/engines.js"); michael@0: Cu.import("resource://services-sync/record.js"); michael@0: Cu.import("resource://services-sync/service.js"); michael@0: Cu.import("resource://services-sync/util.js"); michael@0: Cu.import("resource://testing-common/services/sync/rotaryengine.js"); michael@0: Cu.import("resource://testing-common/services/sync/utils.js"); michael@0: michael@0: add_test(function test_processIncoming_abort() { michael@0: _("An abort exception, raised in applyIncoming, will abort _processIncoming."); michael@0: let engine = new RotaryEngine(Service); michael@0: michael@0: let collection = new ServerCollection(); michael@0: let id = Utils.makeGUID(); michael@0: let payload = encryptPayload({id: id, denomination: "Record No. " + id}); michael@0: collection.insert(id, payload); michael@0: michael@0: let server = sync_httpd_setup({ michael@0: "/1.1/foo/storage/rotary": collection.handler() michael@0: }); michael@0: michael@0: new SyncTestingInfrastructure(server); michael@0: generateNewKeys(Service.collectionKeys); michael@0: michael@0: _("Create some server data."); michael@0: let meta_global = Service.recordManager.set(engine.metaURL, michael@0: new WBORecord(engine.metaURL)); michael@0: meta_global.payload.engines = {rotary: {version: engine.version, michael@0: syncID: engine.syncID}}; michael@0: _("Fake applyIncoming to abort."); michael@0: engine._store.applyIncoming = function (record) { michael@0: let ex = {code: Engine.prototype.eEngineAbortApplyIncoming, michael@0: cause: "Nooo"}; michael@0: _("Throwing: " + JSON.stringify(ex)); michael@0: throw ex; michael@0: }; michael@0: michael@0: _("Trying _processIncoming. It will throw after aborting."); michael@0: let err; michael@0: try { michael@0: engine._syncStartup(); michael@0: engine._processIncoming(); michael@0: } catch (ex) { michael@0: err = ex; michael@0: } michael@0: michael@0: do_check_eq(err, "Nooo"); michael@0: err = undefined; michael@0: michael@0: _("Trying engine.sync(). It will abort without error."); michael@0: try { michael@0: // This will quietly fail. michael@0: engine.sync(); michael@0: } catch (ex) { michael@0: err = ex; michael@0: } michael@0: michael@0: do_check_eq(err, undefined); michael@0: michael@0: server.stop(run_next_test); michael@0: Svc.Prefs.resetBranch(""); michael@0: Service.recordManager.clearCache(); michael@0: }); michael@0: michael@0: function run_test() { michael@0: run_next_test(); michael@0: }