add test for simultaneous requests

This commit is contained in:
jomo 2015-05-26 22:16:33 +02:00
parent 5ef3c4f59c
commit c93ffa5a79

View File

@ -299,12 +299,40 @@ describe("Crafatar", function() {
assert_headers(res); assert_headers(res);
assert(res.headers["etag"]); assert(res.headers["etag"]);
assert.strictEqual(res.headers["content-type"], "image/png"); assert.strictEqual(res.headers["content-type"], "image/png");
assert.strictEqual(res.headers["etag"], '"bb2ea7307d"');
assert(body); assert(body);
done(); done();
}); });
}); });
it("should not fail on simultaneous requests", function(done) {
var url = "http://localhost:3000/avatars/696a82ce41f44b51aa31b8709b8686f0";
// 10 requests at once
var requests = 10;
var finished = 0;
function partDone() {
finished++;
if (finished === requests) {
// all requests have finished
done();
}
}
function req() {
request.get(url, function(error, res, body) {
assert.ifError(error);
assert.strictEqual(res.statusCode, 200);
assert_headers(res);
assert(res.headers["etag"]);
assert.strictEqual(res.headers["content-type"], "image/png");
assert(body);
partDone();
});
}
// make simultanous requests
for (var j = 0; j < requests; j++) {
req(j);
}
});
var server_tests = { var server_tests = {
"avatar with existing username": { "avatar with existing username": {
url: "http://localhost:3000/avatars/jeb_?size=16", url: "http://localhost:3000/avatars/jeb_?size=16",