micro/selector/roundrobin/round_robin_selector_test.go

34 lines
592 B
Go
Raw Normal View History

2015-12-09 19:23:16 +00:00
package roundrobin
2015-12-09 00:02:45 +00:00
import (
"testing"
2015-12-09 19:23:16 +00:00
"github.com/micro/go-micro/registry/mock"
"github.com/micro/go-micro/selector"
2015-12-09 00:02:45 +00:00
)
func TestRoundRobinSelector(t *testing.T) {
counts := map[string]int{}
rr := &roundRobinSelector{
2015-12-09 19:23:16 +00:00
so: selector.Options{
Registry: mock.NewRegistry(),
2015-12-09 00:02:45 +00:00
},
}
next, err := rr.Select("foo")
if err != nil {
t.Errorf("Unexpected error calling rr select: %v", err)
}
for i := 0; i < 100; i++ {
node, err := next()
if err != nil {
t.Errorf("Expected node err, got err: %v", err)
}
counts[node.Id]++
}
t.Logf("Round Robin Counts %v", counts)
}