mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 21:10:32 +01:00
Why does Dispose not wait for HttpServer to actually stop? #439
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @emilpeder on GitHub (Aug 17, 2022).
Originally assigned to: @StefH on GitHub.
In the WireMockServer class:
https://github.com/WireMock-Net/WireMock.Net/blob/master/src/WireMock.Net/Server/WireMockServer.cs
The Dispose method calls
_httpServer?.StopAsync();must does not wait for this operation to complete. Is there any reason for that?On the contrary, the Stop method does wait.
If we want to make sure the WireMockServer is fully stopped and disposed we therefore need to call both Stop and then Dispose, is that correct?
@StefH commented on GitHub (Aug 17, 2022):
@emilpeder
There's no specific reason for that, other that dispose normally only cleans the resources.
But I could call Stop first.
For now you indeed need to call Stop and then Dispose it.
@emilpeder commented on GitHub (Aug 17, 2022):
All right. For us this was a source of confusion, since we ended up with race conditions where sometimes tests failed because the HttpServer inside WireMock was still serving requests although we had disposed the WireMockServer instance.
Thanks for the clarification.