2015-11-08 01:48:48 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2015-11-20 16:17:33 +00:00
|
|
|
"github.com/micro/go-micro/registry"
|
2015-11-08 01:48:48 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestNodeSelector(t *testing.T) {
|
|
|
|
services := []*registry.Service{
|
|
|
|
{
|
|
|
|
Name: "foo",
|
|
|
|
Version: "1.0.0",
|
|
|
|
Nodes: []*registry.Node{
|
|
|
|
{
|
|
|
|
Id: "foo-123",
|
|
|
|
Address: "localhost",
|
|
|
|
Port: 9999,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "foo",
|
|
|
|
Version: "1.0.1",
|
|
|
|
Nodes: []*registry.Node{
|
|
|
|
{
|
|
|
|
Id: "foo-321",
|
|
|
|
Address: "localhost",
|
|
|
|
Port: 6666,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
counts := map[string]int{}
|
|
|
|
|
|
|
|
for i := 0; i < 100; i++ {
|
|
|
|
n, err := nodeSelector(services)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Expected node, got err: %v", err)
|
|
|
|
}
|
|
|
|
counts[n.Id]++
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Logf("Counts %v", counts)
|
|
|
|
}
|