Исправить замечания ревью кода: убрать повтор в AppendOnce за счёт запаса у чистки ключей, вынести MessagePayload и SameContent, принять X-Request-Id от балансировщика, упростить фоновые задачи сервера, сократить комментарии
This commit is contained in:
+2
-5
@@ -39,10 +39,8 @@ type Deps struct {
|
||||
MaxBodyBytes int64
|
||||
// RequestTimeout bounds every API request; zero means the default.
|
||||
RequestTimeout time.Duration
|
||||
// InstanceID is sent as X-Instance-Id on every response.
|
||||
InstanceID string
|
||||
// IdempotencyTTL is how long a message Idempotency-Key is remembered;
|
||||
// zero means the default.
|
||||
InstanceID string
|
||||
// IdempotencyTTL zero means the contract's 24 hours.
|
||||
IdempotencyTTL time.Duration
|
||||
}
|
||||
|
||||
@@ -50,7 +48,6 @@ type Deps struct {
|
||||
// request that gives up on a dependency can still write its 503.
|
||||
const defaultRequestTimeout = 5 * time.Second
|
||||
|
||||
// defaultIdempotencyTTL is the contract's retention of message keys.
|
||||
const defaultIdempotencyTTL = 24 * time.Hour
|
||||
|
||||
func New(d Deps) *App {
|
||||
|
||||
@@ -52,7 +52,6 @@ func TestMain(m *testing.M) {
|
||||
|
||||
const testPassword = "correct-horse-battery"
|
||||
|
||||
// testInstance is the alias of the in-process application under test.
|
||||
const testInstance = "00000000000000a1"
|
||||
|
||||
// errorBody mirrors the contract error envelope.
|
||||
@@ -245,7 +244,6 @@ func (ts *tester) message(token, chatID, text string) chat.MessageResponse {
|
||||
return decode[chat.MessageResponse](ts.t, res)
|
||||
}
|
||||
|
||||
// freshKey is the header of a first attempt: a key never used before.
|
||||
func freshKey() map[string]string {
|
||||
return map[string]string{"Idempotency-Key": uuid.NewString()}
|
||||
}
|
||||
|
||||
@@ -146,11 +146,8 @@ func TestLogoutRevokesOnlyTheCurrentToken(t *testing.T) {
|
||||
ts.expect(ts.do(http.MethodGet, "/api/v1/users/me", other.Token, nil, nil), http.StatusOK, "")
|
||||
}
|
||||
|
||||
// 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.
|
||||
// Valkey enforces the expiry by the Docker VM clock, which may lag this host
|
||||
// by a fraction of a second, so the 401 is awaited with a tolerance.
|
||||
func TestSessionExpiresAfterTTL(t *testing.T) {
|
||||
const ttl, clockTolerance = 2 * time.Second, 3 * time.Second
|
||||
ts := newTesterWithTTL(t, ttl)
|
||||
|
||||
@@ -101,9 +101,8 @@ func TestOutsiderWithoutKeyGets400AndWithKey404(t *testing.T) {
|
||||
ts.expect(ts.send(eve.token, room.ID, "k", map[string]string{"text": "x"}), http.StatusNotFound, "not_found")
|
||||
}
|
||||
|
||||
// Two applications over the same stores stand for two replicas behind the
|
||||
// balancer: retries of one key alternate between them and still create one
|
||||
// message.
|
||||
// Two applications over the same stores stand for two replicas: retries of one
|
||||
// key alternate between them and still create one message.
|
||||
func TestConcurrentReplaysAcrossTwoAppsCreateOneMessage(t *testing.T) {
|
||||
ts := newTester(t)
|
||||
alice := ts.user("alice", "A")
|
||||
|
||||
Reference in New Issue
Block a user