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

How to handle pact:verify with dependencies to other µServices ? #755

Closed
AlexTess opened this issue Aug 10, 2018 · 6 comments
Closed

How to handle pact:verify with dependencies to other µServices ? #755

AlexTess opened this issue Aug 10, 2018 · 6 comments

Comments

@AlexTess
Copy link

Hello,

I was wondering if there was a common way to handle the following case:
Let's say I have 3 services that interact like this: (A) ==> (B) ==> (C)
Naturally, I have pacts between A & B, and B & C

The issue is, when B is verifying the contract from consumer A, it fails because C isn't running (and it needs to have C running for the pact to return the expected result).

We're using provider states already, but usually they pertain to data that need to exist for the pact to be verified, that can be provisioned through api.
We could, I guess, use provider states to run a mock of (C) if needed, but I was wondering if others were facing this issue and if this was the recommended way for such case or if I missed something ?

One of my issue with this solution, is that it implies that (A) needs to have a state that would be something like "given (C) is running' which doesn't make much sense (it's not something they should have to know).

Thanks in advance for any inputs, ideas ?

@uglyog
Copy link
Member

uglyog commented Aug 12, 2018

The best approach is to stub out the interactions downstream when verifying an interaction upstream. You can use a web mock server (like Mocky, Mock-Server ot the pact-stub-server), or if you are using JUnit tests to verify, you can either mock out the call to the downstream client code or use something like Wiremock.

@AlexTess
Copy link
Author

Thanks for your answer. Yes, I am on board with the mocking. However, since I'm using maven for the pact verify, I don't have a way to launch a mock from there (as far as I could tell). is there a way to do this with the pact-provider-maven ?

Otherwise, the only place where I could launch mock through java would be the pact state change, which is not the most convenient, in my opinion.

@uglyog
Copy link
Member

uglyog commented Aug 26, 2018

With Maven you can bind the plugin goals to a phase. There is an integration test phase, which has a pre-integration-test and post-integration-test phase. See https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html

@AlexTess
Copy link
Author

AlexTess commented Sep 7, 2018

Thank you. The problem in our case is that all our IT tests are bound to those phases, including the ones that do not run against pact. Not all ITs are linked to testing the interface with other µServices, and may mock within the test with other tools/context etc.
So, if we used the pre-integration phase to launch a generic mock (to be used by pact), it would conflict with other mocks.
I've gone around the issue by using the Pact Provider Junit to verify the contracts instead of using maven plugin, which allows to launch the mock within this specific context. But using maven was my preference beforehand, hence my question.
No one raised this need before, I assume ?

@uglyog
Copy link
Member

uglyog commented Sep 9, 2018

You could use a different port for the mock server, and the tests could configure the port appropriately. But to be honest, I think using Pact Provider Junit is the better way as it gives you more control, you can use mock libraries like Mockito and you don't have to have the whole server running for the test.

But, yes, nobody has raised this as an issue before ;-).

@AlexTess
Copy link
Author

Yes, the problem with using different port is the µService only communicates with a defined one, and I'd like to avoid redeploying each time I need a new mock, that is too costly in terms of execution time.

But alright, I agree given our discussion that Pact Provider Junit is the best suited solution for our needs.
Thank you !

@uglyog uglyog closed this as completed Feb 22, 2020
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

2 participants