Clean shutdown of test apiserver

This commit is contained in:
Wojciech Tyczyński
2022-05-12 12:10:02 +02:00
parent e0dbea2443
commit 6f706775bc
10 changed files with 111 additions and 67 deletions

View File

@@ -70,7 +70,14 @@ func TestGracefulShutdown(t *testing.T) {
resp.Body.Close()
t.Logf("shutting down server")
tearDownOnce.Do(server.TearDownFn)
// We tear it down in the background to ensure that
// pending requests should work fine.
wg := sync.WaitGroup{}
wg.Add(1)
go func() {
defer wg.Done()
tearDownOnce.Do(server.TearDownFn)
}()
t.Logf("server should fail new requests")
if err := wait.Poll(time.Millisecond*100, wait.ForeverTestTimeout, func() (done bool, err error) {
@@ -100,6 +107,8 @@ func TestGracefulShutdown(t *testing.T) {
t.Fatal(err)
}
t.Logf("response: code %d, body: %s", respErr.resp.StatusCode, string(bs))
wg.Wait()
}
type responseErrorPair struct {