X-Git-Url: https://git.giacomolli.uk/onechat/blobdiff_plain/2daf91497c2cc70d7156f7c0d99b1451933a818a..80e348724041a694002fc38f57e8868b9b9a2be9:/syncer_test.go diff --git a/syncer_test.go b/syncer_test.go index efa174a..d463eec 100644 --- a/syncer_test.go +++ b/syncer_test.go @@ -28,6 +28,7 @@ func TestFlushWaitsForASyncThatStartsAfterTheWrite(t *testing.T) { // This write comes during the first sync, so that sync does not cover // it. s.Written() + flushed := make(chan error) go func() { flushed <- s.Flush(t.Context()) @@ -35,6 +36,7 @@ func TestFlushWaitsForASyncThatStartsAfterTheWrite(t *testing.T) { gate.Release() gate.WaitStarted(t, 2) + select { case err := <-flushed: t.Fatalf("flush returned before the second sync: %v", err) @@ -52,6 +54,7 @@ func TestOneSyncCoversTheWritesDuringTheSyncBeforeIt(t *testing.T) { s := newSyncer(gate.Sync) s.Written() gate.WaitStarted(t, 1) + for range 10 { s.Written() } @@ -103,6 +106,7 @@ func TestKilledWriterLosesNoLoggedMessage(t *testing.T) { memory, err := openMemory(t.Context(), root, time.Now, newFakeSummarizer(), discardLog()) require.NoError(t, err) require.GreaterOrEqual(t, memory.log.Len(), acknowledged) + for id := range memory.log.Len() { message, err := memory.log.Message(id) require.NoError(t, err) @@ -144,12 +148,21 @@ type SyncerGatedSync struct { release chan struct{} } +func newSyncerGatedSync() *SyncerGatedSync { + return &SyncerGatedSync{ + started: make(chan struct{}, 100), + release: make(chan struct{}), + } +} + func (g *SyncerGatedSync) Sync() error { g.mutex.Lock() + g.count++ g.mutex.Unlock() g.started <- struct{}{} + <-g.release return nil @@ -167,6 +180,7 @@ func (g *SyncerGatedSync) WaitStarted(t *testing.T, n int) { // Release lets the running sync end. func (g *SyncerGatedSync) Release() { <-g.started + g.release <- struct{}{} } @@ -177,13 +191,6 @@ func (g *SyncerGatedSync) Count() int { return g.count } -func newSyncerGatedSync() *SyncerGatedSync { - return &SyncerGatedSync{ - started: make(chan struct{}, 100), - release: make(chan struct{}), - } -} - // syncerRunKilledWriter starts the writer child on the chat in root, kills it // with SIGKILL after it acknowledged count messages, and returns the number of // messages that it acknowledged. @@ -206,6 +213,7 @@ func syncerRunKilledWriter(t *testing.T, root string, count int) int { } require.NoError(t, command.Process.Kill()) + for scanner.Scan() { _, err = strconv.Atoi(strings.TrimSpace(scanner.Text())) if err == nil {