forked from nightwatchjs/nightwatch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated unit tests for request timeout and slight refactoring
- Loading branch information
1 parent
1ed15e1
commit f3bc41c
Showing
8 changed files
with
135 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
var nock = require('nock'); | ||
nock.setAllowUnmocked(true); | ||
|
||
module.exports = { | ||
createSession : function() { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
var common = require('../../common.js'); | ||
var HttpRequest = common.require('http/request.js'); | ||
var MockServer = require('../../lib/mockserver.js'); | ||
var Logger = common.require('util/logger'); | ||
var assert = require('assert'); | ||
|
||
module.exports = { | ||
'test HttpRequestTimeout' : { | ||
beforeEach : function(done) { | ||
this.server = MockServer.init(); | ||
Logger.disable(); | ||
this.server.on('listening', function() { | ||
done(); | ||
}); | ||
}, | ||
|
||
afterEach : function(done) { | ||
this.server.close(function() { | ||
done(); | ||
}); | ||
}, | ||
|
||
testRequestTimeout: function (done) { | ||
MockServer.addMock({ | ||
url : '/wd/hub/123456/element', | ||
response : '', | ||
method: 'GET', | ||
socketDelay : 400 | ||
}, true); | ||
|
||
var options = { | ||
path: '/:sessionId/element', | ||
selenium_port: 10195, | ||
method: 'GET', | ||
sessionId: '123456' | ||
}; | ||
|
||
HttpRequest.setTimeout(50); | ||
|
||
var request = new HttpRequest(options); | ||
|
||
request.on('error', function (err, res) { | ||
assert.ok(res instanceof Error); | ||
done(); | ||
}).on('success', function(result, response) { | ||
done(new Error('Request should have timed out.')); | ||
}).send(); | ||
|
||
}, | ||
|
||
testRetryAttempts: function (done) { | ||
MockServer.addMock({ | ||
url : '/wd/hub/10000000/element', | ||
response : '', | ||
method: 'GET', | ||
socketDelay : 200 | ||
}, true).addMock({ | ||
url : '/wd/hub/10000000/element', | ||
response : '', | ||
method: 'GET' | ||
}, true); | ||
|
||
var options = { | ||
path: '/:sessionId/element', | ||
selenium_port: 10195, | ||
method: 'GET', | ||
sessionId: '10000000' | ||
}; | ||
|
||
HttpRequest.setTimeout(50); | ||
HttpRequest.setRetryAttempts(1); | ||
|
||
var request = new HttpRequest(options); | ||
assert.equal(request.retryAttempts, 1); | ||
|
||
request | ||
.on('error', function(res, err) { | ||
assert.strictEqual(request.retryAttempts, 0); | ||
assert.ok(err instanceof Error); // the 'socket hang up' error, caused by aborting the request | ||
}) | ||
.on('success', function (result) { | ||
assert.strictEqual(request.retryAttempts, 0); | ||
done(); | ||
}) | ||
.send(); | ||
} | ||
} | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters