Skip to content

Commit

Permalink
feat: initial circuit ready tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jeroenrinzema committed Dec 2, 2019
1 parent f33a739 commit f8c480e
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions internal/circuit/ready_test.go
Original file line number Diff line number Diff line change
@@ -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()
}

0 comments on commit f8c480e

Please sign in to comment.