Dealt with race condition detector warnings:
* stopped obvious race condition with replacing handler in ServingLargeResponses test * lowered probability of other race conditions with test code while test server is yet activating * fixed errmessage in Shutdown
This commit is contained in:
parent
ef07b9a69a
commit
c618657d9b
|
@ -333,7 +333,7 @@ func (srv *Server) Shutdown() error {
|
|||
|
||||
select {
|
||||
case <-time.After(srv.getReadTimeout()):
|
||||
return &Error{err: "shutdown is pending"}
|
||||
return &Error{err: "server shutdown is pending"}
|
||||
case <-fin:
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -40,6 +40,10 @@ func RunLocalUDPServer(laddr string) (*Server, string, error) {
|
|||
server.ActivateAndServe()
|
||||
pc.Close()
|
||||
}()
|
||||
// in order to let all Server internals to finish before test will touch
|
||||
// server's internal fields, we need to cycle thru other goroutinges for
|
||||
// one more time
|
||||
runtime.Gosched()
|
||||
return server, pc.LocalAddr().String(), nil
|
||||
}
|
||||
|
||||
|
@ -53,6 +57,10 @@ func RunLocalTCPServer(laddr string) (*Server, string, error) {
|
|||
server.ActivateAndServe()
|
||||
l.Close()
|
||||
}()
|
||||
// in order to let all Server internals to finish before test will touch
|
||||
// server's internal fields, we need to cycle thru other goroutinges for
|
||||
// one more time
|
||||
runtime.Gosched()
|
||||
return server, l.Addr().String(), nil
|
||||
}
|
||||
|
||||
|
@ -260,15 +268,13 @@ func HelloServerLargeResponse(resp ResponseWriter, req *Msg) {
|
|||
}
|
||||
|
||||
func TestServingLargeResponses(t *testing.T) {
|
||||
mux := NewServeMux()
|
||||
mux.HandleFunc("example.", HelloServerLargeResponse)
|
||||
HandleFunc("example.", HelloServerLargeResponse)
|
||||
|
||||
s, addrstr, err := RunLocalUDPServer("127.0.0.1:0")
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to run test server: %s", err)
|
||||
}
|
||||
defer s.Shutdown()
|
||||
s.Handler = mux
|
||||
|
||||
// Create request
|
||||
m := new(Msg)
|
||||
|
|
Loading…
Reference in New Issue