pact-foundation / pact-net

.NET version of Pact. Enables consumer driven contract testing, providing a mock service and DSL for the consumer project, and interaction playback and verification for the service provider project.
https://pact.io
MIT License
823 stars 225 forks source link

Multiple integrations with same Consumer and Provider cause to pact file write errors #509

Closed arnoldsi-payo closed 4 days ago

arnoldsi-payo commented 4 days ago

Version information:

following conversation here: https://app.slack.com/client/T5F60FXSQ/C5F4KFKR8 There are two sets of integrations (same consumer and same provider: Consumer -> HTTP Provider (Provider 1) Consumer -> Messaging Provider (Provider 1)

This is HTTP integration file

var pact = Pact.V3("Cart API", "Products API", pactConfig);
_pactBuilder = pact.WithHttpInteractions();

This is a messaging integration file

var pact = Pact.V3("Cart API", "Products API", pactConfig);
_pactBuilder = pact.WithMessageInteractions();

When I run it, I get the following error.

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.
mefellows commented 4 days ago

As discussed on slack, this is because you're generating a V3 spec pact file which doesn't support serialising mixed interaction types.

The new beta version of Pact .NET will support this as it can generate V4 pacts

arnoldsi-payo commented 4 days ago

@mefellows, are there any updates on when the stable version will be released? It's very problematic to integration beta versions in our Enterprise

YOU54F commented 4 days ago

we need people to use the library and provide feedback.

the beta status shouldn't be an issue and isn't our concern as maintainers, that you are unable to run betas in enterprise.

the best solution for you with v3 capabilities is to name your message provider differently than your http provider as has always been the guidance for v3 pacts

YOU54F commented 4 days ago

path to release is here as set out the this repos maintainer

https://github.com/pact-foundation/pact-net/milestone/5

arnoldsi-payo commented 4 days ago

we need people to use the library and provide feedback.

the beta status shouldn't be an issue and isn't our concern as maintainers, that you are unable to run betas in enterprise.

the best solution for you with v3 capabilities is to name your message provider differently than your http provider as has always been the guidance for v3 pacts

In this case, I must manage the connection between consumers and providers in some DB, in order to "group" different integrations of the same consumer-provider

adamrodger commented 4 days ago

The roadmap for v5 is close now, with some final issues to fix and testing to perform.

I've been using the beta for a few months now in production and not had any issues, so I'd encourage you to give it a try in the meantime if the alternatives suggested above don't work for you 👍

adamrodger commented 4 days ago

Closed just because there's no planned change here. The "fix" for this use case is in v5 and pact specification v4.