Сделать отправку сообщения идемпотентной по Idempotency-Key с общей таблицей ключей и их чисткой

This commit is contained in:
2026-11-02 17:11:04 +03:00
parent 7fa8881eb3
commit 951fd0d517
19 changed files with 856 additions and 40 deletions
+20 -6
View File
@@ -146,15 +146,29 @@ func TestLogoutRevokesOnlyTheCurrentToken(t *testing.T) {
ts.expect(ts.do(http.MethodGet, "/api/v1/users/me", other.Token, nil, nil), http.StatusOK, "")
}
// The TTL leaves room for a loaded machine: with one second the first request
// after login sometimes arrived too late under -race with all packages
// running at once.
// The expiry is an absolute time written by the application and enforced by
// Valkey's clock. Here the test runs on the Windows host and Valkey in the
// Docker VM, whose clock lags by a fraction of a second, so the test waits
// for the 401 with a tolerance instead of sleeping exactly one TTL. On the
// stand both run in the same VM.
func TestSessionExpiresAfterTTL(t *testing.T) {
ts := newTesterWithTTL(t, 3*time.Second)
const ttl, clockTolerance = 2 * time.Second, 3 * time.Second
ts := newTesterWithTTL(t, ttl)
alice := ts.user("alice", "A")
ts.expect(ts.do(http.MethodGet, "/api/v1/users/me", alice.token, nil, nil), http.StatusOK, "")
time.Sleep(3200 * time.Millisecond)
ts.expect(ts.do(http.MethodGet, "/api/v1/users/me", alice.token, nil, nil), http.StatusUnauthorized, "unauthorized")
time.Sleep(ttl)
deadline := time.Now().Add(clockTolerance)
for {
res := ts.do(http.MethodGet, "/api/v1/users/me", alice.token, nil, nil)
if res.status == http.StatusUnauthorized {
ts.expect(res, http.StatusUnauthorized, "unauthorized")
return
}
if time.Now().After(deadline) {
t.Fatalf("session still valid %v after its TTL of %v", clockTolerance, ttl)
}
time.Sleep(100 * time.Millisecond)
}
}
func TestRegistrationIsPublicAndIgnoresAuthorization(t *testing.T) {