[Groonga-commit] droonga/express-droonga at 2276fc8 [master] Add tests for expired caches

Back to archive index

YUKI Hiroshi null+****@clear*****
Thu Mar 20 18:36:05 JST 2014


YUKI Hiroshi	2014-03-20 18:36:05 +0900 (Thu, 20 Mar 2014)

  New Revision: 2276fc8e84536b2668aebdb38f7d675973f7db7c
  https://github.com/droonga/express-droonga/commit/2276fc8e84536b2668aebdb38f7d675973f7db7c

  Message:
    Add tests for expired caches

  Modified files:
    test/response-cache/middleware.test.js

  Modified: test/response-cache/middleware.test.js (+113 -0)
===================================================================
--- test/response-cache/middleware.test.js    2014-03-20 18:19:37 +0900 (381d4ca)
+++ test/response-cache/middleware.test.js    2014-03-20 18:36:05 +0900 (342986d)
@@ -222,6 +222,119 @@ suite('Response Cache Middleware', function() {
             });
         });
     });
+
+    test('size over', function(done) {
+      application = express();
+      application.use(middleware({
+        size: 1,
+        rules: [
+          { regex: /cached/ }
+        ]
+      }));
+      application.get('/cached/first', function(request, response){
+        response.json(200, 'OK');
+      });
+      application.get('/cached/second', function(request, response){
+        response.json(200, 'OK');
+      });
+      client(application)
+        .get('/cached/first')
+        .expect(200)
+        .end(function(error, response){
+          if (error)
+            return done(error);
+
+          client(application)
+            .get('/cached/second')
+            .expect(200)
+            .end(function(error, response){
+              if (error)
+                return done(error);
+
+              client(application)
+                .get('/cached/second')
+                .expect(200)
+                .expect('X-Droonga-Cached', 'yes')
+                .end(function(error, response){
+                  if (error)
+                    return done(error);
+
+                  client(application)
+                    .get('/cached/first')
+                    .expect(200)
+                    .end(function(error, response){
+                      if (error)
+                        done(error);
+                      else
+                        assertNotCached(response, done);
+                    });
+                });
+            });
+        });
+    });
+
+    test('expired by global TTL', function(done) {
+      application = express();
+      application.use(middleware({
+        ttlInMilliSeconds: 300,
+        rules: [
+          { regex: /cached/ }
+        ]
+      }));
+      application.get('/cached/expired', function(request, response){
+        response.json(200, 'OK');
+      });
+      client(application)
+        .get('/cached/expired')
+        .expect(200)
+        .end(function(error, response){
+          if (error)
+            return done(error);
+
+          setTimeout(function() {
+            client(application)
+              .get('/cached/expired')
+              .expect(200)
+              .end(function(error, response){
+                if (error)
+                  return done(error);
+                else
+                  assertNotCached(response, done);
+              });
+          }, 600);
+        });
+    });
+
+    test('expired by TTL for a rule', function(done) {
+      application = express();
+      application.use(middleware({
+        rules: [
+          { regex: /cached/, ttlInMilliSeconds: 300 }
+        ]
+      }));
+      application.get('/cached/expired', function(request, response){
+        response.json(200, 'OK');
+      });
+      client(application)
+        .get('/cached/expired')
+        .expect(200)
+        .end(function(error, response){
+          if (error)
+            return done(error);
+
+          setTimeout(function() {
+            client(application)
+              .get('/cached/expired')
+              .expect(200)
+              .end(function(error, response){
+                if (error)
+                  return done(error);
+                else
+                  assertNotCached(response, done);
+              });
+          }, 600);
+        });
+    });
   });
 });
 
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index