Hello, I'm testing a service (`users-service`) whi...
# pactflow
t
Hello, I'm testing a service (
users-service
) which is both an API provider and a API consumer. The provider test works
Copy code
CONSUMER           | C.VERSION                                  | PROVIDER      | P.VERSION                                     | SUCCESS? | RESULT#
-------------------|--------------------------------------------|---------------|-----------------------------------------------|----------|--------
gdprexport-service | C-5cf6a5f1b2e171382a3f0dee4e8696d8a0c34685 | users-service | P-v2-f1e31679d8f7a7c144ca63d80a5ebf69ac92719d | true     | 1
But for some reason an the
gdprexport-service
, which is the API consumer, is also tested against the
users-service
consumer pact 🤯
Copy code
CONSUMER           | C.VERSION                                  | PROVIDER      | P.VERSION | SUCCESS? | RESULT#
-------------------|--------------------------------------------|---------------|-----------|----------|--------
gdprexport-service | C-5cf6a5f1b2e171382a3f0dee4e8696d8a0c34685 | users-service | ???       | ???      |        
users-service      | C-f1e31679d8f7a7c144ca63d80a5ebf69ac92719d | accounts-api  | 6.5.2     | true     | 1
Copy code
There is no verified pact between the latest version of gdprexport-service (C-5cf6a5f1b2e171382a3f0dee4e8696d8a0c34685) and version C-f1e31679d8f7a7c144ca63d80a5ebf69ac92719d of users-service
We prefix the consumer version with
C-
and the provider version with
P-<api-version>
. Actually pactflow should only test
Copy code
gdprexport-service | C-5cf6a5f1b2e171382a3f0dee4e8696d8a0c34685 | users-service | P-v2-f1e31679d8f7a7c144ca63d80a5ebf69ac92719d 
users-service      | C-f1e31679d8f7a7c144ca63d80a5ebf69ac92719d | accounts-api  | 6.5.2
and not
Copy code
gdprexport-service | C-5cf6a5f1b2e171382a3f0dee4e8696d8a0c34685 | users-service | ???
How can I fix this?
b
Hi @Thomas, could you try identifying the pacticipants as
users-service-consumer
when it is a consumer and
users-service-provider
when it is a provider?
👍 1
t
Didn't thought about this option so far, but I can give it a try.
On the other hand, shouldn't it be clear for pactflow, that a consumer should only be tested against a provider and vice versa?
Are the different versions
C-
and
P-
confusing the system?
b
I don't know the exact logic that Pactflow users to determine whether some pacticipant is a consumer or a provider, maybe it's all in one big list / table 🙂 The core maintainers can probably tell you more about that. The different
c-
and
p-
versions should not be the problem, you can use pretty much whatever you want as a provider or consumer version identifier (although there are some good practices)
b
The logic should only be "does this pacticipant send requests or receive requests?" (i.e. just the directionality of requests, which is typically one-way per contract)
☝️ 1
You shouldn't need to identify different parts of the same app as consumer vs provider. That would make some things hard to reconcile (like the pacticipants dependency graph, and maybe preverification).
☝️ 1
💡 1
I'm not sure why the verifications are getting confused, unless you've specified the wrong names in the contract setup, or something think up hopefully a maintainer can jump in and answer soon 🙂
m
You shouldn’t need to identify different parts of the same app as consumer vs provider. That would make some things hard to reconcile (like the pacticipants dependency graph, and maybe preverification). (edited)
yes, why are you doing this? It doesn’t make sense (at least without further explanation) for a version of the software to be a consumer and another version of the software to be a provider. Either it is both, or it isn’t, and the version is orthogonal to that
t
Thank you for your answers. So far I didn't change the pacticipant-name. Any other suggestions?
m
It would help if you explain your setup in a diagram. In fact, the network diagram in PactFlow would help to see what’s happening
these also look like
can-i-deploy
outputs, it would be helpful to see how you are invoking that command
👀 1
So far I didn’t change the pacticipant-name.
what do you mean by this?
t
👍 1
👌 1
m
This diagram has
rt-
prexfies on the apps - did you manually modify the output from above to drop that?
t
what do you mean by this?
@Matt (pactflow.io / pact-js / pact-go) I referred to the first suggestion from @Bas Dijkstra
👍 1
did you manually modify the output from above to drop that?
Yes, because the prefix doesn't matter for the example.
👍 1
m
Can you please show the arguments you used to generate this?
t
Copy code
if [ "$(params.publish-consumer-contract)" = "true" ] ; then
          if [ -n "$(params.pact_deploy_to_environment)" ] ; then
            pact-broker can-i-deploy\
             --broker-base-url=$(params.pact_broker_base_url)\
             --broker-token=$PACT_BROKER_TOKEN\
             --pacticipant=$(params.pact_pacticipant)\
             --version=C-$(params.git_sha)\
             --to-environment=$(params.pact_deploy_to_environment)\
             --retry-while-unknown=2\
             --retry-interval=10
          else
            pact-broker can-i-deploy\
             --broker-base-url=$(params.pact_broker_base_url)\
             --broker-token=$PACT_BROKER_TOKEN\
             --pacticipant=$(params.pact_pacticipant)\
             --version=C-$(params.git_sha)\
             --retry-while-unknown=2\
             --retry-interval=10
          fi
        else
