Bug 1528211 [wpt PR 15362] - Fix flakiness with stale-while-revalidate tests., a=testonly
authorDave Tapuska <dtapuska@chromium.org>
Tue, 05 Mar 2019 12:16:11 +0000
changeset 522177 ed2e428a7fb7ac020c2e30cc8b4f96240ff3e1b3
parent 522176 32c8219664b626f1ecb577238d5fed0265c04c94
child 522178 2e1f864ca5041d044027c9cbe52ab50c6630b1bd
push id10871
push usercbrindusan@mozilla.com
push dateMon, 18 Mar 2019 15:49:32 +0000
treeherdermozilla-beta@018abdd16060 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1528211, 15362
milestone67.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 1528211 [wpt PR 15362] - Fix flakiness with stale-while-revalidate tests., a=testonly Automatic update from web-platform-tests Fix flakiness with stale-while-revalidate tests. (#15362) Using cookies didn't seem reliable in the wpt test runner when it was re-run. Stop using cookies and use the server side stash instead like the rest of the fetch tests do. Increase timeout on staleness. -- wpt-commits: 2801597ed275a33f31b8e54081a7e891eda0ff07 wpt-pr: 15362
testing/web-platform/tests/fetch/stale-while-revalidate/fetch.tentative.html
testing/web-platform/tests/fetch/stale-while-revalidate/stale-css.py
testing/web-platform/tests/fetch/stale-while-revalidate/stale-css.tentative.html
testing/web-platform/tests/fetch/stale-while-revalidate/stale-image.py
testing/web-platform/tests/fetch/stale-while-revalidate/stale-image.tentative.html
testing/web-platform/tests/fetch/stale-while-revalidate/stale-script.py
testing/web-platform/tests/fetch/stale-while-revalidate/stale-script.tentative.html
--- a/testing/web-platform/tests/fetch/stale-while-revalidate/fetch.tentative.html
+++ b/testing/web-platform/tests/fetch/stale-while-revalidate/fetch.tentative.html
@@ -2,16 +2,19 @@
 <!---
 Tentative test against:
 https://github.com/whatwg/fetch/pull/853
 -->
 <meta charset="utf-8">
 <title>Tests Stale While Revalidate is not executed for fetch API</title>
 <script src="/resources/testharness.js"></script>
 <script src="/resources/testharnessreport.js"></script>
+<script src="/common/utils.js"></script>
 <script>
 promise_test(async (test) => {
-  const response = await fetch(`stale-script.py`);
-  const response2 = await fetch(`stale-script.py`);
+  var request_token = token();
 
-  assert_not_equals(response.headers.get('Token'), response2.headers.get('Token'));
+  const response = await fetch(`stale-script.py?token=` + request_token);
+  const response2 = await fetch(`stale-script.py?token=` + request_token);
+
+  assert_not_equals(response.headers.get('Unique-Id'), response2.headers.get('Unique-Id'));
 }, 'Second fetch does not return same response');
 </script>
--- a/testing/web-platform/tests/fetch/stale-while-revalidate/stale-css.py
+++ b/testing/web-platform/tests/fetch/stale-while-revalidate/stale-css.py
@@ -1,20 +1,22 @@
 def main(request, response):
 
-    cookie = request.cookies.first("Count", None)
+    token = request.GET.first("token", None)
+    value = request.server.stash.take(token)
     count = 0
-    if cookie != None:
-      count = int(cookie.value)
+    if value != None:
+      count = int(value)
     if request.GET.first("query", None) != None:
       headers = [("Count", count)]
       content = ""
       return 200, headers, content
     else:
       count = count + 1
       content = "body { background: rgb(0, 128, 0); }"
       if count > 1:
         content = "body { background: rgb(255, 0, 0); }"
 
       headers = [("Content-Type", "text/css"),
-               ("Set-Cookie", "Count={}".format(count)),
-               ("Cache-Control", "private, max-age=0, stale-while-revalidate=10")]
+               ("Cache-Control", "private, max-age=0, stale-while-revalidate=60")]
+
+      request.server.stash.put(token, count)
       return 200, headers, content
--- a/testing/web-platform/tests/fetch/stale-while-revalidate/stale-css.tentative.html
+++ b/testing/web-platform/tests/fetch/stale-while-revalidate/stale-css.tentative.html
@@ -2,46 +2,48 @@
 <!---
 Tentative test against:
 https://github.com/whatwg/fetch/pull/853
 -->
 <meta charset="utf-8">
 <title>Tests Stale While Revalidate works for css</title>
 <script src="/resources/testharness.js"></script>
 <script src="/resources/testharnessreport.js"></script>
