From 3382abb51b06f9d15a863af4df015ec18a455288 Mon Sep 17 00:00:00 2001 From: Christopher Lamb <37453482+lambchr@users.noreply.github.com> Date: Thu, 12 Oct 2023 10:54:25 +1300 Subject: [PATCH] add delete method to race condition test --- broadcaster/backlog/backlog_test.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/broadcaster/backlog/backlog_test.go b/broadcaster/backlog/backlog_test.go index fe062aee1f..65b5d7095b 100644 --- a/broadcaster/backlog/backlog_test.go +++ b/broadcaster/backlog/backlog_test.go @@ -414,7 +414,20 @@ func TestBacklogRaceCondition(t *testing.T) { } }(t, b) - // Wait for both goroutines to finish + // Delete from backlog in goroutine. This is normally done via Append with + // a confirmed sequence number, using delete method for simplicity in test. + wg.Add(1) + go func(t *testing.T, b *backlog) { + defer wg.Done() + for _, i := range []uint64{40, 43, 47} { + b.delete(i) + time.Sleep(5 * time.Millisecond) + } + }(t, b) + + // Wait for all goroutines to finish wg.Wait() - validateBacklog(t, b, 16, 40, 55, append(indexes, newIndexes...)) + // Messages up to 47 were deleted. However the segment that 47 was in is + // kept, which is why the backlog starts at 46. + validateBacklog(t, b, 10, 46, 55, append(indexes, newIndexes...)) }