Исправить замечания ревью кода: убрать повтор в AppendOnce за счёт запаса у чистки ключей, вынести MessagePayload и SameContent, принять X-Request-Id от балансировщика, упростить фоновые задачи сервера, сократить комментарии
This commit is contained in:
@@ -9,7 +9,6 @@ import (
|
||||
"github.com/google/uuid"
|
||||
|
||||
"messenger/internal/chat"
|
||||
"messenger/internal/chat/store"
|
||||
)
|
||||
|
||||
const keyTTL = time.Hour
|
||||
@@ -168,29 +167,6 @@ func TestCleanerSkipsRowLockedByRequest(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// The key is alive when the claim runs but deleted before the replay lookup,
|
||||
// as by a cleaner whose clock is a moment later at the TTL boundary. The
|
||||
// operation starts over and stores the new message.
|
||||
func TestAppendOnceRetriesWhenKeyVanishes(t *testing.T) {
|
||||
f := newFixture(t)
|
||||
alice := f.mustUser(t)
|
||||
c := f.mustChat(t, alice)
|
||||
f.appendOnce(t, f.newMessage(t, c.ID, alice), "k1")
|
||||
var once sync.Once
|
||||
restore := store.SetAfterClaim(func() {
|
||||
once.Do(func() {
|
||||
if _, err := db.Pool.Exec(context.Background(), `DELETE FROM message_idempotency_keys WHERE key = 'k1'`); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
})
|
||||
})
|
||||
defer restore()
|
||||
next := f.newMessage(t, c.ID, alice)
|
||||
if got := f.appendOnce(t, next, "k1"); got.ID != next.ID {
|
||||
t.Fatalf("got %v, want the new message %v", got.ID, next.ID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeleteExpiredKeysOnlyExpiredAndUpToLimit(t *testing.T) {
|
||||
f := newFixture(t)
|
||||
alice := f.mustUser(t)
|
||||
|
||||
Reference in New Issue
Block a user