]> git.giacomolli.uk - onechat/commitdiff
Prove direct cancellation during a pending sync
authorAnderson A. Giacomolli <redacted>
Wed, 11 Nov 2026 15:07:59 +0000 (12:07 -0300)
committerAnderson A. Giacomolli <redacted>
Wed, 11 Nov 2026 15:07:59 +0000 (12:07 -0300)
A cancelled flush returns the direct context error while the durable
write is still pending. Releasing the sync then lets final cleanup
finish normally. This protects cancellation identity and shutdown
ordering while local failure context is added elsewhere.

Issue: 3cdc678

syncer_test.go

index 8eeb1eeee55213541def549d08b8b4772b0508ee..65a96725ee02829ac9e4c94f954cc5423562ca5e 100644 (file)
@@ -2,6 +2,7 @@ package main
 
 import (
        "bufio"
+       "context"
        "errors"
        "fmt"
        "os"
@@ -89,6 +90,24 @@ func TestAFailedSyncFailsEachLaterFlush(t *testing.T) {
        require.ErrorIs(t, s.Close(), failure)
 }
 
+func TestFlushCancellationKeepsTheDirectContextError(t *testing.T) {
+       gate := newSyncerGatedSync()
+       s := newSyncer(gate.Sync)
+       s.Written()
+       gate.WaitStarted(t, 1)
+
+       ctx, cancel := context.WithCancel(t.Context())
+       defer cancel()
+
+       cancel()
+
+       err := s.Flush(ctx)
+       require.Equal(t, context.Canceled, err)
+
+       gate.Release()
+       require.NoError(t, s.Close())
+}
+
 func TestMemoryFlushSyncsTheChat(t *testing.T) {
        memory, err := openMemory(t.Context(), t.TempDir(), newTestClock().Now, newFakeSummarizer(), discardLog())
        require.NoError(t, err)