fn: container init timeout should be a 504 (#1329)

Too-Busy 503 is a retriable error, this error
should be 504 instead.
This commit is contained in:
Tolga Ceylan
2018-11-28 14:39:37 -08:00
committed by GitHub
parent 59a1d910a0
commit 1d34cc11a3
2 changed files with 50 additions and 1 deletions

View File

@@ -41,7 +41,7 @@ var (
error: errors.New("Docker pull timed out"),
}
ErrContainerInitTimeout = err{
code: http.StatusServiceUnavailable,
code: http.StatusGatewayTimeout,
error: errors.New("Container initialization timed out, please ensure you are using the latest fdk / format and check the logs"),
}
ErrUnsupportedMediaType = err{

View File

@@ -15,6 +15,55 @@ import (
"github.com/fnproject/fn/api/models"
)
func TestInitTimeoutContainer(t *testing.T) {
buf := setLogBuffer()
defer func() {
if t.Failed() {
t.Log(buf.String())
}
}()
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
defer cancel()
app := &models.App{Name: id.New().String()}
app = ensureApp(t, app)
fn := &models.Fn{
AppID: app.ID,
Name: id.New().String(),
Image: image,
ResourceConfig: models.ResourceConfig{
Memory: memory,
},
}
fn.Config = models.Config{"ENABLE_INIT_DELAY_MSEC": "10000"}
fn = ensureFn(t, fn)
lb, err := LB()
if err != nil {
t.Fatalf("Got unexpected error: %v", err)
}
u := url.URL{
Scheme: "http",
Host: lb,
}
u.Path = path.Join(u.Path, "invoke", fn.ID)
body := `{"echoContent": "HelloWorld", "sleepTime": 0, "isDebug": true}`
content := bytes.NewBuffer([]byte(body))
output := &bytes.Buffer{}
resp, err := callFN(ctx, u.String(), content, output, models.TypeSync)
if err != nil {
t.Fatalf("Got unexpected error: %v", err)
}
if resp.StatusCode != http.StatusGatewayTimeout {
t.Fatalf("StatusCode check failed on %v", resp.StatusCode)
}
}
func TestCanExecuteFunction(t *testing.T) {
buf := setLogBuffer()
defer func() {