2015-12-09 22:23:16 +03:00
|
|
|
package selector
|
2015-12-09 03:02:45 +03:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2015-12-09 22:23:16 +03:00
|
|
|
|
|
|
|
"github.com/micro/go-micro/registry/mock"
|
2015-12-09 03:02:45 +03:00
|
|
|
)
|
|
|
|
|
2016-05-07 02:04:08 +03:00
|
|
|
func TestDefaultSelector(t *testing.T) {
|
2015-12-09 03:02:45 +03:00
|
|
|
counts := map[string]int{}
|
|
|
|
|
2016-05-04 00:06:19 +03:00
|
|
|
rs := newDefaultSelector(Registry(mock.NewRegistry()))
|
2015-12-09 03:02:45 +03:00
|
|
|
|
2016-02-26 03:09:06 +03:00
|
|
|
next, err := rs.Select("foo")
|
2015-12-09 03:02:45 +03:00
|
|
|
if err != nil {
|
2016-05-04 00:06:19 +03:00
|
|
|
t.Errorf("Unexpected error calling default 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]++
|
|
|
|
}
|
|
|
|
|
2016-05-07 02:04:08 +03:00
|
|
|
t.Logf("Default Counts %v", counts)
|
|
|
|
}
|