Improved speed of the test harness for testing net/http parsing by adding a call to runtime.Gosched() before shutting down the server #63
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #59
Added a call to
runtime.Gosched()
before the call toserver.Shutdown()
.This dramatically improved the time it took to run the tests. It turns out that
server.Shutdown
polls every 0.5 s if all idle connections are closed. When we call server.Shutdown, our connection isn't closed just yet, so therefore we always have to wait 0.5 s for each test. But in reality it takes a lot less time than 0.5 s for the connection to finish closing. So if we just give up execution for a moment before callingserver.Shutdown
then the other goroutines have the time to shut the connection down beforeserver.Shutdown
checks if everything is closed. And then we don't get punished with waiting for 0.5 s every time we try to shut down.With this approach sometimes tests still take 0.5 s to run. This might be because the scheduler continues execution on the same goroutine faster than the time it takes to close the connection. Putting in a
time.Sleep(100 * time.Microsecond)
instead of theruntime.Gosched()
consistently makes the tests run faster, on my machine at least. But that is something I'll leave to be investigated at another time.