MCPcopy
hub / github.com/iron-io/functions / TestRouteRunnerTimeout

Function TestRouteRunnerTimeout

api/server/runner_test.go:174–225  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

172}
173
174func TestRouteRunnerTimeout(t *testing.T) {
175 t.Skip("doesn't work on old Ubuntu")
176 buf := setLogBuffer()
177
178 tasks := make(chan task.Request)
179 ctx, cancel := context.WithCancel(context.Background())
180 defer cancel()
181
182 rnr, cancelrnr := testRunner(t)
183 defer cancelrnr()
184 go runner.StartWorkers(ctx, rnr, tasks)
185
186 srv := testServer(datastore.NewMockInit(
187 []*models.App{
188 {Name: "myapp", Config: models.Config{}},
189 },
190 []*models.Route{
191 {Path: "/sleeper", AppName: "myapp", Image: "iron/sleeper", Timeout: 1},
192 },
193 ), &mqs.Mock{}, rnr, tasks)
194
195 for i, test := range []struct {
196 path string
197 body string
198 method string
199 expectedCode int
200 expectedHeaders map[string][]string
201 }{
202 {"/r/myapp/sleeper", `{"sleep": 0}`, "POST", http.StatusOK, nil},
203 {"/r/myapp/sleeper", `{"sleep": 2}`, "POST", http.StatusGatewayTimeout, nil},
204 } {
205 body := strings.NewReader(test.body)
206 _, rec := routerRequest(t, srv.Router, test.method, test.path, body)
207
208 if rec.Code != test.expectedCode {
209 t.Log(buf.String())
210 t.Errorf("Test %d: Expected status code to be %d but was %d",
211 i, test.expectedCode, rec.Code)
212 }
213
214 if test.expectedHeaders == nil {
215 continue
216 }
217 for name, header := range test.expectedHeaders {
218 if header[0] != rec.Header().Get(name) {
219 t.Log(buf.String())
220 t.Errorf("Test %d: Expected header `%s` to be %s but was %s",
221 i, name, header[0], rec.Header().Get(name))
222 }
223 }
224 }
225}
226
227func TestMatchRoute(t *testing.T) {
228 buf := setLogBuffer()

Callers

nothing calls this directly

Calls 6

testServerFunction · 0.85
routerRequestFunction · 0.85
setLogBufferFunction · 0.70
testRunnerFunction · 0.70
LogMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…