Bug 799323 - Make test from bug 793672 more reliable. r=past,blanket-a=test-only
authorMike Hommey <mh+mozilla@glandium.org>
Tue, 09 Oct 2012 10:17:27 +0200
changeset 113306 d5cf98031f8d015394ee681a9797b5c913489630
parent 113305 97a3487c3b5152e18742d582b8d61260d593c24e
child 113307 b62f5e245b7f32a0b820857f3101a748704a50ce
push id2275
push userbugzilla@standard8.plus.com
push dateThu, 11 Oct 2012 19:03:22 +0000
treeherdermozilla-aurora@d5cf98031f8d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspast
bugs799323, 793672
milestone18.0a2
Bug 799323 - Make test from bug 793672 more reliable. r=past,blanket-a=test-only
toolkit/devtools/debugger/tests/unit/test_profiler_actor.js
--- a/toolkit/devtools/debugger/tests/unit/test_profiler_actor.js
+++ b/toolkit/devtools/debugger/tests/unit/test_profiler_actor.js
@@ -109,26 +109,33 @@ function test_profile(aClient, aProfiler
     do_check_eq(typeof aResponse.profile, "object");
     do_check_eq(typeof aResponse.profile.meta, "object");
     do_check_eq(typeof aResponse.profile.meta.platform, "string");
     do_check_eq(typeof aResponse.profile.threads, "object");
     do_check_eq(typeof aResponse.profile.threads[0], "object");
     do_check_eq(typeof aResponse.profile.threads[0].samples, "object");
     do_check_neq(aResponse.profile.threads[0].samples.length, 0);
 
-    // A sample around the middle of the list is expected to have been
-    // in the busy wait above.
-    var sample = aResponse.profile.threads[0].samples[Math.floor(aResponse.profile.threads[0].samples.length / 2)];
-    do_check_eq(sample.name, "(root)");
-    do_check_eq(typeof sample.frames, "object");
-    do_check_neq(sample.frames.length, 0);
-    do_check_true(sample.frames.some(function(f) {
-                    return (f.line == stack.lineNumber) &&
-                           (f.location == stack.name + " (" + stack.filename + ":" + funcLine + ")");
-                  }));
+    function some(array, cb) {
+      for (var i = array.length; i; i--) {
+        if (cb(array[i - 1]))
+          return true;
+      }
+      return false;
+    }
+    // At least one sample is expected to have been in the busy wait above.
+    do_check_true(some(aResponse.profile.threads[0].samples, function(sample) {
+      return sample.name == "(root)" &&
+             typeof sample.frames == "object" &&
+             sample.frames.length != 0 &&
+             sample.frames.some(function(f) {
+               return (f.line == stack.lineNumber) &&
+                      (f.location == stack.name + " (" + stack.filename + ":" + funcLine + ")");
+             });
+    }));
 
     aClient.request({ to: aProfiler, type: "stopProfiler" }, function (aResponse) {
       do_check_eq(typeof aResponse.msg, "string");
       aClient.request({ to: aProfiler, type: "isActive" }, function (aResponse) {
         do_check_false(aResponse.isActive);
         aClient.close(function() {
           test_profiler_status();
         });