mirror of
https://github.com/kemko/nomad.git
synced 2026-01-05 09:55:44 +03:00
Test RPC from server
This commit is contained in:
@@ -61,7 +61,6 @@ func (c *Client) RPC(method string, args interface{}, reply interface{}) error {
|
||||
return mErr.ErrorOrNil()
|
||||
}
|
||||
|
||||
// TODO This can't really be tested until Servers can dial back to the client.
|
||||
// setupClientRpc is used to setup the Client's RPC endpoints
|
||||
func (c *Client) setupClientRpc() {
|
||||
// Initialize the RPC handlers
|
||||
|
||||
53
nomad/client_stats_endpoint_test.go
Normal file
53
nomad/client_stats_endpoint_test.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package nomad
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
msgpackrpc "github.com/hashicorp/net-rpc-msgpackrpc"
|
||||
"github.com/hashicorp/nomad/client"
|
||||
"github.com/hashicorp/nomad/client/config"
|
||||
cstructs "github.com/hashicorp/nomad/client/structs"
|
||||
"github.com/hashicorp/nomad/nomad/structs"
|
||||
"github.com/hashicorp/nomad/testutil"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestClientStats_Stats_Local(t *testing.T) {
|
||||
t.Parallel()
|
||||
require := require.New(t)
|
||||
|
||||
// Start a server and client
|
||||
s := TestServer(t, nil)
|
||||
defer s.Shutdown()
|
||||
codec := rpcClient(t, s)
|
||||
testutil.WaitForLeader(t, s.RPC)
|
||||
|
||||
c := client.TestClient(t, func(c *config.Config) {
|
||||
c.Servers = []string{s.config.RPCAddr.String()}
|
||||
})
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
nodes := s.connectedNodes()
|
||||
return len(nodes) == 1, nil
|
||||
}, func(err error) {
|
||||
t.Fatalf("should have a clients")
|
||||
})
|
||||
|
||||
// Make the request without having a node-id
|
||||
req := &cstructs.ClientStatsRequest{
|
||||
QueryOptions: structs.QueryOptions{Region: "global"},
|
||||
}
|
||||
|
||||
// Fetch the response
|
||||
var resp cstructs.ClientStatsResponse
|
||||
err := msgpackrpc.CallWithCodec(codec, "ClientStats.Stats", req, &resp)
|
||||
require.NotNil(err)
|
||||
require.Contains(err.Error(), "missing")
|
||||
|
||||
// Fetch the response setting the node id
|
||||
req.NodeID = c.NodeID()
|
||||
var resp2 cstructs.ClientStatsResponse
|
||||
err = msgpackrpc.CallWithCodec(codec, "ClientStats.Stats", req, &resp2)
|
||||
require.Nil(err)
|
||||
require.NotNil(resp2.HostStats)
|
||||
}
|
||||
Reference in New Issue
Block a user