Bug 1478336 - Reset sync status when new Remote Settings client is registered r=glasserc
authorMathieu Leplatre <mathieu@mozilla.com>
Wed, 25 Jul 2018 17:43:08 +0200
changeset 486470 d353b80fd66cd8519b1637fe8b071e6e05fbe95e
parent 486469 dfe8ab123e01667be489a20b253e3cd3b20c10bd
child 486495 35a17ebc4ee64460cdac22d3fb2a57e1215e9b0f
child 486497 2e7b746dfdcf28d93f32cb4cede3124e2a0f486c
push id1815
push userffxbld-merge
push dateMon, 15 Oct 2018 10:40:45 +0000
treeherdermozilla-release@18d4c09e9378 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglasserc
bugs1478336
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1478336 - Reset sync status when new Remote Settings client is registered r=glasserc MozReview-Commit-ID: 6lx90PmNRiz
services/settings/remote-settings.js
services/settings/test/unit/test_remote_settings_poll.js
--- a/services/settings/remote-settings.js
+++ b/services/settings/remote-settings.js
@@ -615,18 +615,22 @@ function remoteSettingsFunction() {
     const rsOptions = {
       bucketName: mainBucket,
       signerName: defaultSigner,
       ...options
     };
     const { bucketName } = rsOptions;
     const key = `${bucketName}/${collectionName}`;
     if (!_clients.has(key)) {
+      // Register a new client!
       const c = new RemoteSettingsClient(collectionName, rsOptions);
       _clients.set(key, c);
+      // Invalidate the polling status, since we want the new collection to
+      // be taken into account.
+      Services.prefs.clearUserPref(PREF_SETTINGS_LAST_ETAG);
     }
     return _clients.get(key);
   };
 
   Object.defineProperty(remoteSettings, "pollingEndpoint", {
     get() {
       const kintoServer = Services.prefs.getCharPref(PREF_SETTINGS_SERVER);
       const changesPath = Services.prefs.getCharPref(PREF_SETTINGS_CHANGES_PATH);
--- a/services/settings/test/unit/test_remote_settings_poll.js
+++ b/services/settings/test/unit/test_remote_settings_poll.js
@@ -514,8 +514,50 @@ add_task(async function test_syncs_clien
   // The `main/some-unknown` should be skipped because it has no dump.
   // The `blocklists/addons` should be skipped because it is not the main bucket.
   // The `example` has a dump, and should cause a network error because the test
   // does not setup the server to receive the requests of `maybeSync()`.
   Assert.ok(/HTTP 404/.test(error.message), "server will return 404 on sync");
   Assert.equal(error.details.collection, "example");
 });
 add_task(clear_state);
+
+
+add_task(async function test_adding_client_resets_last_etag() {
+  function serve200or304(request, response) {
+    const entries = [{
+      id: "aa71e6cc-9f37-447a-b6e0-c025e8eabd03",
+      last_modified: 42,
+      host: "localhost",
+      bucket: "main",
+      collection: "a-collection"
+    }];
+    if (request.queryString == `_since=${encodeURIComponent('"42"')}`) {
+      response.write(JSON.stringify({
+        data: entries.slice(0, 1)
+      }));
+      response.setHeader("ETag", '"42"');
+      response.setStatusLine(null, 304, "Not Modified");
+    } else {
+      response.write(JSON.stringify({
+        data: entries
+      }));
+      response.setHeader("ETag", '"42"');
+      response.setStatusLine(null, 200, "OK");
+    }
+    response.setHeader("Date", (new Date()).toUTCString());
+  }
+  server.registerPathHandler(CHANGES_PATH, serve200or304);
+
+  // Poll once, without any client for "a-collection"
+  await RemoteSettings.pollChanges();
+
+  // Register a new client.
+  let maybeSyncCalled = false;
+  const c = RemoteSettings("a-collection");
+  c.maybeSync = () => { maybeSyncCalled = true; };
+
+  // Poll again.
+  await RemoteSettings.pollChanges();
+
+  // The new client was called, even if the server data didn't change.
+  Assert.ok(maybeSyncCalled);
+});