Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Got Net::HTTPFatalError: 503 "Service Unavailable" when provider verify the pact #315

Closed
AlanEnjoy opened this issue Oct 31, 2022 · 6 comments

Comments

@AlanEnjoy
Copy link

AlanEnjoy commented Oct 31, 2022

I try to verify the pact through the code below
but always got "Net::HTTPFatalError: 503" error as below and I check my provider api logs. No call happened.
And I can verify it by the pact-provider-verifier CLI tool with the same config.
Anything went wrong ?

issue code:
PACT_BROKER_URL = "**********"
PACT_BROKER_TOKEN = "***********"

PROVIDER_HOST = "*********.com"

PROVIDER_URL = f"https://{PROVIDER_HOST}"

@pytest.fixture
def broker_opts():
return {
"broker_url": PACT_BROKER_URL,
"broker_token": PACT_BROKER_TOKEN,
"publish_version": "3",
"publish_verification_results": True,
}

def test_user_service_provider_against_broker(broker_opts):
verifier = Verifier(provider="partner-content", provider_base_url=PROVIDER_URL)
success, logs = verifier.verify_with_broker(
**broker_opts,
# verbose=True,
enable_pending=False
)

error log:
`
E assert 1 == 0

tests/provider/test_provider.py:61: AssertionError
------------------------------------------------------------------------------------------------------------------ Captured stdout call ------------------------------------------------------------------------------------------------------------------
INFO: Fetching pacts for partner-content from *********** with the selection criteria:
INFO: Reading pact at ******
WARN: Please note: we are tracking events anonymously to gather important usage statistics like Pact-Ruby version
and operating system. To disable tracking, set the 'PACT_DO_NOT_TRACK' environment
variable to 'true'.

DEBUG: The pact at ******* is being verified because the pact content belongs to the consumer version matching the following criterion:
* latest version of partner-front-end that has a pact with partner-content (1.0.0)

Verifying a pact between partner-front-end and partner-content
Given fetch correct facility sections
a request to fetch the correct section
with GET /fresa/extranet/content/facilities/sections/get?hotel_id=2556459&ses=0ebee5e52eee39ee1ebef0b79252042d&lang=en
returns a response which
WARN: Skipping set up for provider state 'fetch correct facility sections' for consumer 'partner-front-end' as there is no --provider-states-setup-url specified.
has status code 200 (FAILED - 1)
WARN: Skipping set up for provider state 'fetch correct facility sections' for consumer 'partner-front-end' as there is no --provider-states-setup-url specified.
has a matching body (FAILED - 2)

Failures:

  1. Verifying a pact between partner-front-end and partner-content Given fetch correct facility sections a request to fetch the correct section with GET /fresa/extranet/content/facilities/sections/get?hotel_id=2556459&ses=0ebee5e52eee39ee1ebef0b79252042d&lang=en returns a response which has status code 200
    Failure/Error: replay_interaction interaction, options[:request_customizer]

    Net::HTTPFatalError:
    503 "Service Unavailable"
    /Users/szhu2/Projects/main/venv/lib/python3.9/site-packages/pact/bin/pact/lib/ruby/lib/ruby/2.2.0/net/http/response.rb:119:in error!' /Users/szhu2/Projects/main/venv/lib/python3.9/site-packages/pact/bin/pact/lib/ruby/lib/ruby/2.2.0/net/http/response.rb:128:in value'
    /Users/szhu2/Projects/main/venv/lib/python3.9/site-packages/pact/bin/pact/lib/ruby/lib/ruby/2.2.0/net/http.rb:915:in connect' /Users/szhu2/Projects/main/venv/lib/python3.9/site-packages/pact/bin/pact/lib/ruby/lib/ruby/2.2.0/net/http.rb:863:in do_start'
    /Users/szhu2/Projects/main/venv/lib/python3.9/site-packages/pact/bin/pact/lib/ruby/lib/ruby/2.2.0/net/http.rb:858:in `start'

  2. Verifying a pact between partner-front-end and partner-content Given fetch correct facility sections a request to fetch the correct section with GET /fresa/extranet/content/facilities/sections/get?hotel_id=2556459&ses=0ebee5e52eee39ee1ebef0b79252042d&lang=en returns a response which has a matching body
    Failure/Error: replay_interaction interaction, options[:request_customizer]

    Net::HTTPFatalError:
    503 "Service Unavailable"
    /Users/szhu2/Projects/main/venv/lib/python3.9/site-packages/pact/bin/pact/lib/ruby/lib/ruby/2.2.0/net/http/response.rb:119:in error!' /Users/szhu2/Projects/main/venv/lib/python3.9/site-packages/pact/bin/pact/lib/ruby/lib/ruby/2.2.0/net/http/response.rb:128:in value'
    /Users/szhu2/Projects/main/venv/lib/python3.9/site-packages/pact/bin/pact/lib/ruby/lib/ruby/2.2.0/net/http.rb:915:in connect' /Users/szhu2/Projects/main/venv/lib/python3.9/site-packages/pact/bin/pact/lib/ruby/lib/ruby/2.2.0/net/http.rb:863:in do_start'
    /Users/szhu2/Projects/main/venv/lib/python3.9/site-packages/pact/bin/pact/lib/ruby/lib/ruby/2.2.0/net/http.rb:858:in `start'

1 interaction, 1 failure

`

