Skip to content

Commit

Permalink
fix(verification): allow user to specify verification timeout #30
Browse files Browse the repository at this point in the history
  • Loading branch information
mefellows committed Feb 22, 2017
1 parent 02e582f commit a68b8d1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ var opts = {
providerStatesSetupUrl: <String>, // URL to send PUT requests to setup a given provider state. Optional.
pactBrokerUsername: <String>, // Username for Pact Broker basic authentication. Optional
pactBrokerPassword: <String>, // Password for Pact Broker basic authentication. Optional
timeout: <Number> // The duration in ms we should wait to confirm verification process was successful. Defaults to 60000, Optional.
};

pact.verifyPacts(opts).then(function () {
Expand Down
13 changes: 10 additions & 3 deletions src/verifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ var checkTypes = require('check-types'),
isWindows = process.platform === 'win32';

// Constructor
function Verifier(providerBaseUrl, pactUrls, providerStatesUrl, providerStatesSetupUrl, pactBrokerUsername, pactBrokerPassword) {
function Verifier(providerBaseUrl, pactUrls, providerStatesUrl, providerStatesSetupUrl, pactBrokerUsername, pactBrokerPassword, timeout) {
this._options = {};
this._options.providerBaseUrl = providerBaseUrl;
this._options.pactUrls = pactUrls;
this._options.providerStatesUrl = providerStatesUrl;
this._options.providerStatesSetupUrl = providerStatesSetupUrl;
this._options.pactBrokerUsername = pactBrokerUsername;
this._options.pactBrokerPassword = pactBrokerPassword;
this._options.timeout = timeout;
}

Verifier.prototype.verify = function () {
Expand Down Expand Up @@ -78,7 +79,7 @@ Verifier.prototype.verify = function () {
});

logger.info('Created Pact Verifier process with PID: ' + this._instance.pid);
return deferred.promise.timeout(10000, "Couldn't start Pact Verifier process with PID: " + this._instance.pid)
return deferred.promise.timeout(this._options.timeout, "Timeout waiting for verification process to complete (PID: " + this._instance.pid + ")")
.tap(function (data) {
logger.info('Pact Verification succeeded.');
});
Expand Down Expand Up @@ -145,5 +146,11 @@ module.exports = function (options) {
checkTypes.assert.string(options.providerBaseUrl);
}

return new Verifier(options.providerBaseUrl, options.pactUrls, options.providerStatesUrl, options.providerStatesSetupUrl, options.pactBrokerUsername, options.pactBrokerPassword);
if (options.timeout) {
checkTypes.assert.positive(options.timeout);
} else {
options.timeout = 60000;
}

return new Verifier(options.providerBaseUrl, options.pactUrls, options.providerStatesUrl, options.providerStatesSetupUrl, options.pactBrokerUsername, options.pactBrokerPassword, options.timeout);
};
11 changes: 11 additions & 0 deletions src/verifier.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ describe("Verifier Spec", function () {
}).to.throw(Error);
});
});
context("when given an invalid timeout", function () {
it("should fail with an error", function () {
expect(function () {
verifierFactory({
providerBaseUrl: "http://localhost",
pactUrls: ["http://idontexist"],
timeout: -10
});
}).to.throw(Error);
});
});
context("when given remote Pact URLs that don't exist", function () {
it("should pass through to the Pact Verifier regardless", function () {
expect(function () {
Expand Down

0 comments on commit a68b8d1

Please sign in to comment.