+<script src="/common/utils.js"></script>
 <body>
 <script>
 
+var request_token = token();
 async_test(t => {
   window.onload = t.step_func(() => {
     t.step_timeout(() => {
       assert_equals(window.getComputedStyle(document.body).getPropertyValue('background-color'), "rgb(0, 128, 0)");
       var link2 = document.createElement("link");
       link2.onload = t.step_func(() => {
         assert_equals(window.getComputedStyle(document.body).getPropertyValue('background-color'), "rgb(0, 128, 0)");
         var checkResult = () => {
           // We poll because we don't know when the revalidation will occur.
-          fetch("stale-css.py?query").then(t.step_func((response) => {
+          fetch("stale-css.py?query&token=" + request_token).then(t.step_func((response) => {
             var count = response.headers.get("Count");
             if (count == '2') {
-                t.done();
+              t.done();
             } else {
               t.step_timeout(checkResult, 25);
             }
           }));
         };
         t.step_timeout(checkResult, 25);
       });
       link2.rel = "stylesheet";
       link2.type = "text/css";
-      link2.href = "stale-css.py";
+      link2.href = "stale-css.py?token=" + request_token;
       document.body.appendChild(link2);
     }, 0);
   });
 }, 'Cache returns stale resource');
 
 var link = document.createElement("link");
 link.rel = "stylesheet";
 link.type = "text/css";
-link.href = "stale-css.py";
+link.href = "stale-css.py?token=" + request_token;
 document.body.appendChild(link);
 </script>
 </body>
--- a/testing/web-platform/tests/fetch/stale-while-revalidate/stale-image.py
+++ b/testing/web-platform/tests/fetch/stale-while-revalidate/stale-image.py
@@ -1,30 +1,31 @@
 import os.path
 
 def main(request, response):
 
-    cookie = request.cookies.first("Count", None)
+    token = request.GET.first("token", None)
+    value = request.server.stash.take(token)
     count = 0
-    if cookie != None:
-      count = int(cookie.value)
+    if value != None:
+      count = int(value)
     if request.GET.first("query", None) != None:
       headers = [("Count", count)]
       content = ""
       return 200, headers, content
     else:
       count = count + 1
       filename = "green-16x16.png"
-      if cookie > 1:
+      if count > 1:
         filename = "green-256x256.png"
 
       path = os.path.join(os.path.dirname(__file__), "../../images", filename)
       body = open(path, "rb").read()
 
+      request.server.stash.put(token, count)
       response.add_required_headers = False
       response.writer.write_status(200)
       response.writer.write_header("content-length", len(body))
-      response.writer.write_header("Cache-Control", "private, max-age=0, stale-while-revalidate=10")
+      response.writer.write_header("Cache-Control", "private, max-age=0, stale-while-revalidate=60")
       response.writer.write_header("content-type", "image/png")
-      response.writer.write_header("Set-Cookie", "Count={}".format(count))
       response.writer.end_headers()
 
       response.writer.write(body)
--- a/testing/web-platform/tests/fetch/stale-while-revalidate/stale-image.tentative.html
+++ b/testing/web-platform/tests/fetch/stale-while-revalidate/stale-image.tentative.html
@@ -2,50 +2,52 @@
 <!---
 Tentative test against:
 https://github.com/whatwg/fetch/pull/853
 -->
 <meta charset="utf-8">
 <title>Tests Stale While Revalidate works for images</title>
 <script src="/resources/testharness.js"></script>
 <script src="/resources/testharnessreport.js"></script>
+<script src="/common/utils.js"></script>
 <body>
 <!--
 Use a child document to load the second stale image into because
 an image loaded into the same document will skip cache-control headers.
 See: https://html.spec.whatwg.org/#the-list-of-available-images
 -->
 <iframe id="child" srcdoc=""></iframe>
 <script>
 
+var request_token = token();
 async_test(t => {
   window.onload = t.step_func(() => {
     t.step_timeout(() => {
       assert_equals(document.getElementById("firstimage").width, 16, "Width is 16");
       var childDocument = document.getElementById('child').contentDocument;
       var img2 = childDocument.createElement("img");
       img2.onload = t.step_func(() => {
         assert_equals(img2.width, 16, "image dimension");
         var checkResult = () => {
           // We poll because we don't know when the revalidation will occur.
-          fetch("stale-image.py?query").then(t.step_func((response) => {
+          fetch("stale-image.py?query&token=" + request_token).then(t.step_func((response) => {
             var count = response.headers.get("Count");
             if (count == '2') {
                 t.done();
             } else {
               t.step_timeout(checkResult, 25);
             }
           }));
         };
         t.step_timeout(checkResult, 25);
       });
-      img2.src = "stale-image.py";
+      img2.src = "stale-image.py?token=" + request_token;
       childDocument.body.appendChild(img2);
     }, 0);
   });
 }, 'Cache returns stale resource');
 
 var img = document.createElement("img");
-img.src = "stale-image.py";
+img.src = "stale-image.py?token=" + request_token;
 img.id = "firstimage";
 document.body.appendChild(img);
 </script>
 </body>
--- a/testing/web-platform/tests/fetch/stale-while-revalidate/stale-script.py
+++ b/testing/web-platform/tests/fetch/stale-while-revalidate/stale-script.py
@@ -1,25 +1,26 @@
 import random, string, datetime
 
-def token():
+def id_token():
    letters = string.ascii_lowercase
    return ''.join(random.choice(letters) for i in range(20))
 
 def main(request, response):
-    cookie = request.cookies.first("Count", None)
+    token = request.GET.first("token", None)
+    value = request.server.stash.take(token)
     count = 0
-    if cookie != None:
-      count = int(cookie.value)
+    if value != None:
+      count = int(value)
     if request.GET.first("query", None) != None:
       headers = [("Count", count)]
       content = ""
       return 200, headers, content
     else:
       count = count + 1
 
-      unique_id = token()
+      unique_id = id_token()
       headers = [("Content-Type", "text/javascript"),
-                 ("Cache-Control", "private, max-age=0, stale-while-revalidate=10"),
-                 ("Set-Cookie", "Count={}".format(count)),
-                 ("Token", unique_id)]
+                 ("Cache-Control", "private, max-age=0, stale-while-revalidate=60"),
+                 ("Unique-Id", unique_id)]
       content = "report('{}')".format(unique_id)
+      request.server.stash.put(token, count)
       return 200, headers, content
--- a/testing/web-platform/tests/fetch/stale-while-revalidate/stale-script.tentative.html
+++ b/testing/web-platform/tests/fetch/stale-while-revalidate/stale-script.tentative.html
@@ -2,54 +2,56 @@
 <!---
 Tentative test against:
 https://github.com/whatwg/fetch/pull/853
 -->
 <meta charset="utf-8">
 <title>Tests Stale While Revalidate works for scripts</title>
 <script src="/resources/testharness.js"></script>
 <script src="/resources/testharnessreport.js"></script>
+<script src="/common/utils.js"></script>
 <body>
 <script>
 var last_modified;
 var last_modified_count = 0;
+var request_token = token();
 
 // The script will call report via a uniquely generated ID on the subresource.
 // If it is a cache hit the ID will be the same and the test will pass.
 function report(mod) {
   if (!last_modified) {
     last_modified = mod;
     last_modified_count = 1;
   } else if (last_modified == mod) {
     last_modified_count++;
   }
 }
 
 async_test(t => {
   window.onload = t.step_func(() => {
     step_timeout(() => {
       var script = document.createElement("script");
-      script.src = "stale-script.py";
+      script.src = "stale-script.py?token=" + request_token;
       document.body.appendChild(script);
       script.onload = t.step_func(() => {
           assert_equals(last_modified_count, 2, "last modified");
           var checkResult = () => {
             // We poll because we don't know when the revalidation will occur.
-            fetch("stale-script.py?query").then(t.step_func((response) => {
+            fetch("stale-script.py?query&token=" + request_token).then(t.step_func((response) => {
               var count = response.headers.get("Count");
               if (count == '2') {
                   t.done();
               } else {
                 t.step_timeout(checkResult, 25);
               }
             }));
           };
           t.step_timeout(checkResult, 25);
       });
     }, 0);
   });
 }, 'Cache returns stale resource');
 
 var script = document.createElement("script");
-script.src = "stale-script.py";
+script.src = "stale-script.py?token=" + request_token;
 document.body.appendChild(script);
 </script>
 </body>