Hi team, I work at Macmillan Learning on a team ca...
# pact-broker
a
Hi team, I work at Macmillan Learning on a team called "writing tools" and I'm encountering an issue I believe might be related to Provider States and state handlers (which as far as I know we aren't using). I would love any advice that you can offer. My error previously mentioned "no null state handler present" prior to failing, and my new error occurs at nearly the same point in our Jenkins build and publish process, and looks as follows: Verifying writing 0.0.0-8477ca993 [2022-08-09 141240.376 +0000] INFO (29 on d53225d7acfa): pact@9.18.1: Verifying provider [2022-08-09 141240.389 +0000] INFO (29 on d53225d7acfa): pact-node@10.17.6: Verifying Pacts. [2022-08-09 141240.391 +0000] INFO (29 on d53225d7acfa): pact-node@10.17.6: Verifying Pact Files Error: connect EINVAL 0.0.11.184:80 - Local (0.0.0.0:0) at internalConnect (nodenet953:16) at defaultTriggerAsyncIdScope (nodeinternal/async hooks465:18) at GetAddrInfoReqWrap.emitLookup [as callback] (nodenet1097:9) at GetAddrInfoReqWrap.onlookup [as oncomplete] (nodedns73:8) { errno: -22, code: 'EINVAL', syscall: 'connect', address: '0.0.11.184', port: 80 } error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
👋 1
m
Hi Alison, this looks like a JS issue. Does it work on your local machines and only fail on CI? We’ll need a bit more info in addition to this to see what’s happening
(howtotroubleshoot)
s
To help assist with debugging your issue, please provide: your pact test setup (code), the generated pact file and terminal output/relevant log files. Please note: statements such as "I cannot share in public because it's commercially sensitive" are not helpful. See this link on how to produce a minimal reproducible example that we can use to help you: https://stackoverflow.com/help/minimal-reproducible-example
m
please see the tips above. What makes you believe it’s a provider states issue and not something else? The logs shown don’t point to that. It looks like the verifier is trying to connect to port
80
on
00.0.11.184
. That looks to be a non-local IP address, and the verifier is unable to reach it. You might find that instead of pointing to
localhost
, pointing to
127.0.0.1
(or the correct local IP) might work
a
Hi Matt, thanks for the suggestion! I thought it was related to provider states because it started showing up at the same time as the message "pact@9.18.1: No state handler found for "null", ignoring", which caused me to add
Copy code
stateHandlers: {
        [null]: () => {
          // This is the "default" state handler, when no state is given
          console.log('hit null state, handling')
        }
      },
to my Verifier.
m
interesting
did you manage to resolve it?
a
Everything was working perfectly in CI pipeline and then out of the blue on a fresh rebuild we started hitting this error. I'm still trying to locate what changed or the source of the issue is.
👍 1
Locally verify completes its execution without issue.
Copy code
Finished verifying writing
Reading json outputfile ...writing/api/app/tests/pact-tests/pact-verify-result.json
6 examples, 2 failures
Verification Failed...
One known issue (that I doubt is related to this error) is that we are generating a new random uuid on the consumer side and republishing the pact any time we want verify to pass, since we can't get around a no-duplicate-creation issue in our POST requests to the actual writing DB in our testing. We are not mocking the server. So that's why there are 2 failures. But that is fixed each time we recreate the pact and re-run verify.
😬 1
m
We are not mocking the server.
do you mean, you’re hitting a live service or that you aren’t mocking dependencies? In case it’s not clear, you should definitely not mock the provider that you’re verifying
a
Right, we are NOT mocking the provider, we are hitting the actual provider API and modifying the real DB. This was a point of debate on the team, but in the end we agreed to hit the real provider API since that's the only way (imo) Pact really serves its purpose.
So we are indeed hitting a live service but I'm fairly unclear on what this connection is that's failing, I have no idea what lives on that port 80 at that IP addr, I'm very new to this side of things as I'm mostly a front end dev XD
Is there something else I can put in the Null State handler now that I know I am getting into that block (my console.log has come out from there just prior to the error) that would perform the default behavior? We don't have any different possible states in this context on the Consumer side, and I wasn't sure what was meant in the Provider State Docs by the Promise.resolve that was the example here:
Copy code
"Has no animals": () => {
      animalRepository.clear()
      return Promise.resolve(`Animals removed from the db`)
    },
Is the Promise being referred to some hypothetical animalRepository.clear() function that wouldn't exist in my context? Or is this a default behavior inside the Pact stateHandler where I could put Promise.resolve(
'Completed Pact Verify'
)?
This issue has been resolved. I was pointed to localhost where I should have been pointed to the live Provider API due to a brief test I forgot I did and then never changed it back. I was fixating on the broker url but the one that was off was the provider url in verify.js. Thanks for the advice Matt! Your URL check suggestion was on point.
m
I think you can ignore the null state handler, it won't impact anything
Glad to hear it's sorted though!
I will say, it's not best practice to point to a live provider, we recommend testing against a locally running provider with third party dependencies stubbed out. Live servers will be hard to manage as state becomes more important, and you're likely to get flakey and unreliable tests as a result
For the same reason the e2e tests can be painful, running tests against a live server is a step in that direction.
b
I’ve just added a FAQ for that, as it’s come up a few times recently https://docs.pact.io/faq#can-i-verify-my-pacts-against-a-deployed-instance-of-a-provider
👍 1
m
The other practical reason is that using provider states is very hard to do this way.
b
good point. i’ll add that.
👍 1
m
thx