2015-12-09 22:23:16 +03:00
|
|
|
package selector
|
2015-12-09 03:02:45 +03:00
|
|
|
|
|
|
|
import (
|
2020-04-09 14:05:46 +03:00
|
|
|
"os"
|
2015-12-09 03:02:45 +03:00
|
|
|
"testing"
|
2015-12-09 22:23:16 +03:00
|
|
|
|
2020-01-30 14:39:00 +03:00
|
|
|
"github.com/micro/go-micro/v2/registry/memory"
|
2015-12-09 03:02:45 +03:00
|
|
|
)
|
|
|
|
|
2018-12-29 18:44:51 +03:00
|
|
|
func TestRegistrySelector(t *testing.T) {
|
2015-12-09 03:02:45 +03:00
|
|
|
counts := map[string]int{}
|
|
|
|
|
2019-11-16 13:55:11 +03:00
|
|
|
r := memory.NewRegistry(memory.Services(testData))
|
2019-01-14 18:27:25 +03:00
|
|
|
cache := NewSelector(Registry(r))
|
2015-12-09 03:02:45 +03:00
|
|
|
|
2018-12-29 18:44:51 +03:00
|
|
|
next, err := cache.Select("foo")
|
2015-12-09 03:02:45 +03:00
|
|
|
if err != nil {
|
2018-12-29 18:44:51 +03:00
|
|
|
t.Errorf("Unexpected error calling cache 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]++
|
|
|
|
}
|
|
|
|
|
2020-04-09 14:05:46 +03:00
|
|
|
if len(os.Getenv("IN_TRAVIS_CI")) == 0 {
|
|
|
|
t.Logf("Selector Counts %v", counts)
|
|
|
|
}
|
2016-05-07 02:04:08 +03:00
|
|
|
}
|