webrtc/peer-connection-audio-mute.html is sometimes flaky
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 25 Sep 2017 16:01:47 +0000 (16:01 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 25 Sep 2017 16:01:47 +0000 (16:01 +0000)
https://bugs.webkit.org/show_bug.cgi?id=172649

Patch by Youenn Fablet <youenn@apple.com> on 2017-09-25
Reviewed by Darin Adler.

Iterating until getting the expected result to make test more stable.

* webrtc/peer-connection-audio-mute.html:
* webrtc/peer-connection-remote-audio-mute.html:

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

LayoutTests/ChangeLog
LayoutTests/webrtc/peer-connection-audio-mute.html
LayoutTests/webrtc/peer-connection-remote-audio-mute.html

index f7f0bc2..24eb3d1 100644 (file)
@@ -1,5 +1,17 @@
 2017-09-25  Youenn Fablet  <youenn@apple.com>
 
+        webrtc/peer-connection-audio-mute.html is sometimes flaky
+        https://bugs.webkit.org/show_bug.cgi?id=172649
+
+        Reviewed by Darin Adler.
+
+        Iterating until getting the expected result to make test more stable.
+
+        * webrtc/peer-connection-audio-mute.html:
+        * webrtc/peer-connection-remote-audio-mute.html:
+
+2017-09-25  Youenn Fablet  <youenn@apple.com>
+
         Make captureCanvas-webrtc.html more robust
         https://bugs.webkit.org/show_bug.cgi?id=177334
 
index 199c591..0f20c39 100644 (file)
         if (window.testRunner)
             testRunner.setUserMediaPermission(true);
 
+        var remoteStream;
+        async function checkForSound(expected, message, count)
+        {
+            if (count === undefined)
+                count = 0;
+
+            var results = await analyseAudio(remoteStream, 200, context);
+            if (results.heardHum === expected)
+                return;
+            if (count > 50)
+                return Promise.reject("checkForSound timed out when testing: " + message);
+
+            await waitFor(100);
+            return checkForSound(expected, message, ++count);
+        }
+
         var localTrack;
         return navigator.mediaDevices.getUserMedia({audio: true}).then((localStream) => {
             localTrack = localStream.getAudioTracks()[0];
-            var remoteStream;
             return new Promise((resolve, reject) => {
                 createConnections((firstConnection) => {
                     firstConnection.addTrack(localTrack, localStream);
                     };
                 });
             }).then(() => {
-                return waitFor(500);
-            }).then(() => {
-                return analyseAudio(remoteStream, 500, context).then((results) => {
-                    assert_true(results.heardHum, "heard hum from remote enabled track");
-                });
+                return checkForSound(true, "should hear hum from remote enabled track");
             }).then(() => {
                 localTrack.enabled = false;
-                return waitFor(500);
+                return waitFor(100);
             }).then(() => {
-                return analyseAudio(remoteStream, 500, context).then((results) => {
-                    assert_false(results.heardHum, "not heard hum from remote disabled track");
-                });
+                return checkForSound(false, "should not hear hum from remote enabled track");
             }).then(() => {
                 return context.close();
             });
index 59456c6..6024c4d 100644 (file)
@@ -9,14 +9,30 @@
 <body>
     <script src ="routines.js"></script>
     <script>
+
     var context = new webkitAudioContext();
+    var remoteStream;
+    async function checkForSound(expected, message, count)
+    {
+        if (count === undefined)
+            count = 0;
+
+        var results = await analyseAudio(remoteStream, 200, context);
+        if (results.heardHum === expected)
+            return;
+        if (count > 50)
+            return Promise.reject("checkForSound timed out when testing: " + message);
+
+        await waitFor(100);
+        return checkForSound(expected, message, ++count);
+    }
+
     promise_test((test) => {
         if (window.testRunner)
             testRunner.setUserMediaPermission(true);
 
         return navigator.mediaDevices.getUserMedia({audio: true}).then((localStream) => {
             var remoteTrack;
-            var remoteStream;
             return new Promise((resolve, reject) => {
                 createConnections((firstConnection) => {
                     firstConnection.addTrack(localStream.getAudioTracks()[0], localStream);
                     };
                 });
             }).then(() => {
-                return analyseAudio(remoteStream, 200, context).then((results) => {
-                    assert_true(results.heardHum, "heard hum from remote enabled track");
-                });
+                return checkForSound(true, "should hear hum from remote enabled track");
             }).then(() => {
                 remoteTrack.enabled = false;
                 return waitFor(100);
             }).then(() => {
-                return analyseAudio(remoteStream, 200, context).then((results) => {
-                    assert_false(results.heardHum, "not heard hum from remote disabled track");
-                });
+                return checkForSound(false, "should not hear hum from remote disabled track");
             }).then(() => {
                 return context.close();
             });