MCPcopy Create free account
hub / github.com/Mnexa-AI/e2a / TestComplete_DoubleCallIsNoop

Function TestComplete_DoubleCallIsNoop

internal/idempotency/store_test.go:216–239  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

214}
215
216func TestComplete_DoubleCallIsNoop(t *testing.T) {
217 store, userID, _ := newStoreAndUser(t)
218 ctx := context.Background()
219
220 hash := idempotency.HashBody([]byte(`{"a":1}`))
221 first, _ := store.Claim(ctx, userID, "key-dbl", "/api/v1/send", hash)
222 if first.Outcome != idempotency.OutcomeAcquired {
223 t.Fatalf("first Outcome = %d", first.Outcome)
224 }
225 originalCached := idempotency.CachedResponse{StatusCode: 200, ContentType: "application/json", Body: []byte(`{"status":"sent"}`)}
226 _ = store.Complete(ctx, userID, "key-dbl", originalCached)
227
228 // A buggy caller re-Completes with a different body. Must not
229 // overwrite the cached response.
230 _ = store.Complete(ctx, userID, "key-dbl", idempotency.CachedResponse{StatusCode: 500, Body: []byte("oops")})
231
232 replay, _ := store.Claim(ctx, userID, "key-dbl", "/api/v1/send", hash)
233 if replay.Outcome != idempotency.OutcomeReplay {
234 t.Fatalf("Outcome = %d", replay.Outcome)
235 }
236 if string(replay.Cached.Body) != string(originalCached.Body) {
237 t.Errorf("cached body = %q, want %q (Complete should be no-op after first call)", replay.Cached.Body, originalCached.Body)
238 }
239}
240
241func TestSweep_DeletesCompletedRowsPastTTL(t *testing.T) {
242 store, userID, pool := newStoreAndUser(t)

Callers

nothing calls this directly

Calls 4

HashBodyFunction · 0.92
newStoreAndUserFunction · 0.85
ClaimMethod · 0.65
CompleteMethod · 0.65

Tested by

no test coverage detected