Currently we are not setting the
to-environment
(we are on it).
m
This row says
gdprexport-service
can’t be deployed (to wherever the target you specified is) because the
users-service
is required for it to operate.
Copy code
CONSUMER           | C.VERSION                                  | PROVIDER      | P.VERSION | SUCCESS? | RESULT#
-------------------|--------------------------------------------|---------------|-----------|----------|--------
gdprexport-service | C-5cf6a5f1b2e171382a3f0dee4e8696d8a0c34685 | users-service | ???       | ???      |
It goes on to say:
Copy code
There is no verified pact between the latest version of gdprexport-service (C-5cf6a5f1b2e171382a3f0dee4e8696d8a0c34685) and version C-f1e31679d8f7a7c144ca63d80a5ebf69ac92719d of users-service
I think you are confused by versioning. The version is the piece of software you’re releasing (e.g. git sha a1b2c3). If
users-service
is both a consumer and a provider, then it should only have one version. Because when you deploy it, you only deploy one version of it. I suspect this is why it’s picking up the
C-
version. The last time
users-service
is deployed to <target>, it was the version with
C-
. I think that is causing some confusion about how all of this works.
OK, so in lieu of specifying an environment, I think this will just verify against the latest provider. If the latest version of
users-service
is
C-
then that would also explain it
either way, your versioning is a bit strange
t
We came up with this, because the services offers different (legacy, but still active) API versions. Currently we are testing the provider against API version 2 ->
P-V2-<git-sha>
. I think using only the
<git-sha>
as version lead pactflow test the consumer against all APIs, where of course only one test succeeded, but I can't remember exactly. Is your recommendation to use the
<git-sha>
without prefix for both consumer and provider and for all API versions?
m
Yes, that would be my recommendation. If the API is versioned and logically different, you could: 1. Use the
releases
to model that two concurrent released versions in the wild (see https://docs.pact.io/pact_broker/recording_deployments_and_releases#releases) 2. Create a new name of the API to indicate it’s a separately deployed thing (e.g.
users-service-v2
) It sounds like it’s the same deployable unit that supports multiple interfaces (API versions), so I don’t think these actually make sense for you.
thankyou 3 1
👀 1
t
OK, I'll have a look into that. Thank you.
👍 1
Short update: Using only the git-sha as
version
in combination with
releases
and
deployments
worked so far.
👍 2
... until now. I reproduced the original issue, which lead to add a prefix to the
version
. We have a micro service with 2 API versions (
v1
and
v2
). Those two API versions are documented in 2 separate OAS files.
Copy code
Error making request to <https://adidascdc.pactflow.io/provider-contracts/provider/rt-consents-service/publish> status=409 {"title":"Conflict","type":"<https://adidascdc.pactflow.io/problems/conflict>","detail":"A provider contract for rt-consents-service version 64d9021bfcc4df13014b52384290c270da92b089 already exists with different content and may not be modified. You will need to delete this resource and re-publish it. You can delete the resource by opening <https://adidascdc.pactflow.io/hal-browser/browser.html#https://adidascdc.pactflow.io/contracts/provider/rt-consents-service/version/64d9021bfcc4df13014b52384290c270da92b089> in your browser, clicking on the `NON-GET` button for the `self` relation, and sending a `DELETE` request to it.","status":409,"instance":"/","errors":[{"type":"<https://adidascdc.pactflow.io/problems/invalid-body-property-value>","title":"Invalid body parameter","detail":"conflicts with existing value","pointer":"/contract/content"}]}
Can't pactflow take the filename also into consideration? You check the content of the OAS file, but not the filename. 😞 How ist this supposed to work?
y
You would need to merge them into a single document, PactFlow doesn’t currently support multiple documents (as you only upload one, so references aren’t involved) In your instance, its trying to overwrite the contents of the file, which it’s saying is dangerous (quite rightly) as that contract content, against that version would be non deterministic. Also on can-i-deploy, using just the version, is essentially checking against the latest published contracts for related parties, which is really underministic too. Without envs/releases, I would use can I deploy to the main branch.
You would need to merge them into a single document
Not sure if this would actually be possible, based on your content but just spit balling
t
You would need to merge them into a single document
Oh, boy. Didn't know that only one file is supported. I was aware, that it should not include references etc, but I thought we can upload multiple files.
Will merge the files.