From 828fa5f88c83961d8364d2f3fefed080077ab491 Mon Sep 17 00:00:00 2001 From: Soam Vasani Date: Mon, 29 Aug 2016 15:30:04 -0700 Subject: [PATCH] Fix test shutdown Mutable mux test occasionally panics because the server is shut down before the client goroutine. Fix this by shutting down the client goroutines before shutting down the server. --- src/router/mutablemux_test.go | 36 ++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/src/router/mutablemux_test.go b/src/router/mutablemux_test.go index de8d3820..1b1417ba 100644 --- a/src/router/mutablemux_test.go +++ b/src/router/mutablemux_test.go @@ -55,16 +55,21 @@ func startServer(mr *mutableRouter) { http.ListenAndServe(":3333", mr) } -func spamServer() { + +func spamServer(quit chan bool) { i := 0 for { - i = i + 1 - resp, err := http.Get("http://localhost:3333") - if (err != nil) { - log.Panicf("failed make get request %v", i) + select { + case <- quit: + break + default: + i = i + 1 + resp, err := http.Get("http://localhost:3333") + if (err != nil) { + log.Panicf("failed make get request %v: %v", i, err) + } + resp.Body.Close() } - resp.Body.Close() - log.Printf("request count = %v", i) } } @@ -80,9 +85,13 @@ func TestMutableMux(t *testing.T) { go startServer(mr) // continuously make requests, panic if any fails - go spamServer() - go spamServer() - go spamServer() + time.Sleep(100 * time.Millisecond) + q1 := make(chan bool) + go spamServer(q1) + q2 := make(chan bool) + go spamServer(q2) + q3 := make(chan bool) + go spamServer(q3) time.Sleep(5 * time.Millisecond) @@ -101,7 +110,8 @@ func TestMutableMux(t *testing.T) { verifyRequest("new handler") time.Sleep(5 * time.Millisecond) - - // all done - log.Print("ok") + q1 <- true + q2 <- true + q3 <- true + time.Sleep(100 * time.Millisecond) }