Kinda related to <this thread>, but does pact-jvm ...
# pact-jvm
s
Kinda related to this thread, but does pact-jvm have a modern way to select multiple consumers for a given provider test? i.e. if a provider has a known set of consumers (rather than just one) we would like to run all tests for those on the same class if possible. Using
@Consumer
only allows one consumer per test class. I see that
@PactBroker
annotation has the
consumerVersionSelectors
field, but that is apparently deprecated. The
@PactBrokerConsumerVersionSelectors
method with
SelectorBuilder
doesn't appear to have any way to select multiple consumer names. Is there a better approach?
y
You can provide raw json with
rawSelectorJson(json: String)
and pass the consumer name selectors https://docs.pact.io/pact_broker/advanced_topics/consumer_version_selectors#advanced it takes an array of selectors, so you can provide scope your selector with the consumer name
note: I’ve not tested it, but that is why we allow the raw selectors to be passed through, because the core impl should support that fetching mechanism
s
Is this something that will be officially supported for a while? Just a little hesitant to use the raw JSON since we lose some of that first class support
y
the client language provide little decorators but tie the client impls with the core impl. having raw json selectors, means you can always use the latest your broker supports without having to worry about your language keeping up to date
obviously we want all the nice named selectors in the DSL, I am sure a PR wouldn’t go amiss to add a consumer name property as a first class thing 🙂
s
Yeah I'm not opposed to submitting a PR upstream if thats something you all would support 🙂
y
ps. I don’t live in the pact-jvm world much, @uglyog is our jvm dude, you can always raise an issue on the repo and we can see if there would be support for it 👍
s
Thanks! On a side note, do you have any thoughts on the linked thread above?
u
By default, a provider test will verify the pacts for all consumers. This is by design. You shouldn't need to specify the consumers.
s
In our case though we were running into an issue where we just split up provider tests to different classes. So we had something like:
ProviderATest
(consumed by
consumer-a
) and
ProviderBTest
(consumed by
consumer-b
) in the same monolithic project, each with their own states since they're pretty disjoint features. Pact was then complaining that
ProviderATest
didn't have the states that
ProviderBTest
verified and vice versa
Are we just going about this all wrong? Or are there better guides for using Pact in a chonky monolith provider?
y
I'll be honest Si, I work better with visuals once there are more than a few hops in our scenario and a big thread. I also haven't had time to dip into that other thread yet. How artsy are you feeling? Do you think you could roughly draw up the chonkie boi. It might give us a better working base to get in the head space. If your crayolas are a bit blunt, you could whip up a sample repo? I don't mind diving into code.
p
Does this bad drawing help at all @Yousaf Nabi (pactflow.io) 😆 All of the provider tests within the same monolith are separate classes with their own unique set set states since they are all for different consumers but they all have the same
@Provider(Monolith)
annotation
😅 1
plusone 1
chefkiss 1
thank you 1
s
(@Phillip Lo and I are working on the same project btw)
🙌 1
y
perfect! could you consider the three providers in the monolith to be of separate concerns, they just live in the same home, say name them by convention monolith-provider-a. assume they all deploy together so they would share the same version number. at the point of deployment for the monolith you would check can i deploy with repeated arguments for each names monolith-provider-x
consumer side they would just call can i deploy with thier own name, they don’t appear to be relayed to anything else. but effectively if they made a contract with 2nd micro service in the monolith, this would be picked up at both ends. the only pain point i see if when you want to deploy the mono but one of the services inside isn’t compat. hopefully they are ironed out pre deploy and on the provider verification side you have enable pending pacts and include wip pacts since date set
that diagram is spot on @Phillip Lo and ralph wave
also my choice of verbiage confused my colleagues so i am glad you guys got it 😂
p
can you explain this line
the only pain point i see if when you want to deploy the mono but one of the services inside isn't compat.
y
so monorepo is made up of say 3 micro providers. they each talk to one, different consumer. the monorepo has a single version number of which you wish to deploy into an environment. that version number would be shared around the 3 micro providers ( as the version number relates to the code you are releasing and they all comprise in a single repo ) if one of the micro providers in the mono repo isn’t compatible with its consumer, none of your monorepo can be deployed, blocking the other micro providers. i am using a term micro provider here loosely, to represent your provider test class a, b and c in your diagram. i assume these aren’t that related and are effective distinct providers from each consumers perspective?
it’s probably far more nuanced, but that is my simplistic view based on the diagram
p
yea, unfortunately they could be distinctive but are also many times related and could actually be the exact same "microprovider"
I think thats where in the other thread the sharing states came into play. ie. What do we do if it is actually the same set of endpoints in each Provider test class but they are used by different consumer microservices? Do we have to tell every consumer to write their contracts with the same states? We were hoping that they could be independent with their own set of provider tests but seems not
y
hmm. so there is the idea of provider states with params in v3 and v4. could this allow the idea of some kind of shared state and then a permutation based on a particular clients needs ( as informed by the state params )
then in the provider verification you can match on the state description and then do actionable items based on the param conditions. that way you aren’t filtering contacts, but processing the states potentially for different consumers needs or some kind of shared state default
provider states should be discussed with provider team by the team generating the contracts, otherwise it’s fair game imo to have a process where as this new pact is now validated and say fails on state because consumers hadn’t collaborated, that they are forced to now collab and potentially update the generated states in their test. the onus is on the consumer to get a successful verification in order to deploy, the provider will be happy enough without any consumers. that doesn’t mean they can yolo a contract over the fence and hope for the best
👍 1