Skip to content

Commit

Permalink
Add test to demo memory store .maxAge issue
Browse files Browse the repository at this point in the history
  • Loading branch information
joewagner committed Jun 8, 2014
1 parent d5cc313 commit 57277e8
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions test/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -781,4 +781,37 @@ describe('session()', function(){
})

})

describe('MemoryStore', function () {
it('should destory sessions after .maxAge has elapsed', function(done){
var maxAge = 500
, store = new session.MemoryStore;

var app = express()
.use(cookieParser())
.use(session({ store: store, secret: 'keyboard cat', cookie: { maxAge: maxAge }}))
.use(function(req, res, next){
req.session.count = req.session.count || 0;
req.session.count++;
res.end();
});

request(app)
.get('/')
.end(function(err, res){
Object.keys(store.sessions).length.should.equal(1);

setTimeout(function(){
request(app)
.get('/')
// The browser has deleted the old cookie so it's not sent
.end(function(err, res){
// The store should have deleted the old session
Object.keys(store.sessions).length.should.equal(1);
done();
});
}, maxAge + 100);
});
})
})
})

0 comments on commit 57277e8

Please sign in to comment.