Skip to content

Instantly share code, notes, and snippets.

@steevehook
Created July 26, 2019 07:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steevehook/92f03ca433e4424624c2ed2318023a5a to your computer and use it in GitHub Desktop.
Save steevehook/92f03ca433e4424624c2ed2318023a5a to your computer and use it in GitHub Desktop.
// WithTimeout runs a function and fails if it didn't finish within the timeout
func (s *Suite) WithTimeout(timeout time.Duration, fn func()) {
ch := make(chan struct{})
go func() {
fn()
ch <- struct{}{}
}()
select {
case <-time.After(timeout):
s.Fail("The test stuck for more than expected timeout")
case <-ch:
return
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment