2015-12-09 03:02:45 +03:00
|
|
|
package registry
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestRandomSelector(t *testing.T) {
|
|
|
|
counts := map[string]int{}
|
|
|
|
|
|
|
|
rr := &randomSelector{
|
|
|
|
so: SelectorOptions{
|
|
|
|
Registry: &mockRegistry{},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
next, err := rr.Select("foo")
|
|
|
|
if err != nil {
|
2015-12-09 05:31:17 +03:00
|
|
|
t.Errorf("Unexpected error calling random select: %v", err)
|
2015-12-09 03:02:45 +03: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)
|
|
|
|
}
|