ITV / scala-pact

A Scala implementation of CDC using the Pact standard
Other
108 stars 54 forks source link

Verify from Pact Broker fails with no useful information #98

Open adam-pike-dunelm opened 6 years ago

adam-pike-dunelm commented 6 years ago

Description:

I want to verify my provider against a pact on a remotely hosted Pact Broker (the Beta version provided by Pact). But I get a Failed to load consumer pact from: <url> message.

There's nothing to help me understand why either in the consol or the logs. The Verification works fine against a local pact file.

Steps:

Added the following to my build.sbt

pactBrokerAddress := "https://my-pact-broker:4321"
providerName := "The Name Of This Service"
consumerNames := Seq("Consumer A")

Have checked that all of my values are correct on the above and even tried adding it to a pact.sbt but got the same result.

Ran the following:

sbt "pact-verify --host localhost --port <port-number-of-running-service>"

Expectation:

If all is well a test result. If all is not well, a useful error message that points to why it failed

Actual:

Attempting to fetch pact from pact broker at: https://<url>/latest
[http4s-blaze-client-5] INFO org.http4s.client.PoolManager - Shutting down connection pool: allocated=1 idleQueue.size=1 waitQueue.size=0
Failed to load consumer pact from: https://<url>/latest
Verifying against 'localhost' on port '9000' with a timeout of <unspecified> second(s).

Sorry if I have missed anything obvious, but I didn't really know where to start with debugging this.

adam-pike-dunelm commented 6 years ago

FYI: I can pull down the pact file via a Postman GET

davesmith00000 commented 6 years ago

Can I just check: your examples above reference http and https, is that just an oversight as you wrote up the issue?

adam-pike-dunelm commented 6 years ago

Correct - I have the whole lot as https. I copied the first snippet from from the pact documentation, will edit.

adam-pike-dunelm commented 6 years ago

Actually, I've just realised - where I have successfully download via Postman, I had read access username and password basic auth. Are there any options for this on the scala-pact CLI?

davesmith00000 commented 6 years ago

Try this: https://github.com/ITV/scala-pact/blob/cfc5aa819baa6eac439b5f01c4d360286829ceb9/scalapact-core/src/test/scala/com/itv/scalapactcore/common/PactBrokerAddressValidationSpec.scala#L34

adam-pike-dunelm commented 6 years ago

OK I gave that a go and I get the same result. I copied the url from the console output and compared it with what I have in postman and they're exactly the same.

Just for thoroughness I tried switching to our guest wifi and I now get a different error:

Error: Client request timeout after 2 seconds.

So I suspect the first fail was something to do with the corp network - although it allowed postman requests weirdly.

Is there a way I can extend the default timeout of 2 seconds?

davesmith00000 commented 6 years ago

Yes, sounds like we might be making some progress. You're literally the second person to report this problem and the first guy also submitted the PR with the test case I pointed you to. :-)

Try this: sbt "pact-verify --host --port --clientTimeout 10"

There is, unfortunately, this issue which I discovered yesterday: https://github.com/ITV/scala-pact/issues/99

That issuse shouldn't be the problem however, just a symptom of something else, 2 seconds to Scala-Pact might as well be two minutes. Assuming you're contract file isn't gigantic and you're network isn't really really poor, then a client timeout usually means that the details to your pact broker or to your running service are incorrect.

Something to try!

Use Postman or Curl to download the Pact file, and then do this to run the verification from a local source: sbt "pact-verify --host --port --source "

If that works, then it's definitely something to do with your ability to connect to pact broker, if it doesn't work then the problem (or one of the problems) is that you're not setup to hit your service properly.

Let me know how you get on!

adam-pike-dunelm commented 6 years ago

Thanks Dave,

Using the --clientTimeout does prevent my timeouts so I just have rubbish internets here. But I'm back to the original error being shown constantly. I can run against the downloaded file as a local source no problem and I really can't see what is wrong with my pact setup for downloading - the documented setup is really simple and I've double checked everything is right.

I'm not going to burn more time on it for now as there's a simple solution - I download from Pact Broker to a local directory with another client as a pre-step to running pact.

davesmith00000 commented 6 years ago

Hmmm.. I'll also take an action to look into this more carefully. I was satisfied that the committer had done the right thing the first time around (given that he'd fixed his own problem!) but I'll give it some more attention when I get a few minutes and see if I can replicate it at least.

Glad to hear you have a work around for now though.