From: Anderson A. Giacomolli Date: Wed, 11 Nov 2026 15:07:59 +0000 (-0300) Subject: Prove direct cancellation during a pending sync X-Git-Url: https://git.giacomolli.uk/onechat/commitdiff_plain/2a528fe2981639cf099c713a6be16b8ea0e2cc67?ds=inline Prove direct cancellation during a pending sync 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 --- diff --git a/syncer_test.go b/syncer_test.go index 8eeb1ee..65a9672 100644 --- a/syncer_test.go +++ b/syncer_test.go @@ -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)