X-Git-Url: https://git.giacomolli.uk/onechat/blobdiff_plain/80e348724041a694002fc38f57e8868b9b9a2be9..98d137c3e945a09f76e85bd18238558c668fdca4:/syncer_test.go?ds=sidebyside diff --git a/syncer_test.go b/syncer_test.go index d463eec..65a9672 100644 --- a/syncer_test.go +++ b/syncer_test.go @@ -2,6 +2,7 @@ package main import ( "bufio" + "context" "errors" "fmt" "os" @@ -76,16 +77,35 @@ func TestFlushWithoutWritesNeedsNoSync(t *testing.T) { } func TestAFailedSyncFailsEachLaterFlush(t *testing.T) { + failure := errors.New("disk error") s := newSyncer(func() error { - return errors.New("disk error") + return failure }) s.Written() - require.ErrorContains(t, s.Flush(t.Context()), "disk error") + require.ErrorIs(t, s.Flush(t.Context()), failure) s.Written() - require.ErrorContains(t, s.Flush(t.Context()), "disk error") - require.ErrorContains(t, s.Close(), "disk error") + require.ErrorIs(t, s.Flush(t.Context()), failure) + 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) {