Hi <@U9UUY3CU9> <@UELMFD9PG> I have a scenario whe...
# libpact_ffi-users
p
Hi @Matt (pactflow.io / pact-js / pact-go) @Yousaf Nabi (pactflow.io) I have a scenario where i created a new pact using a Consumer and a provider, created an interaction and then started the mock server for it. When we cleanup a pact mock server, and again start the pact mock server using https://docs.rs/pact_ffi/latest/pact_ffi/mock_server/fn.pactffi_cleanup_mock_server.html and https://docs.rs/pact_ffi/latest/pact_ffi/mock_server/fn.pactffi_create_mock_server_for_transport.html respectively, does that account for the last interaction that i added ?
y
are you asking if the interaction added before starting the mock server, persists after calling pact_cleanup_mock_servers?
p
yes
y
Having a quick look at the rust code, I don’t think the interactionHandle or PactHandle is cleared, I would need to test, by shutting down a mock server and then starting it against by passing it the same PactHandle
p
I did this: 1. created new pact -> generated a new pact handle 2. created new interaction -> generated a new interaction handle 3. Added request and response with this interaction handle 4. started the mock server for this pact handle 5. successfully executed the api and verified it and also called the mock server cleanup function (https://docs.rs/pact_ffi/latest/pact_ffi/mock_server/fn.pactffi_cleanup_mock_server.html) 6. Repeated steps 2,3,4. In step 5, execution of api is successful, but verification fails because it also expects me to execute the previous interaction. For verification i have used this - https://docs.rs/pact_ffi/latest/pact_ffi/mock_server/fn.pactffi_mock_server_matched.html
y
the PactHandle and InteractionHandle’s are opaque pointers, so numbers 1,2,3 etc. You may need to generate a new PactHandle and then InteractionHandle, or clear the setup Interaction with
pactffi_pact_interaction_delete
for your existing
PactHandle
post calling
pactffi_mock_server_matched
(and processing any mismatches) I’d need to check some other impls and see what they do
looks like there is
pactffi_pact_model_delete
for deleting the PactHandle I believe
m
OK, looking at the code in JS, we actually recreate the
Pact
handle for each individual interaction, using the
pactffi_new_pact
method. @uglyog is this the intended behaviour?
u
PactHandle was not designed to be reused
👍 2
m
Thanks. This will be useful to add to the developer docs. I reckon a mermaid diagram with a state chart would be super nice here!
plus1 1
p
@Matt (pactflow.io / pact-js / pact-go) yes, will be very helpful for someone who is developing pact client for other languages
👍 1
thanks a lot everyone for the help though !!
m
no worries
also thanks for raising, I just realised that the V4 interface in Pact JS doesn’t do what I said the V3 interface does (and have just fixed it).