Skip to content

Commit

Permalink
FIX Don't call done unless the test case passes
Browse files Browse the repository at this point in the history
Problem:
Test case 'Reuse authentication tokens'
            -> 'When a PEP Proxy has an expired token and another
                request arrives to the proxy'
               -> 'both requests should finish'

We call done() without being sure that both requests have finished.

Solution:
Only call done once the second request receives a response.
When the test case fails, it now does so in the test case proper
rather than in a hook.
  • Loading branch information
davisjam committed Oct 14, 2016
1 parent e2f3bba commit 3b535ba
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion test/unit/reuse_keystone_tokens_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@ describe('Reuse authentication tokens', function() {
it('both requests should finish', function(done) {
var bus = new EventEmitter();

var nRequests = 2;
var nFinishedRequests = 0;

mockOAuthApp.handler = function(req, res) {
if (req.path === currentAuthentication.authPath && req.method === 'POST') {
bus.once('secondArrived', function() {
Expand All @@ -300,7 +303,10 @@ describe('Reuse authentication tokens', function() {
bus.once('firstWaiting', function() {
request(options, function(error, response, body) {
should.not.exist(error);
done();
nFinishedRequests++;
if (nFinishedRequests === nRequests) {
done();
}
});

setTimeout(function() {
Expand All @@ -310,6 +316,10 @@ describe('Reuse authentication tokens', function() {

request(options, function(error, response, body) {
should.not.exist(error);
nFinishedRequests++;
if (nFinishedRequests === nRequests) {
done();
}
});
});
});
Expand Down

0 comments on commit 3b535ba

Please sign in to comment.