siddharth shetty
05/12/2023, 10:17 AMauto syncInteraction1 = pactffi_new_sync_message_interaction( pact, "Interaction");
pactffi_given( syncInteraction1, "Given" );
pactffi_upon_receiving( syncInteraction1, "Upon receiving" );
pactffi_with_body( syncInteraction1, InteractionPart::InteractionPart_Request, "application/json", R"({"jsonrpc":"2.0","id":{"value":3,"pact:matcher:type":"type"}});
pactffi_with_body( syncInteraction3, InteractionPart::InteractionPart_Response, "application/json", R"#({"jsonrpc":"2.0","id":{"value":3,"pact:matcher:type":"type"}})#");
auto syncInteraction2 = pactffi_new_sync_message_interaction( pact, "Interaction");
pactffi_given( syncInteraction2, "Given" );
pactffi_upon_receiving( syncInteraction2, "Upon receiving" );
pactffi_with_body( syncInteraction2, InteractionPart::InteractionPart_Request, "application/json", R"({"jsonrpc":"2.0","id":{"value":4,"pact:matcher:type":"type"}});
pactffi_with_body( syncInteraction2, InteractionPart::InteractionPart_Response, "application/json", R"#({"jsonrpc":"2.0","id":{"value":4,"pact:matcher:type":"type"}})#");
The above 2 interactions are the same except that the id field(in the request/response) has different values but is matched by type. So, I was expecting this to generate only 1 entry in the contract for both interactions which the provider can verify. But in the contract, there are 2 entries. I suppose this is because there are 2 unique keys generated for each of the 2 interactions? Any ideas how we can get around this so we can have only 1 entry in the contract for such duplicated interactions when using the C++ FFI to write PACT consumer tests would be much appreciated.Yousaf Nabi (pactflow.io)
Yousaf Nabi (pactflow.io)
Yousaf Nabi (pactflow.io)
siddharth shetty
05/12/2023, 10:43 AMYousaf Nabi (pactflow.io)
We were hoping the provider would not be replayed the same request multiple times with different ID`s.I don't understand why you have two tests, that cover the same scenario, with the same description and state. these tests don't seem different, if they are different, they should be named as such. It might be scope creep into functional testing, it just seems an odd case. Anyway that aside, maybe it should dedupe in this instance, but the interaction key that the pact core adds, might be stopping that. I would raise this in the pact-reference repo I think as a question. Ahhh SkyComcast and the WS Plugin I presume? @Adam Cox mentioned engineers were using the FFI directly
Yousaf Nabi (pactflow.io)
pactffi_given_with_param
for using a given state, with parameters
/**
* Adds a provider state to the Interaction with a parameter key and value. Returns false if the interaction or Pact can't be
* modified (i.e. the mock server for it has already started)
*
* * `description` - The provider state description. It needs to be unique.
* * `name` - Parameter name.
* * `value` - Parameter value.
*/
bool pactffi_given_with_param(InteractionHandle interaction,
const char *description,
const char *name,
const char *value);
Yousaf Nabi (pactflow.io)
pactffi_given
that the description
must be unique
/**
* Adds a provider state to the Interaction. Returns false if the interaction or Pact can't be
* modified (i.e. the mock server for it has already started)
*
* * `description` - The provider state description. It needs to be unique.
*/
bool pactffi_given(InteractionHandle interaction, const char *description);
Yousaf Nabi (pactflow.io)
Yousaf Nabi (pactflow.io)
siddharth shetty
05/12/2023, 10:57 AMI don't understand why you have two tests, that cover the same scenario, with the same description and state.So we have multiple unit tests for testing a single API/Method for ensuring code coverage for every statement/condition in the method. Which means the websocket request would be called multiple times with different ID`s depending on the state of the object under test.
siddharth shetty
05/12/2023, 10:58 AMAhhh SkyComcast and the WS Plugin I presume? @Adam Cox mentioned engineers were using the FFI directlyYes thats right π
Yousaf Nabi (pactflow.io)
siddharth shetty
05/12/2023, 11:01 AMThe notes state for pactffi_given
that the description must be unique
I tried this as well, but dont think it matters in what we are trying to acheive here. I mean having a unique description for each interaction will not create the 1 entry in the contract right?Yousaf Nabi (pactflow.io)
Yousaf Nabi (pactflow.io)
siddharth shetty
05/12/2023, 11:04 AMok so you want the full coverage on the consumer side, using the pact ffi to facilitate the unit testing, but only want to selectively verify some of them in the provider, as otherwise there is duplicationYes we are writing unit tests which use the pact framework to standup a mock websocket server and respond to requests as the tests progress. Which is why there might be multiple requests which are similar except they differ in ID value`s. So the provider does not have to verify redundant requests which differ only in ID`s.
Adam Cox
05/12/2023, 11:28 AMYousaf Nabi (pactflow.io)
Yousaf Nabi (pactflow.io)
Yousaf Nabi (pactflow.io)
Adam Cox
05/12/2023, 11:31 AMYousaf Nabi (pactflow.io)
Adam Cox
05/12/2023, 11:34 AMIf they should be unique, I wonder if Pact should clobber one of them and warn the userThis would solve our current use case I think. Might cause issues for other people elsewhere but if it should be unique then there should be only one
Yousaf Nabi (pactflow.io)
void pactffi_verifier_set_filter_info(VerifierHandle *handle,
const char *filter_description,
const char *filter_state,
unsigned char filter_no_state);
It would probably be easy to add an exclude filter method into the codebase, which would allow your verification runs just to exclude certain states or descriptions (unit test / xyz)Adam Cox
05/12/2023, 11:51 AMTimothy Jones
05/13/2023, 12:32 AM