Created
July 26, 2019 07:21
-
-
Save steevehook/92f03ca433e4424624c2ed2318023a5a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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