Hi everyone, I have a scenario that I would like t...
# general
a
Hi everyone, I have a scenario that I would like to understand how to handle it I have one consumer and one provider they have the following: • Bi-directional approach (pactflow) for the contract testing • Messaging integration In the when I publish the contracts and integrations, I get 2 integrations (this is very logical). Now, I want to use can-i-use for both integrations because, in the end, it's the same services with different integrations, but I need to make sure both interactions are good before deploying the services. I would like to know what is the best practice for this scenario.
m
In the when I publish the contracts and integrations, I get 2 integrations (this is very logical).
It’s the same set of apps talking to each other, so it’s possible for it only to be one. If using V4 of the pact spec, there should be one consumer contract with both HTTP and messages If you are using an older spec version, then technically you can’t have both in the same pact file and you would need to map to two different integrations
Assuming you have two sets of integrations:
Consumer
->
HTTP Provider
Consumer
->
Messaging Provider
then if it’s mapped as two integrations, you would need to call
can-i-deploy
(I think this is what you meant?) once on the consumer side (because PactFlow would automatically detect the dependencies) and twice on the provider side, one for each logical name of the provider
a
The problem is that I it tries to generate pact files, and due to same file name (because it's the same consumer and provider) it throws an error. Maybe it's .net library issue
m
Can you please show how you're doing it? What version of Pact .NET are you on?
a
pact .net verson 4.5 This is http integration file
Copy code
var pact = Pact.V3("Cart API", "Products API", pactConfig);
_pactBuilder = pact.WithHttpInteractions();
This is a messaging integration file
Copy code
var pact = Pact.V3("Cart API", "Products API", pactConfig);
_pactBuilder = pact.WithMessageInteractions();
When I run it, I get the following error. The reason for it is that all the tests run in parallel, so you can't create the same file with the same name in parallel.
Copy code
Test method Cart.API.Tests.ProductsEventsTests.ReceiveSomeProductsEvents threw exception: 
PactNet.Exceptions.PactMessageConsumerVerificationException: The message could not be verified by the consumer handler ---> System.InvalidOperationException: The pact file could not be written
    at PactNet.Drivers.AbstractPactDriver.WritePactFile(String directory)
   at PactNet.ConfiguredMessageVerifier.Verify[T](Action`1 handler)
--- End of inner exception stack trace ---
    at PactNet.ConfiguredMessageVerifier.Verify[T](Action`1 handler)
   at Cart.API.Tests.ProductsEventsTests.ReceiveSomeProductsEvents() in /Users/arnoldsi/Desktop/dev/Pact-Demo/poc-pactflow-consumer-1/Cart.API.Tests/ProductsEventsTests.cs:line 39.
m
what happens if you don’t run them in parallel? Does it work?
The reason for it is that all the tests run in parallel, so you can’t create the same file with the same name in parallel.
Are you sure this is true? The underlying core knows how to put file locks etc. in place, so this (parallel tests) should be allowed
a
The unit tests are always run in parallel and they create this error of write exception
Even if I run them one after another, I get this error. Only when I change the consumer or provider name it's working, but it's creates a new pact file and new integration
m
Thanks. Can you please raise a bug on the Pact .NET repo?
Just for clarity, it needs to be a V4 serialised pact for this to work. It won't work on a spec version 3 or earlier.
In V4 support was added to store both HTTP and non-http requests in the same file
a
I will raise the issue. Just for clarification, V4 is .net version 5.0.0, right?
m
Yes, I'm referring to the pact specification and not Pact .Net version.