Skip to content

Commit

Permalink
Implement testResults queue. Retry /status on 404.
Browse files Browse the repository at this point in the history
The /status API now returns test results that have
been collected but not previously recorded.

Retry /status on 404 because a browser using XHR
may need some more time to reconnect before we
request status again. This is especially true in
our tests, where we request batches rapidly.
  • Loading branch information
reid committed Sep 8, 2010
1 parent 33d7b9c commit 2e830b1
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
8 changes: 7 additions & 1 deletion lib/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,16 @@ function fromConfiguration (config) {
d.method = "GET";
d.path = "/status/" + id;
(function moreResults () {
http.request(d).on("response", function (res, result) {
http.request(d).on("response", function X (res, result) {
if (res.statusCode === 200) {
ui.results(result);
moreResults();
} else if (!d._404 && res.statusCode === 404) {
// perhaps the client hasn't connected yet?
d._404 = true;
return setTimeout(function () {
http.request(d).on("response", X);
}, 500);
} else {
ui.exit("The server says: " + result);
}
Expand Down
15 changes: 13 additions & 2 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,19 @@ function serveExpress (port, path, cb) {
});

app.get("/status/:id", function (req, res, params) {
if (params.id in testIds) {
tests.on(params.id, function (results) {
var id = params.id;
if (id in testIds) {
if (id in testResults) {
var results = testResults[id].shift();
if (results) {
return res.send(results);
} else {
// nothing in the queue
delete testResults[id];
// fallthrough to the test listener
}
}
tests.on(id, function (results) {
res.send(results);
});
} else {
Expand Down
15 changes: 14 additions & 1 deletion test/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,24 @@ function request (code, path, body, method) {
).on("response", function X (res, results) {
var err = null;
if (res.statusCode !== code)
err = res.statusCode + " " + require("http").STATUS_CODES[res.statusCode];
err = options.method + " " + options.path
+ ": " + res.statusCode
+ " " + require("http").STATUS_CODES[res.statusCode];
if (res.statusCode === 302) { // handle redirects
options.path = res.headers.location;
return http.request(options).on("response", X);
}
if (res.statusCode === 404 && !options._404) {
// when Yeti gives a 404, the resource may be available
// in the future. wait a moment then try again.
// this typically happens when requesting /status
// and a browser, using XHR transport, hasn't
// reconnected before the test demands its status
options._404 = true;
return setTimeout(function () {
http.request(options).on("response", X);
}, 500);
}
vow.callback(err, results);
});
}
Expand Down

0 comments on commit 2e830b1

Please sign in to comment.