浏览代码

add test for simultaneous requests

jomo 10 年之前
父节点
当前提交
c93ffa5a79
共有 1 个文件被更改,包括 29 次插入1 次删除
  1. 29 1
      test/test.js

+ 29 - 1
test/test.js

@@ -299,12 +299,40 @@ describe("Crafatar", function() {
         assert_headers(res);
         assert(res.headers["etag"]);
         assert.strictEqual(res.headers["content-type"], "image/png");
-        assert.strictEqual(res.headers["etag"], '"bb2ea7307d"');
         assert(body);
         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 = {
       "avatar with existing username": {
         url: "http://localhost:3000/avatars/jeb_?size=16",