@mefellows
Copy link
Member

503 service unavailable suggests the service is unavailable, so this might be hard for us to debug for you.

If you could please set logging of the test to debug so that we can see the request/response, and ideally provide the log file from the verifier, this would help.

You should also review the logs from your provider to see what might be going on.

It also looks like you're verifying against a deployed environment. Whilst this is supported, it's not recommended (harder to get fine grained control over the test) and as we're seeing here, harder to get logging information as to why the service is erroring out.

@AlanEnjoy
Copy link
Author

AlanEnjoy commented Nov 3, 2022

Thanks for replying. Yes, we are verifying against a deployed environment for a demo because it's kind hard to verify our app in local now.
Actually the real issue confused me is the provider service is good. We can call the API by curl&postman. Even I can verify it by the pact-provider-verifier CLI tooling. And we can get the right access log from provider side.
But we I'm trying use the upper code to do verification. It response with 503 "Service Unavailable" after a long time waiting(2 or 3 mins). And nothing appeared in the provider access log which means no request sent to the provider service
I do set the log level to DEBUG(by code logging.basicConfig(level=logging.DEBUG)) but I still can not get the request and response info when I run the test.
So I report this issue because the responses are truly different between code demo(503) and pact-provider-verifier CLI(verify successfully).
Anyway I can use pact-provider-verifier CLI to finish my demo. Thanks

@mefellows
Copy link
Member

I do set the log level to DEBUG(by code logging.basicConfig(level=logging.DEBUG)) but I still can not get the request and response info when I run the test.

Is that a Pact method?

To enable better logging, I believe these are the parameters to do so: https://github.com/pact-foundation/pact-python/blob/master/pact/verifier.py#L99-L100

Glad to hear you're moving ahead, but I'd still love to see you getting the Python library up and running as in the long term it should be better for you.

@AlanEnjoy
Copy link
Author

Thanks again. After walking through the source code and debugging I think I have located the problem. Mostly because the pact binaries combined in pact-python is incompatible with my local dev env
I just run the pact-provider-verifier(md5: facd78d6de9c3eee604a60d804f13454 ) cmd generated in code which pact binary in python site-packages/pact/bin/pact/bin, it won't work
But when I use the pact-provider-verifiers(md5: 7e9cbbf1d1cfe0f47b9913fa99993014 ) I downloaded before. It works fine. That explains why this issue comes up.
So I try to do a offline Installation of Standalone Packages to avoid it like readme suggested.
pip install pact-python --bin-path=/absolute/path/to/folder/containing/pact/binaries/for/your/os
But it returned with "no such option: --bin-path"
Any other suggestions?

@AlanEnjoy
Copy link
Author

AlanEnjoy commented Nov 9, 2022

Same issue when I run it in my gitlab pipeline with pact-provider-verifier(md5: facd78d6de9c3eee604a60d804f13454 ) integrated in pact-python. I download the pact standalone with version 1.88.83. The pact-provider-verifier won't work too with same 503 error. How about update the pact binaries integrated in pact-python to the latest?

@YOU54F
Copy link
Member

YOU54F commented Aug 3, 2023

You may wish to try again with pact-python 2.x - it included the latest pact-ruby-standalone which has an updated ruby runtime.

If not, and you can provide a reproducible example. I have a GitLab account and a self hosted instance in my homelab so can help out.

Will close this issue for now, feel free to reply and we can reopen if you wish

@YOU54F YOU54F closed this as completed Aug 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants