mirror of
https://github.com/minio/minio.git
synced 2025-03-31 17:53:43 -04:00
Fix rare 'go test -race' failure in ListenServe{Plain,TLS} (#2588)
This commit is contained in:
parent
a3b4199e9b
commit
e79d2381fc
@ -153,7 +153,7 @@ func TestServerCloseBlocking(t *testing.T) {
|
|||||||
m.mu.Unlock()
|
m.mu.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestListenAndServe(t *testing.T) {
|
func TestListenAndServePlain(t *testing.T) {
|
||||||
wait := make(chan struct{})
|
wait := make(chan struct{})
|
||||||
addr := "127.0.0.1:" + strconv.Itoa(getFreePort())
|
addr := "127.0.0.1:" + strconv.Itoa(getFreePort())
|
||||||
errc := make(chan error)
|
errc := make(chan error)
|
||||||
@ -171,6 +171,8 @@ func TestListenAndServe(t *testing.T) {
|
|||||||
// Make sure we don't block by closing wait after a timeout
|
// Make sure we don't block by closing wait after a timeout
|
||||||
tf := time.AfterFunc(time.Millisecond*500, func() { errc <- errors.New("Unable to connect to server") })
|
tf := time.AfterFunc(time.Millisecond*500, func() { errc <- errors.New("Unable to connect to server") })
|
||||||
|
|
||||||
|
wg := &sync.WaitGroup{}
|
||||||
|
wg.Add(1)
|
||||||
// Keep trying the server until it's accepting connections
|
// Keep trying the server until it's accepting connections
|
||||||
go func() {
|
go func() {
|
||||||
client := http.Client{Timeout: time.Millisecond * 10}
|
client := http.Client{Timeout: time.Millisecond * 10}
|
||||||
@ -182,9 +184,12 @@ func TestListenAndServe(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wg.Done()
|
||||||
tf.Stop() // Cancel the timeout since we made a successful request
|
tf.Stop() // Cancel the timeout since we made a successful request
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
wg.Wait()
|
||||||
|
|
||||||
// Block until we get an error or wait closed
|
// Block until we get an error or wait closed
|
||||||
select {
|
select {
|
||||||
case err := <-errc:
|
case err := <-errc:
|
||||||
@ -230,6 +235,8 @@ func TestListenAndServeTLS(t *testing.T) {
|
|||||||
|
|
||||||
// Make sure we don't block by closing wait after a timeout
|
// Make sure we don't block by closing wait after a timeout
|
||||||
tf := time.AfterFunc(time.Millisecond*500, func() { errc <- errors.New("Unable to connect to server") })
|
tf := time.AfterFunc(time.Millisecond*500, func() { errc <- errors.New("Unable to connect to server") })
|
||||||
|
wg := &sync.WaitGroup{}
|
||||||
|
wg.Add(1)
|
||||||
|
|
||||||
// Keep trying the server until it's accepting connections
|
// Keep trying the server until it's accepting connections
|
||||||
go func() {
|
go func() {
|
||||||
@ -248,9 +255,12 @@ func TestListenAndServeTLS(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wg.Done()
|
||||||
tf.Stop() // Cancel the timeout since we made a successful request
|
tf.Stop() // Cancel the timeout since we made a successful request
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
wg.Wait()
|
||||||
|
|
||||||
// Block until we get an error or wait closed
|
// Block until we get an error or wait closed
|
||||||
select {
|
select {
|
||||||
case err := <-errc:
|
case err := <-errc:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user