mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-11 00:14:00 +00:00
feat: make proposal responses durable
This commit is contained in:
@@ -22,8 +22,18 @@ type queueBackendSpy struct{ createCalls, heartbeatCalls, cancelCalls, getCalls
|
||||
type sessionBackendSpy struct{ calls int }
|
||||
|
||||
type proposalBackendSpy struct {
|
||||
proposal domain.Proposal
|
||||
calls int
|
||||
proposal domain.Proposal
|
||||
calls int
|
||||
mutations int
|
||||
}
|
||||
|
||||
func (b *proposalBackendSpy) Respond(_ context.Context, playerID, _ string, key string, accept bool, revision uint64, now time.Time) (domain.Proposal, error) {
|
||||
b.mutations++
|
||||
updated, err := b.proposal.Respond(playerID, key, accept, revision, now)
|
||||
if err == nil {
|
||||
b.proposal = updated
|
||||
}
|
||||
return updated, err
|
||||
}
|
||||
|
||||
func (b *proposalBackendSpy) Get(_ context.Context, playerID, _ string, _ time.Time) (domain.Proposal, error) {
|
||||
@@ -389,6 +399,21 @@ func TestProposalRecoveryUsesDurableBackendAndRemainsParticipantScoped(t *testin
|
||||
if status := get(participantSession, participantToken); status != http.StatusOK {
|
||||
t.Fatalf("participant recovery status = %d", status)
|
||||
}
|
||||
respond, err := http.NewRequest(http.MethodPost, server.URL+"/v1/proposals/"+proposal.ProposalID+"/accept", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
respond.Header.Set("Authorization", "Bearer "+participantSession.SessionID+":"+participantToken)
|
||||
respond.Header.Set("Idempotency-Key", "proposal-durable-response-123456")
|
||||
respond.Header.Set("If-Match-Revision", "0")
|
||||
response, err := server.Client().Do(respond)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_ = response.Body.Close()
|
||||
if response.StatusCode != http.StatusOK || backend.mutations != 1 {
|
||||
t.Fatalf("durable response status = %d, mutations = %d", response.StatusCode, backend.mutations)
|
||||
}
|
||||
if status := get(outsiderSession, outsiderToken); status != http.StatusNotFound {
|
||||
t.Fatalf("outsider recovery status = %d", status)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user