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:
Alex Sergeyev 2014-08-29 14:10:05 -04:00
parent ef07b9a69a
commit c618657d9b
2 changed files with 10 additions and 4 deletions

View File

@ -333,7 +333,7 @@ func (srv *Server) Shutdown() error {
select { select {
case <-time.After(srv.getReadTimeout()): case <-time.After(srv.getReadTimeout()):
return &Error{err: "shutdown is pending"} return &Error{err: "server shutdown is pending"}
case <-fin: case <-fin:
return nil return nil
} }

View File

@ -40,6 +40,10 @@ func RunLocalUDPServer(laddr string) (*Server, string, error) {
server.ActivateAndServe() server.ActivateAndServe()
pc.Close() 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 return server, pc.LocalAddr().String(), nil
} }
@ -53,6 +57,10 @@ func RunLocalTCPServer(laddr string) (*Server, string, error) {
server.ActivateAndServe() server.ActivateAndServe()
l.Close() 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 return server, l.Addr().String(), nil
} }
@ -260,15 +268,13 @@ func HelloServerLargeResponse(resp ResponseWriter, req *Msg) {
} }
func TestServingLargeResponses(t *testing.T) { func TestServingLargeResponses(t *testing.T) {
mux := NewServeMux() HandleFunc("example.", HelloServerLargeResponse)
mux.HandleFunc("example.", HelloServerLargeResponse)
s, addrstr, err := RunLocalUDPServer("127.0.0.1:0") s, addrstr, err := RunLocalUDPServer("127.0.0.1:0")
if err != nil { if err != nil {
t.Fatalf("Unable to run test server: %s", err) t.Fatalf("Unable to run test server: %s", err)
} }
defer s.Shutdown() defer s.Shutdown()
s.Handler = mux
// Create request // Create request
m := new(Msg) m := new(Msg)