Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

Commit

Permalink
fix(server-session-pool): ensure the queue is LIFO
Browse files Browse the repository at this point in the history
NODE-1088
  • Loading branch information
mbroadst committed Nov 4, 2017
1 parent 3968a39 commit ac68e76
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/sessions.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class ServerSessionPool {
}

if (!session.hasTimedOut(sessionTimeoutMinutes)) {
this.sessions.push(session);
this.sessions.unshift(session);
}
}
}
Expand Down
20 changes: 20 additions & 0 deletions test/tests/unit/sessions_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,5 +169,25 @@ describe('Sessions', function() {
done();
}
});

it('should maintain a LIFO queue of sessions', {
metadata: { requires: { topology: 'single' } },
test: function(done) {
const pool = new ServerSessionPool(test.client);

const sessionA = new ServerSession();
const sessionB = new ServerSession();

pool.release(sessionA);
pool.release(sessionB);

const sessionC = pool.acquire();
const sessionD = pool.acquire();

expect(sessionC.id).to.eql(sessionB.id);
expect(sessionD.id).to.eql(sessionA.id);
done();
}
});
});
});

0 comments on commit ac68e76

Please sign in to comment.