Skip to content
Snippets Groups Projects
Commit f4092726 authored by Sybren A. Stüvel's avatar Sybren A. Stüvel
Browse files

Manager: fixed panic in TimeoutAfter func when timeout channel was closed

parent 10d8eb0c
Branches
Tags
No related merge requests found
......@@ -156,6 +156,7 @@ func (s *SchedulerTestSuite) TestSchedulerVerifyUpstreamCanceled(t *check.C) {
}
timeout := TimeoutAfter(1 * time.Second)
defer close(timeout)
// Mock that the task with highest priority was actually canceled on the Server.
httpmock.RegisterResponder(
......@@ -207,6 +208,7 @@ func (s *SchedulerTestSuite) TestSchedulerVerifyUpstreamPrioChange(t *check.C) {
}
timeout := TimeoutAfter(1 * time.Second)
defer close(timeout)
// Mock that the task with highest priority was actually canceled on the Server.
httpmock.RegisterResponder(
......@@ -264,6 +266,7 @@ func (s *SchedulerTestSuite) TestSchedulerVerifyUpstreamDeleted(t *check.C) {
}
timeout := TimeoutAfter(1 * time.Second)
defer close(timeout)
// Mock that the task with highest priority was actually canceled on the Server.
httpmock.RegisterResponder(
......
......@@ -53,6 +53,7 @@ func (s *TaskUpdatesTestSuite) TestCancelRunningTasks(t *check.C) {
}
timeout := TimeoutAfter(1 * time.Second)
defer close(timeout)
// Mock that the task with highest priority was actually canceled on the Server.
httpmock.RegisterResponder(
......@@ -81,7 +82,6 @@ func (s *TaskUpdatesTestSuite) TestCancelRunningTasks(t *check.C) {
timedout := <-timeout
assert.False(t, timedout, "HTTP POST to Flamenco Server not performed")
close(timeout)
// Give the tup.Go() coroutine (and subsequent calls) time to run.
// the "timeout <- false" call in the responder is triggered before
......
......@@ -88,11 +88,23 @@ func UtcNow() *time.Time {
return &now
}
/* Sends a 'true' to the channel after the given timeout.
* Send a 'false' to the channel yourself if you want to notify the receiver that
* a timeout didn't happen.
*
* The channel is buffered with size 2, so both your 'false' and this routine's 'true'
* write won't block.
*/
func TimeoutAfter(duration time.Duration) chan bool {
timeout := make(chan bool, 1)
timeout := make(chan bool, 2)
go func() {
time.Sleep(duration)
defer func() {
// Recover from a panic. This panic can happen when the caller closed the
// channel while we were sleeping.
recover()
}()
timeout <- true
}()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment