2015-11-08 04:48:48 +03:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2015-11-20 19:17:33 +03:00
|
|
|
"github.com/micro/go-micro/registry"
|
2015-11-08 04:48:48 +03: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)
|
|
|
|
}
|