2015-12-09 19:23:16 +00:00
|
|
|
package selector
|
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"
|
2015-12-09 00:02:45 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestRandomSelector(t *testing.T) {
|
|
|
|
counts := map[string]int{}
|
|
|
|
|
2016-02-26 00:09:06 +00:00
|
|
|
rs := &randomSelector{
|
2015-12-09 19:23:16 +00:00
|
|
|
so: Options{
|
|
|
|
Registry: mock.NewRegistry(),
|
2015-12-09 00:02:45 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2016-02-26 00:09:06 +00:00
|
|
|
next, err := rs.Select("foo")
|
2015-12-09 00:02:45 +00:00
|
|
|
if err != nil {
|
2015-12-09 02:31:17 +00:00
|
|
|
t.Errorf("Unexpected error calling random select: %v", err)
|
2015-12-09 00:02:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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("Random Counts %v", counts)
|
|
|
|
}
|