diff --git a/internal/circuit/ready_test.go b/internal/circuit/ready_test.go new file mode 100644 index 0000000..7b0b1c2 --- /dev/null +++ b/internal/circuit/ready_test.go @@ -0,0 +1,52 @@ +package circuit + +import ( + "context" + "testing" + "time" +) + +func TestReadyOnce(t *testing.T) { + ready := Ready{} + timeout, _ := context.WithTimeout(context.Background(), 50*time.Millisecond) + + go ready.Mark() + + select { + case <-timeout.Done(): + t.Error("timeout reached") + case <-ready.On(): + } +} + +func TestReadyOnceMultipleMark(t *testing.T) { + ready := Ready{} + timeout, _ := context.WithTimeout(context.Background(), 50*time.Millisecond) + + go ready.Mark() + go ready.Mark() + + select { + case <-timeout.Done(): + t.Error("timeout reached") + case <-ready.On(): + } +} + +func TestReadyOnceMultipleListeners(t *testing.T) { + ready := Ready{} + timeout, _ := context.WithTimeout(context.Background(), 50*time.Millisecond) + + listener := func() { + select { + case <-timeout.Done(): + t.Error("timeout reached") + case <-ready.On(): + } + } + + go listener() + go listener() + + ready.Mark() +}