test(worker): add retry and persistence checks and adapt attachment tests for async processing

This commit is contained in:
kk10
2026-11-16 12:41:11 +03:00
parent 4a6176fe81
commit eafc437933
9 changed files with 345 additions and 70 deletions
+1 -39
View File
@@ -6,50 +6,12 @@ import (
"bytes"
"io"
"net/http"
"os/exec"
"testing"
"time"
"mtusi2026-messenger/internal/dto"
)
func compose(t *testing.T, args ...string) {
t.Helper()
cmd := exec.Command("docker", append([]string{"compose"}, args...)...)
cmd.Dir = ".."
if out, err := cmd.CombinedOutput(); err != nil {
t.Fatalf("docker compose %v: %v\n%s", args, err, out)
}
}
func stopService(t *testing.T, name string) {
t.Helper()
compose(t, "stop", name)
t.Cleanup(func() {
compose(t, "start", name)
waitReady(t)
})
}
func waitReady(t *testing.T) {
t.Helper()
deadline := time.Now().Add(60 * time.Second)
for time.Now().Before(deadline) {
resp, err := httpClient.Get(*baseURL + "/health/ready")
if err == nil {
resp.Body.Close()
if resp.StatusCode == http.StatusOK {
return
}
}
time.Sleep(500 * time.Millisecond)
}
t.Fatal("service did not become ready in 60s")
}
func TestRedisDown(t *testing.T) {
user := createUser(t)
@@ -140,7 +102,7 @@ func TestS3Down(t *testing.T) {
response := uploadAttachment(t, user, chat.ID, "recovery.png", "image/png", original)
status := response.StatusCode
response.Body.Close()
if status == http.StatusCreated {
if status == http.StatusAccepted {
uploaded = true
} else if status != http.StatusServiceUnavailable {
t.Fatalf("unexpected upload recovery status: %d", status)