https://pact.io logo
Title
d

David Hvilava

05/25/2023, 4:31 PM
Hi guys. I'm exploring v4.5.0 PactNet version that introduces Provider state teardown. Can someone explain what is a use case of the feature? Description says teardown is supposed to be executed after each interaction. I have interactions that have different provider states. So in this case the same teardown will be applied for different provider states. Also I tried it and noticed that the delegate code is executed only once. Although test log shows several "Running teardown provider state change handler..." message equal to amount of interactions. Here is how I called it:
.WithProviderStateUrl(
	providerStateUrl, 
	(e) => {
		e.WithTeardown();
		Console.WriteLine("Provider state teardown executed.");                        
	});
m

Matt (pactflow.io / pact-js / pact-go)

05/25/2023, 10:12 PM
My understanding is that the teardown hook should be per state. The main idea is to reset the particular state that was setup, as there may be multiple
d

David Hvilava

05/26/2023, 8:15 AM
Right, this is what I would expect from that feature
m

Matt (pactflow.io / pact-js / pact-go)

05/26/2023, 9:29 AM
Sounds like a big somewhere
Mind raising an issue please?
d

David Hvilava

05/26/2023, 9:31 AM
Yes, I will
@Adam Rodger (pact-net), can you please shed light on the intention of Provider states teardown feature implemented in v4.5.0
Managed to figure it out :bananadance_smile: In order to have it work as we expect - teardown for each provider state after each interaction, we need to perform these steps: 1. Turn on teardown feature
.WithProviderStateUrl(
	providerStateUrl, 
	(e) => { e.WithTeardown(); });
It will send an extra request to "provider-states" middleware with new property "action":"teardown". 2. In a test you can define Setup and Teardown delegates for each provider state. 3. In "provider-states" middleware call corresponding delegate depending on received "action" property value (for setup use "action":"setup").
Maybe it will help others how got confused by that feature 🙂