functions: fix goroutine leak in runner (#394)

* functions: fix goroutine leak in runner

* functions: ensure taskQueue is consumed after context cancellation
This commit is contained in:
C Cirello
2016-12-06 16:11:06 +01:00
committed by GitHub
parent f0fc85b85a
commit 0cdd1db3e1
9 changed files with 122 additions and 67 deletions

View File

@@ -189,12 +189,13 @@ func TestTasksrvURL(t *testing.T) {
}
}
func testRunner(t *testing.T) *Runner {
r, err := New(NewFuncLogger(), NewMetricLogger())
func testRunner(t *testing.T) (*Runner, context.CancelFunc) {
ctx, cancel := context.WithCancel(context.Background())
r, err := New(ctx, NewFuncLogger(), NewMetricLogger())
if err != nil {
t.Fatal("Test: failed to create new runner")
}
return r
return r, cancel
}
func TestAsyncRunnersGracefulShutdown(t *testing.T) {
@@ -217,7 +218,9 @@ func TestAsyncRunnersGracefulShutdown(t *testing.T) {
}
}()
startAsyncRunners(ctx, ts.URL+"/tasks", tasks, testRunner(t))
rnr, cancel := testRunner(t)
defer cancel()
startAsyncRunners(ctx, ts.URL+"/tasks", tasks, rnr)
if err := ctx.Err(); err != context.DeadlineExceeded {
t.Log(buf.String())