From 287ea370fde33d95fb52507db75eb4a421a81600 Mon Sep 17 00:00:00 2001 From: Matt Jaffee Date: Wed, 8 Aug 2018 15:11:52 -0500 Subject: [PATCH] add cluster tests for anti entropy abort --- cluster_internal_test.go | 58 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/cluster_internal_test.go b/cluster_internal_test.go index 0d9603031..8bfd364bc 100644 --- a/cluster_internal_test.go +++ b/cluster_internal_test.go @@ -751,6 +751,64 @@ func TestCluster_ResizeStates(t *testing.T) { }) } +func TestAE(t *testing.T) { + t.Run("AbortDoesn'tBlockUninitialized", func(t *testing.T) { + c := newCluster() + ch := make(chan struct{}) + go func() { + c.abortAntiEntropy() + close(ch) + }() + select { + case <-ch: + return + case <-time.After(time.Second): + t.Fatalf("aborting anti entropy on a new cluster blocked") + } + }) + + t.Run("AbortBlocksInitialized", func(t *testing.T) { + c := newCluster() + c.initializeAntiEntropy() + ch := make(chan struct{}) + go func() { + c.abortAntiEntropy() + close(ch) + }() + select { + case <-ch: + t.Fatalf("aborting anti entropy on an initialized didn't block") + case <-time.After(time.Microsecond * 100): + } + }) + + t.Run("AbortAntiEntropyQ", func(t *testing.T) { + c := newCluster() + c.initializeAntiEntropy() + if c.abortAntiEntropyQ() { + t.Fatalf("abortAntiEntropyQ should report false when abort not called") + } + go func() { + for { + if c.abortAntiEntropyQ() { + break + } + } + }() + ch := make(chan struct{}) + go func() { + c.abortAntiEntropy() + close(ch) + }() + select { + case <-ch: + case <-time.After(time.Second): + t.Fatalf("abort should not have blocked this long") + } + }) + +} + // Ensures that coordinator can be changed. func TestCluster_UpdateCoordinator(t *testing.T) { t.Run("UpdateCoordinator", func(t *testing.T) {