Commit 7b425259 authored by inphi's avatar inphi

add missing wait timeout check

parent 26d2ba05
...@@ -49,16 +49,8 @@ func TestHints(t *testing.T) { ...@@ -49,16 +49,8 @@ func TestHints(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
} }
}() }()
if waitTimeout(&wg) {
done := make(chan struct{}) t.Error("hint read/write stuck")
go func() {
wg.Wait()
close(done)
}()
select {
case <-time.After(time.Second * 30):
t.Error("reader/writer stuck")
case <-done:
} }
require.Equal(t, len(hints), len(got), "got all hints") require.Equal(t, len(hints), len(got), "got all hints")
...@@ -121,6 +113,23 @@ func TestHints(t *testing.T) { ...@@ -121,6 +113,23 @@ func TestHints(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, readHint, "two") require.Equal(t, readHint, "two")
}() }()
wg.Wait() if waitTimeout(&wg) {
t.Error("read/write hint stuck")
}
}) })
} }
// waitTimeout returns true iff wg.Wait timed out
func waitTimeout(wg *sync.WaitGroup) bool {
done := make(chan struct{})
go func() {
wg.Wait()
close(done)
}()
select {
case <-time.After(time.Second * 30):
return true
case <-done:
return false
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment