2015-11-24 06:22:48 +00:00
|
|
|
package nomad
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
2019-01-15 19:46:12 +00:00
|
|
|
msgpackrpc "github.com/hashicorp/net-rpc-msgpackrpc"
|
2015-11-24 06:22:48 +00:00
|
|
|
"github.com/hashicorp/nomad/nomad/structs"
|
|
|
|
"github.com/hashicorp/nomad/testutil"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestRegionList(t *testing.T) {
|
2017-07-23 22:04:38 +00:00
|
|
|
t.Parallel()
|
2015-11-24 06:22:48 +00:00
|
|
|
// Make the servers
|
2018-01-12 01:00:30 +00:00
|
|
|
s1 := TestServer(t, func(c *Config) {
|
2015-11-24 06:22:48 +00:00
|
|
|
c.Region = "region1"
|
|
|
|
})
|
|
|
|
defer s1.Shutdown()
|
|
|
|
codec := rpcClient(t, s1)
|
|
|
|
|
2018-01-12 01:00:30 +00:00
|
|
|
s2 := TestServer(t, func(c *Config) {
|
2015-11-24 06:22:48 +00:00
|
|
|
c.Region = "region2"
|
|
|
|
})
|
|
|
|
defer s2.Shutdown()
|
|
|
|
|
|
|
|
// Join the servers
|
|
|
|
s2Addr := fmt.Sprintf("127.0.0.1:%d",
|
|
|
|
s2.config.SerfConfig.MemberlistConfig.BindPort)
|
|
|
|
if n, err := s1.Join([]string{s2Addr}); err != nil || n != 1 {
|
|
|
|
t.Fatalf("Failed joining: %v (%d joined)", err, n)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Query the regions list
|
|
|
|
testutil.WaitForResult(func() (bool, error) {
|
|
|
|
var arg structs.GenericRequest
|
|
|
|
var out []string
|
|
|
|
if err := msgpackrpc.CallWithCodec(codec, "Region.List", &arg, &out); err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
if len(out) != 2 || out[0] != "region1" || out[1] != "region2" {
|
|
|
|
t.Fatalf("unexpected regions: %v", out)
|
|
|
|
}
|
|
|
|
return true, nil
|
|
|
|
}, func(err error) {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
})
|
|
|
|
}
|