Дать подготовке данных в генераторе нагрузки отдельный длинный таймаут: регистрация с Argon2id на реплике с половиной CPU не укладывается в таймаут измерений
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -41,6 +42,10 @@ func TestMain(m *testing.M) {
|
||||
}
|
||||
|
||||
func liveServer(t *testing.T) string {
|
||||
return serve(t, nil)
|
||||
}
|
||||
|
||||
func serve(t *testing.T, wrap func(http.Handler) http.Handler) string {
|
||||
t.Helper()
|
||||
a := app.New(app.Deps{
|
||||
Log: slog.New(slog.NewTextHandler(io.Discard, nil)),
|
||||
@@ -50,11 +55,37 @@ func liveServer(t *testing.T) string {
|
||||
MaxBodyBytes: 64 * 1024,
|
||||
InstanceID: "loadgen-test",
|
||||
})
|
||||
srv := httptest.NewServer(a.Engine)
|
||||
var h http.Handler = a.Engine
|
||||
if wrap != nil {
|
||||
h = wrap(h)
|
||||
}
|
||||
srv := httptest.NewServer(h)
|
||||
t.Cleanup(srv.Close)
|
||||
return srv.URL
|
||||
}
|
||||
|
||||
// Registration hashes a password with Argon2id, which is slow on a small
|
||||
// replica; the setup is not measured, so it must not fail on the short
|
||||
// timeout of the measured requests.
|
||||
func TestSlowSetupDoesNotFailTheRun(t *testing.T) {
|
||||
slowAccounts := func(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method == http.MethodPost && (r.URL.Path == "/api/v1/users" || r.URL.Path == "/api/v1/auth/sessions") {
|
||||
time.Sleep(300 * time.Millisecond)
|
||||
}
|
||||
next.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
cfg, err := parse("bench", []string{"-base-url", serve(t, slowAccounts), "-users", "2", "-chats", "1", "-seed-messages", "1",
|
||||
"-rates", "10", "-step", "1s", "-warmup", "0s", "-timeout", "100ms", "-out", t.TempDir()})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := runBench(context.Background(), cfg); err != nil {
|
||||
t.Fatalf("a setup slower than -timeout failed the run: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBenchAgainstLiveServer(t *testing.T) {
|
||||
out := t.TempDir()
|
||||
cfg, err := parse("bench", []string{"-base-url", liveServer(t), "-users", "4", "-chats", "2", "-seed-messages", "3",
|
||||
|
||||
Reference in New Issue
Block a user