Skip to content

Commit

Permalink
Wait for brower & Yeti to end, then cb. Fix #98.
Browse files Browse the repository at this point in the history
The "session end event fired once" test sometimes fails.
It recently failed in CI and it's happening because
sometimes Phantom completes faster than Yeti, especially
since we switched to a lighter Phantom in ref #97.

Wait for both to complete before making assertions.
  • Loading branch information
reid committed Oct 4, 2012
1 parent 9ac5d2f commit 291be89
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions test/functional.js
Expand Up @@ -268,6 +268,7 @@ function clientFailureContext(createBatchConfiguration) {
var vow = this,
results = [],
firstPathname = null,
finalPathname = null,
sessionEndFires = 0,
agentErrorFires = 0,
agentSeenFires = 0,
Expand All @@ -280,6 +281,18 @@ function clientFailureContext(createBatchConfiguration) {
clientSession,
batch;

function maybeCallback() {
if (sessionEndFires && finalPathname) {
vow.callback(null, {
hub: hub,
expectedPathname: firstPathname,
finalPathname: finalPathname,
sessionEndFires: sessionEndFires,
visitedPaths: visitedPaths
});
}
}

// Recall that:
// Client (test provider) <-> Hub (server) <-> Agent (browser)
//
Expand All @@ -298,13 +311,8 @@ function clientFailureContext(createBatchConfiguration) {
if (visitedPaths.length >= 2 + createBatchConfiguration.tests.length) {
clearTimeout(timeout);
pageTopic.page.release();
vow.callback(null, {
hub: hub,
expectedPathname: firstPathname,
finalPathname: pathname,
sessionEndFires: sessionEndFires,
visitedPaths: visitedPaths
});
finalPathname = pathname;
maybeCallback();
} else if (pathname.indexOf("fixture") !== -1) {
// The URL is a test page.
// Kill the Yeti Client session.
Expand All @@ -323,6 +331,7 @@ function clientFailureContext(createBatchConfiguration) {
lastTopic.session.on("end", function () {
// Hub reports a client session disconnection.
sessionEndFires += 1;
maybeCallback();
});
},
"the agent returned to the capture page": function (topic) {
Expand Down

0 comments on commit 291be89

Please sign in to comment.