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

@@ -36,7 +36,8 @@ func TestRouteCreate(t *testing.T) {
// success
{&datastore.Mock{}, "/v1/apps/a/routes", `{ "route": { "image": "iron/hello", "path": "/myroute" } }`, http.StatusCreated, nil},
} {
router := testRouter(test.mock, &mqs.Mock{}, testRunner(t), tasks)
rnr, cancel := testRunner(t)
router := testRouter(test.mock, &mqs.Mock{}, rnr, tasks)
body := bytes.NewBuffer([]byte(test.body))
_, rec := routerRequest(t, router, "POST", test.path, body)
@@ -56,6 +57,7 @@ func TestRouteCreate(t *testing.T) {
i, test.expectedError.Error(), resp.Error.Message)
}
}
cancel()
}
}
@@ -79,7 +81,8 @@ func TestRouteDelete(t *testing.T) {
},
}, "/v1/apps/a/routes/myroute", "", http.StatusOK, nil},
} {
router := testRouter(test.ds, &mqs.Mock{}, testRunner(t), tasks)
rnr, cancel := testRunner(t)
router := testRouter(test.ds, &mqs.Mock{}, rnr, tasks)
_, rec := routerRequest(t, router, "DELETE", test.path, nil)
if rec.Code != test.expectedCode {
@@ -97,6 +100,7 @@ func TestRouteDelete(t *testing.T) {
i, test.expectedError.Error())
}
}
cancel()
}
}
@@ -105,7 +109,9 @@ func TestRouteList(t *testing.T) {
tasks := mockTasksConduit()
defer close(tasks)
router := testRouter(&datastore.Mock{}, &mqs.Mock{}, testRunner(t), tasks)
rnr, cancel := testRunner(t)
defer cancel()
router := testRouter(&datastore.Mock{}, &mqs.Mock{}, rnr, tasks)
for i, test := range []struct {
path string
@@ -140,7 +146,10 @@ func TestRouteGet(t *testing.T) {
tasks := mockTasksConduit()
defer close(tasks)
router := testRouter(&datastore.Mock{}, &mqs.Mock{}, testRunner(t), tasks)
rnr, cancel := testRunner(t)
defer cancel()
router := testRouter(&datastore.Mock{}, &mqs.Mock{}, rnr, tasks)
for i, test := range []struct {
path string
@@ -196,7 +205,8 @@ func TestRouteUpdate(t *testing.T) {
},
}, "/v1/apps/a/routes/myroute/do", `{ "route": { "image": "iron/hello", "path": "/myroute" } }`, http.StatusOK, nil},
} {
router := testRouter(test.ds, &mqs.Mock{}, testRunner(t), tasks)
rnr, cancel := testRunner(t)
router := testRouter(test.ds, &mqs.Mock{}, rnr, tasks)
body := bytes.NewBuffer([]byte(test.body))
@@ -217,5 +227,6 @@ func TestRouteUpdate(t *testing.T) {
i, test.expectedError.Error())
}
}
cancel()
}
}