test_service_sync_locked.js (1373B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 const { Service } = ChromeUtils.importESModule( 5 "resource://services-sync/service.sys.mjs" 6 ); 7 8 add_task(async function run_test() { 9 validate_all_future_pings(); 10 let debug = []; 11 let info = []; 12 13 function augmentLogger(old) { 14 let d = old.debug; 15 let i = old.info; 16 // For the purposes of this test we don't need to do full formatting 17 // of the 2nd param, as the ones we care about are always strings. 18 old.debug = function (m, p) { 19 debug.push(p ? m + ": " + (p.message || p) : m); 20 d.call(old, m, p); 21 }; 22 old.info = function (m, p) { 23 info.push(p ? m + ": " + (p.message || p) : m); 24 i.call(old, m, p); 25 }; 26 return old; 27 } 28 29 Log.repository.rootLogger.addAppender(new Log.DumpAppender()); 30 31 augmentLogger(Service._log); 32 33 // Avoid daily ping 34 Svc.PrefBranch.setIntPref("lastPing", Math.floor(Date.now() / 1000)); 35 36 _("Check that sync will log appropriately if already in 'progress'."); 37 Service._locked = true; 38 await Service.sync(); 39 Service._locked = false; 40 41 Assert.ok( 42 debug[debug.length - 2].startsWith( 43 'Exception calling WrappedLock: Could not acquire lock. Label: "service.js: login".' 44 ) 45 ); 46 Assert.equal(info[info.length - 1], "Cannot start sync: already syncing?"); 47 });