okami.mom/albedo
git clone https://git.nkp.pet/okami.mom/albedo
2f6697a
main
1// Conditional mutations must retain the observed ETag and never retry conflicts. 2// A controlled peer records delivery and returns conflicts deterministically. 3package daemon 4 5import ( 6"io" 7"net/http" 8"sync/atomic" 9"testing" 10) 11 12func TestConditionalMutationUsesObservedValidatorAndNeverRetriesConflict (t * testing.T ) { 13var requests atomic.Int32 14conn := controlledConnection (t ,func (w http.ResponseWriter ,r * http.Request ) { 15requests .Add (1 ) 16if r .Method != "PATCH" || r .URL .String ()!= "/sessions/s?view=configuration" || r .Header .Get ("If-Match" )!= "\"seen\"" || r .Header .Get ("Content-Type" )!= "application/merge-patch+json" { 17t .Errorf ("wrong conditional mutation: %s %s %v" ,r .Method ,r .URL ,r .Header ) 18 } 19w .WriteHeader (412 ) 20_ ,_ = io .WriteString (w ,`{"type":"about:blank","title":"Changed","status":412,"code":"precondition_failed","detail":"Refresh first"}` ) 21 }) 22if _ ,err := RenameSession (t .Context (),conn ,"s" ,"name" ,"" );err == nil || requests .Load ()!= 0 { 23t .Fatal ("unobserved mutation dispatched" ) 24 } 25if _ ,err := RenameSession (t .Context (),conn ,"s" ,"name" ,"\"seen\"" );err == nil || requests .Load ()!= 1 { 26t .Fatalf ("conditional conflict retried: %v count=%d" ,err ,requests .Load ()) 27 } 28}