-
-
Notifications
You must be signed in to change notification settings - Fork 348
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
Multiple interactions per test case are no longer supported #1078
Comments
For others coming to this issue, The error message is:
Can you try using the newer DSL instead of the 9.x one? Generally you shouldn't need more than one request per interaction, so there was probably an accidental assumption made that there would only be one when adding the compatibility layer for the older DSL. The new DSL has less boilerplate - you don't have to call the lifecycle functions. What are you doing that needs two requests in one interaction? |
Thanks for digging Tim and the helpful repro @martinslota. I agree using the latter interface is recommended, however the idea was to support migrating from 9.x.x so it would be ideal to support it if we can. |
I switched to the newer DSL after I hit this problem, though that has then led to other difficulties, especially pact-foundation/pact_broker-client#131 and then some others which might be more on our side (I'm nowhere near done yet, so it's hard to tell). The impression I got from the documentation was that the compatibility layer in version 10 (and 11, I suppose) would be almost fully backwards compatible with version 9. Not supporting multiple interactions is a deal breaker for the suite I'm migrating. I think that would be worth either fixing or clearly pointing out in the migration instructions. |
Yes, I think it's a bug. |
Hey @TimothyJones, I have a similar use-case some of our code will retry the same request depending on the status that is returned (like a if we only return the failing response in a test then an exception is thrown after a number of attempts which doesn't really test the relationship between the two requests (which I would argue is part of the contract that is imposed on the provider in this case) I could also see this being useful for testing a function that polls for a status. maybe it starts and then waits for an external job to complete and the job can go through multiple stages before completing |
If this is in fact necessary to test, I would suggest these are tested as two separate scenarios differentiated by provider states (one for when the service is available and one for when it isn't). The behaviour you want to test (retry mechanism) is actually the client's behaviour, and not the provider's, so I would further argue this isn't appropriate for a Pact test. The provider should not know how often a client attempts to retry a call. |
I agree with Matt. Making some assumptions about your implementation - the retry call wouldn't be visible to the business layer, so this test would take place in a lower level than the rest of the pact tests. If that's the case, I can see why it might feel appropriate to put it all in one interaction - so that the test boundary doesn't move. However, there's some parts of the behaviour that would be more appropriate for individual tests. For example, the contract test won't include "does the client respect It feels analogous to creating a resource that is immediately modified - where create and modify are separate interactions. Here, being told to retry later and actually retrying later are probably better off as separate interactions. |
We also have a use-case where we need to add multiple interactions for one test. We are using "pact tests" ( |
I think the general advice is the same here - i.e. stub the additional resolver calls. |
OK so I thought this was suspicious - you can definitely test multiple interactions (I added it to the Here is a change to an example project that shows it working: https://github.com/pactflow/example-consumer/compare/feat/repro-pact-js-1078?expand=1
The test also fails if one of the calls wasn't made:
|
I believe that the original problem still stands with the original (not |
Ah! You're right, my apologies. I'll re-open |
Any update on this ? |
If there was an update, it would appear here ;) This interface is quite old, so it's not a priority to go back and add this right now. If you are open to submitting a PR to address it, I could give you some pointers. |
Software versions
Issue Checklist
Please confirm the following:
Expected behaviour
Multiple interactions can be added for a single test case.
Actual behaviour
The pact server crashes when adding the second interaction.
Steps to reproduce
Run
npm ci && npm test
in https://github.com/martinslota/pact-js-bug-multiple-interactions.Relevant log files
failure.log
The text was updated successfully, but these errors were encountered: