Djalmar Gutierrez
03/03/2022, 8:36 PMUnhandled promise rejection: Error: Pact startup failed; tried calling service 10 times with no result.
Nothing else is changed.Matt (pactflow.io / pact-js / pact-go)
03/03/2022, 9:26 PMDjalmar Gutierrez
03/03/2022, 9:40 PMNODE_ENV=test npx jasmine spec/contract/bsapi.spec.js
Running tests with 'NODE_ENV=test'
Started
[2022-03-03 20:44:30.699 +0000] INFO (133 on 7d526b155d90): pact-node@10.17.1: Creating Pact Server with options:
{"timeout":100000,"consumer":"ares-integration-services","cors":false,"dir":"/app/pacts","host":"0.0.0.0","log":"/app/logs/mockserver-integration.log","logLevel":"DEBUG","pactfileWriteMode":"overwrite","provider":"BSAPI","spec":2,"ssl":false,"port":1234,"pactFileWriteMode":"overwrite"}
[2022-03-03 20:44:30.713 +0000] DEBUG (133 on 7d526b155d90): pact-node@10.17.1: Starting pact binary '/app/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.81/pact/bin/pact-mock-service', with arguments [service --consumer ares-integration-services --cors false --pact_dir /app/pacts --host 0.0.0.0 --log /app/logs/mockserver-integration.log --log-level DEBUG --provider BSAPI --pact_specification_version 2 --ssl false --port 1234 --pact-file-write-mode overwrite]
[2022-03-03 20:44:30.719 +0000] DEBUG (133 on 7d526b155d90): pact-node@10.17.1: Created '/app/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.81/pact/bin/pact-mock-service' process with PID: 144
[2022-03-03 20:44:36.922 +0000] DEBUG (133 on 7d526b155d90): pact-node@10.17.1: INFO WEBrick 1.3.1
INFO ruby 2.2.2 (2015-04-13) [x86_64-linux]
[2022-03-03 20:44:36.922 +0000] DEBUG (133 on 7d526b155d90): pact-node@10.17.1: INFO WEBrick::HTTPServer#start: pid=144 port=1234
[2022-03-03 20:46:10.641 +0000] ERROR (133 on 7d526b155d90): pact@9.17.2: The pact mock service doesn't appear to be running
- Please check the logs above to ensure that there are no pact service startup failures
- Please check that pact lifecycle methods are called in the correct order (setup() needs to be called before this method)
- Please check that your test code waits for the promises returned from lifecycle methods to complete before calling the next one
- To learn more about what is happening during your pact run, try setting logLevel: 'DEBUG'
F[2022-03-03 20:46:10.649 +0000] ERROR (133 on 7d526b155d90): pact@9.17.2: The pact mock service doesn't appear to be running
- Please check the logs above to ensure that there are no pact service startup failures
- Please check that pact lifecycle methods are called in the correct order (setup() needs to be called before this method)
- Please check that your test code waits for the promises returned from lifecycle methods to complete before calling the next one
- To learn more about what is happening during your pact run, try setting logLevel: 'DEBUG'
Failures:
1) BSAPI /bsapi/api/v1c/monitoring-series?baseline-id=ORD-2109329-02 when request is not authenticated should fail requiring authentication
Message:
Error: The pact mock service wasn't running when verify was called
Stack:
Error: The pact mock service wasn't running when verify was called
at Pact.verify (/app/node_modules/@pact-foundation/pact/src/httpPact.js:108:35)
at UserContext.<anonymous> (/app/spec/contract/bsapi.spec.js:59:28)
at <Jasmine>
Suite error: BSAPI
Message:
Unhandled promise rejection: Error: Pact startup failed; tried calling service 10 times with no result.
Stack:
Error: Pact startup failed; tried calling service 10 times with no result.
at Server.retry (/app/node_modules/@pact-foundation/pact-node/src/service.js:177:33)
at _rejected (/app/node_modules/q/q.js:864:24)
at /app/node_modules/q/q.js:890:30
at Promise.when (/app/node_modules/q/q.js:1142:31)
at Promise.promise.promiseDispatch (/app/node_modules/q/q.js:808:41)
at /app/node_modules/q/q.js:624:44
at runSingle (/app/node_modules/q/q.js:137:13)
at flush (/app/node_modules/q/q.js:125:13)
at processTicksAndRejections (node:internal/process/task_queues:78:11)
Message:
Error: Timeout - Async function did not complete within 100000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL)
Stack:
Error: Timeout - Async function did not complete within 100000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL)
at <Jasmine>
at listOnTimeout (node:internal/timers:557:17)
at processTimers (node:internal/timers:500:7)
Message:
Error: The pact mock service wasn't running when finalize was called
Stack:
Error: The pact mock service wasn't running when finalize was called
at Pact.finalize (/app/node_modules/@pact-foundation/pact/src/httpPact.js:141:35)
at UserContext.<anonymous> (/app/spec/contract/bsapi.spec.js:61:27)
at <Jasmine>
at processImmediate (node:internal/timers:464:21)
1 spec, 2 failures
Finished in 99.957 seconds
Matt (pactflow.io / pact-js / pact-go)
03/03/2022, 9:42 PMsetup()
is called in the correct place etc.?Yousaf Nabi (pactflow.io)
03/04/2022, 12:25 PMkarma
here which uses pact-web which probably isn't what you are afterDjalmar Gutierrez
03/04/2022, 12:59 PMYousaf Nabi (pactflow.io)
03/04/2022, 1:04 PMapp/logs/mockserver-integration.log
Also if you put three backticks before your code output in slack, you will get a nice formatted code block which is much easier to read 🙂 ````your code text`Djalmar Gutierrez
03/04/2022, 1:04 PMconst path = require('path')
const { Pact } = require('@pact-foundation/pact')
describe('API', () => {
let provider
jasmine.DEFAULT_TIMEOUT_INTERVAL = 100000
provider = new Pact({
consumer: 'ares-integration-services',
provider: 'BSAPI',
port: 1234,
log: path.resolve(process.cwd(), 'logs', 'mockserver-integration.log'),
dir: path.resolve(process.cwd(), 'pacts'),
logLevel: 'DEBUG',
timeout: 100000
})
beforeAll(async () => {
await provider.setup()
provider.addInteraction({
state: 'the request is not authenticated',
uponReceiving: 'a request for monitoring series',
withRequest: {
method: 'GET',
path: '/api'
},
willRespondWith: {
status: 401,
headers: {
'Content-Type': 'application/problem+json; charset=utf-8'
}
}
})
})
describe('/api', () => {
describe('when request is not authenticated', () => {
it('should fail requiring authentication', async () => {
expect(true).toBe(true)
})
})
})
afterEach(() => provider.verify())
afterAll(() => provider.finalize())
})
Yousaf Nabi (pactflow.io)
03/04/2022, 1:06 PMDjalmar Gutierrez
03/04/2022, 1:12 PMI, [2022-03-04T13:11:11.827524 #29] INFO -- : Registered expected interaction GET /api
W, [2022-03-04T13:11:11.830281 #29] WARN -- : Verifying - actual interactions do not match expected interactions.
Missing requests:
GET /api
D, [2022-03-04T13:11:11.830585 #29] DEBUG -- : {
"description": "a request for monitoring series",
"providerState": "the request is not authenticated",
"request": {
"method": "GET",
"path": "/api"
},
"response": {
"status": 401,
"headers": {
"Content-Type": "application/problem+json; charset=utf-8"
}
},
"metadata": null
}
W, [2022-03-04T13:11:11.831952 #29] WARN -- : Missing requests:
GET /api
I, [2022-03-04T13:11:11.845377 #29] INFO -- : Cleared interactions
Yousaf Nabi (pactflow.io)
03/04/2022, 1:26 PMjasmine
and mocha
I need to change the beforeAll
/ afterAll
to `before`/`after` .
In your script, you are using expect
are you getting that from chai
globally?Djalmar Gutierrez
03/04/2022, 1:27 PMYousaf Nabi (pactflow.io)
03/04/2022, 1:29 PM╰─ npm run test:jasmine ─╯
> mochajs-pact-example@1.0.0 test:jasmine
> NODE_ENV=test rimraf pacts && jasmine test/*.jasmine.spec.js
[2022-03-04 13:28:40.017 +0000] INFO (59112 on Yousafs-MacBook-Pro.local): pact-node@10.13.3: Creating Pact Server with options:
{"consumer":"ares-integration-services","cors":false,"dir":"/Users/saf/dev/pactoss/pact-js/examples/mocha/pacts","host":"127.0.0.1","log":"/Users/saf/dev/pactoss/pact-js/examples/mocha/logs/mockserver-integration.log","pactFileWriteMode":"overwrite","port":1234,"provider":"BSAPI","spec":2,"ssl":false}
Randomized with seed 44043
Started
[2022-03-04 13:28:40.025 +0000] DEBUG (59112 on Yousafs-MacBook-Pro.local): pact-node@10.13.3: Starting pact binary 'standalone/darwin-1.88.63/pact/bin/pact-mock-service', with arguments [service --consumer ares-integration-services --pact_dir /Users/saf/dev/pactoss/pact-js/examples/mocha/pacts --host 127.0.0.1 --log /Users/saf/dev/pactoss/pact-js/examples/mocha/logs/mockserver-integration.log --pact-file-write-mode overwrite --port 1234 --provider BSAPI --pact_specification_version 2]
[2022-03-04 13:28:40.029 +0000] DEBUG (59112 on Yousafs-MacBook-Pro.local): pact-node@10.13.3: Created 'standalone/darwin-1.88.63/pact/bin/pact-mock-service' process with PID: 59113
[2022-03-04 13:28:40.428 +0000] DEBUG (59112 on Yousafs-MacBook-Pro.local): pact-node@10.13.3: INFO WEBrick 1.3.1
INFO ruby 2.2.2 (2015-04-13) [x86_64-darwin13]
[2022-03-04 13:28:40.428 +0000] DEBUG (59112 on Yousafs-MacBook-Pro.local): pact-node@10.13.3: INFO WEBrick::HTTPServer#start: pid=59113 port=1234
[2022-03-04 13:28:40.550 +0000] INFO (59112 on Yousafs-MacBook-Pro.local): pact@9.16.0: Setting up Pact with Consumer "ares-integration-services" and Provider "BSAPI"
using mock service on Port: "1234"
Pact verification failed!
Actual interactions do not match expected interactions for mock MockService.
Missing requests:
GET /api
See /Users/saf/dev/pactoss/pact-js/examples/mocha/logs/mockserver-integration.log for details.
F[2022-03-04 13:28:40.570 +0000] INFO (59112 on Yousafs-MacBook-Pro.local): pact@9.16.0: Pact File Written
[2022-03-04 13:28:40.570 +0000] INFO (59112 on Yousafs-MacBook-Pro.local): pact-node@10.13.3: Removing Pact process with PID: 59113
[2022-03-04 13:28:40.571 +0000] INFO (59112 on Yousafs-MacBook-Pro.local): pact-node@10.13.3: Deleting Pact Server with options:
{"consumer":"ares-integration-services","cors":false,"dir":"/Users/saf/dev/pactoss/pact-js/examples/mocha/pacts","host":"127.0.0.1","log":"/Users/saf/dev/pactoss/pact-js/examples/mocha/logs/mockserver-integration.log","pactFileWriteMode":"overwrite","port":1234,"provider":"BSAPI","spec":2,"ssl":false}
[2022-03-04 13:28:40.572 +0000] DEBUG (59112 on Yousafs-MacBook-Pro.local): pact-node@10.13.3: INFO going to shutdown ...
INFO WEBrick::HTTPServer#start done.
Failures:
1) API /api when request is not authenticated should fail requiring authentication
Message:
Error: Pact verification failed - expected interactions did not match actual.
Stack:
at new VerificationError (/Users/saf/dev/pactoss/pact-js/examples/mocha/node_modules/@pact-foundation/pact/src/errors/verificationError.js:19:42)
at /Users/saf/dev/pactoss/pact-js/examples/mocha/node_modules/@pact-foundation/pact/src/httpPact.js:108:23
at processTicksAndRejections (node:internal/process/task_queues:96:5)
1 spec, 1 failure
Finished in 0.554 seconds
Randomized with seed 44043 (jasmine --random=true --seed=44043)
"test:jasmine": "rimraf pacts && jasmine test/*.jasmine.spec.js"
so it looks like the mock provider started ok here. You mentioned this was also running inside a docker container?Djalmar Gutierrez
03/04/2022, 1:32 PMYousaf Nabi (pactflow.io)
03/04/2022, 1:32 PMpact-node@10.17.1
pact@9.17.2
Djalmar Gutierrez
03/04/2022, 1:36 PMYousaf Nabi (pactflow.io)
03/04/2022, 1:39 PMexamples/mocha
and run npm i
and then npm test:jasmine
that is working for me. The mocha version is complaining that expect(...).toBe is not a function
you can run that with npm:test
Djalmar Gutierrez
03/04/2022, 2:46 PMYousaf Nabi (pactflow.io)
03/04/2022, 2:54 PM