IntersectionObserver GC-dependent tests are flaky
authorajuma@chromium.org <ajuma@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 7 Nov 2018 21:00:34 +0000 (21:00 +0000)
committerajuma@chromium.org <ajuma@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 7 Nov 2018 21:00:34 +0000 (21:00 +0000)
https://bugs.webkit.org/show_bug.cgi?id=191387

Reviewed by Chris Dumez.

Make these tests more robust by triggering GC repeatedly inside a setInterval(). Having only a single call to
GC is potentially flaky, since that call will early-out and return immediately if a GC is already underway.

* intersection-observer/root-element-deleted.html:
* intersection-observer/target-deleted.html:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@237939 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/intersection-observer/root-element-deleted.html
LayoutTests/intersection-observer/target-deleted.html

index 4fb4c72..2e06d1a 100644 (file)
@@ -1,3 +1,16 @@
+2018-11-07  Ali Juma  <ajuma@chromium.org>
+
+        IntersectionObserver GC-dependent tests are flaky
+        https://bugs.webkit.org/show_bug.cgi?id=191387
+
+        Reviewed by Chris Dumez.
+
+        Make these tests more robust by triggering GC repeatedly inside a setInterval(). Having only a single call to
+        GC is potentially flaky, since that call will early-out and return immediately if a GC is already underway.
+
+        * intersection-observer/root-element-deleted.html:
+        * intersection-observer/target-deleted.html:
+
 2018-11-07  Dan Bernstein  <mitz@apple.com>
 
         Add a pseudoclass that matches img elements that are backed by an attachment
index 4c4de58..3a859f0 100644 (file)
@@ -9,6 +9,19 @@
 </div>
 
 <script>
+    function observerShouldBeRemoved()
+    {
+        return new Promise(function(resolve) {
+            handle = setInterval(function() {
+                GCController.collect();
+                if (internals && internals.numberOfIntersectionObservers(document) == 0) {
+                    clearInterval(handle);
+                    resolve();
+                }
+            }, 10);
+        });
+    }
+
     async_test(function(t) {
         var root = document.getElementById('root');
         var observer = new IntersectionObserver(function() {}, { root: document.getElementById('root') });;
         root.parentNode.removeChild(root);
         root = null;
         target = null;
-        requestAnimationFrame(t.step_func_done(function() {
+        requestAnimationFrame(function() {
             observer.takeRecords();
-            GCController.collect();
-            assert_equals(observer.root, null, 'Observer has null root after root element is destroyed');
-            assert_equals(internals.numberOfIntersectionObservers(document), 0);
-        }));
+            observerShouldBeRemoved().then(t.step_func_done(function() {
+                assert_equals(observer.root, null, 'Observer has null root after root element is destroyed');
+            }));
+        });
     }, "IntersectionObserver doesn't keep unreachable root alive");
 </script>
 </body>
index c700610..efe42c3 100644 (file)
@@ -8,14 +8,26 @@
 <div id="target" style="width: 100px; height: 100px; background-color: green"></div>
 
 <script>
+    function observerShouldBeRemoved()
+    {
+        return new Promise(function(resolve) {
+            handle = setInterval(function() {
+                gc();
+                if (internals && internals.numberOfIntersectionObservers(document) == 0) {
+                    clearInterval(handle);
+                    resolve();
+                }
+            }, 10);
+        });
+    }
+
     async_test(function(t) {
         let observer = new IntersectionObserver(function(entries) {
             if (entries[0].isIntersecting) {
                 entries[0].target.remove();
-                requestAnimationFrame(t.step_func_done(function() {
-                    gc();
-                    assert_equals(internals.numberOfIntersectionObservers(document), 0);
-                }));
+                observerShouldBeRemoved().then(function() {
+                    t.done();
+                });
             }
         });
         observer.observe(document.getElementById("target"));