Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
822f03193a | ||
|
|
d5052495c7 | ||
|
|
6572b3fe08 |
@@ -49,39 +49,38 @@ func TestServerBusyAnswers503(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestProcessingTimedOutAnswers503 checks that respondImageError and
|
// TestProcessingTimedOutAnswers503 checks that both image routes answer 503
|
||||||
// handleImageError, which answer the errors of the two image routes, answer
|
// with the server busy error when the image service reports that processing
|
||||||
// 503 with the server busy error when the image service reports that
|
// stopped at the deadline of the request doing it, wrapped as the service
|
||||||
// processing stopped at the deadline of the request doing it, wrapped as the
|
// wraps it. A request that waited for that processing gets this error while
|
||||||
// service wraps it. A request that waited for that processing gets this error
|
// its own deadline may have time left.
|
||||||
// while its own deadline may have time left. The request's source only goes
|
|
||||||
// into a log line, so it is left empty.
|
|
||||||
func TestProcessingTimedOutAnswers503(t *testing.T) {
|
func TestProcessingTimedOutAnswers503(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
h := &Handlers{log: slog.New(slog.DiscardHandler)}
|
h := &Handlers{log: slog.New(slog.DiscardHandler)}
|
||||||
|
req := &imgcache.ImageRequest{SourceHost: "img.example.com", SourcePath: "/a.jpg"}
|
||||||
err := fmt.Errorf("%w: failed to encode: %w",
|
err := fmt.Errorf("%w: failed to encode: %w",
|
||||||
imgcache.ErrProcessingTimedOut, context.DeadlineExceeded)
|
imgcache.ErrProcessingTimedOut, context.DeadlineExceeded)
|
||||||
|
|
||||||
plain := httptest.NewRecorder()
|
plain := httptest.NewRecorder()
|
||||||
h.respondImageError(plain, &imgcache.ImageRequest{}, err)
|
h.respondImageError(plain, req, err)
|
||||||
|
|
||||||
encrypted := httptest.NewRecorder()
|
encrypted := httptest.NewRecorder()
|
||||||
h.handleImageError(encrypted, err)
|
h.handleImageError(encrypted, err)
|
||||||
|
|
||||||
for name, rec := range map[string]*httptest.ResponseRecorder{
|
for route, rec := range map[string]*httptest.ResponseRecorder{
|
||||||
"respondImageError": plain, "handleImageError": encrypted,
|
"/v1/image/": plain, "/v1/e/": encrypted,
|
||||||
} {
|
} {
|
||||||
t.Logf("%s: status = %d, body = %q", name, rec.Code, rec.Body.String())
|
t.Logf("%s: status = %d, body = %q", route, rec.Code, rec.Body.String())
|
||||||
|
|
||||||
if rec.Code != http.StatusServiceUnavailable {
|
if rec.Code != http.StatusServiceUnavailable {
|
||||||
t.Errorf("%s: status = %d, want %d",
|
t.Errorf("%s: status = %d, want %d",
|
||||||
name, rec.Code, http.StatusServiceUnavailable)
|
route, rec.Code, http.StatusServiceUnavailable)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !strings.Contains(rec.Body.String(), "server busy, try again later") {
|
if !strings.Contains(rec.Body.String(), "server busy, try again later") {
|
||||||
t.Errorf("%s: body = %q, want the server busy error",
|
t.Errorf("%s: body = %q, want the server busy error",
|
||||||
name, rec.Body.String())
|
route, rec.Body.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user