From 3e9bd931ed198a0926499a8eb7daa774f90ebf88 Mon Sep 17 00:00:00 2001 From: Anis Elleuch Date: Thu, 20 Jan 2022 18:36:09 +0100 Subject: [PATCH] tests: Remove RPC wording from the code (#14142) The lock was using net/rpc in the past but it got replaced with a REST API. This commit will fix function names/comments to avoid confusion. --- internal/dsync/dsync-client_test.go | 60 ++++++++++++++--------------- internal/dsync/dsync-server_test.go | 4 +- internal/dsync/dsync_test.go | 8 ++-- 3 files changed, 36 insertions(+), 36 deletions(-) diff --git a/internal/dsync/dsync-client_test.go b/internal/dsync/dsync-client_test.go index d763aafc3..8172505ef 100644 --- a/internal/dsync/dsync-client_test.go +++ b/internal/dsync/dsync-client_test.go @@ -29,13 +29,13 @@ import ( "github.com/minio/minio/internal/rest" ) -// ReconnectRPCClient is a wrapper type for rpc.Client which provides reconnect on first failure. -type ReconnectRPCClient struct { - u *url.URL - rpc *rest.Client +// ReconnectRESTClient is a wrapper type for rest.Client which provides reconnect on first failure. +type ReconnectRESTClient struct { + u *url.URL + rest *rest.Client } -// newClient constructs a ReconnectRPCClient object with addr and endpoint initialized. +// newClient constructs a ReconnectRESTClient object with addr and endpoint initialized. // It _doesn't_ connect to the remote endpoint. See Call method to see when the // connect happens. func newClient(endpoint string) NetLocker { @@ -59,24 +59,24 @@ func newClient(endpoint string) NetLocker { DisableCompression: true, } - return &ReconnectRPCClient{ - u: u, - rpc: rest.NewClient(u, tr, nil), + return &ReconnectRESTClient{ + u: u, + rest: rest.NewClient(u, tr, nil), } } // Close closes the underlying socket file descriptor. -func (rpcClient *ReconnectRPCClient) IsOnline() bool { - // If rpc client has not connected yet there is nothing to close. - return rpcClient.rpc != nil +func (restClient *ReconnectRESTClient) IsOnline() bool { + // If rest client has not connected yet there is nothing to close. + return restClient.rest != nil } -func (rpcClient *ReconnectRPCClient) IsLocal() bool { +func (restClient *ReconnectRESTClient) IsLocal() bool { return false } // Close closes the underlying socket file descriptor. -func (rpcClient *ReconnectRPCClient) Close() error { +func (restClient *ReconnectRESTClient) Close() error { return nil } @@ -99,14 +99,14 @@ func toLockError(err error) error { return err } -// Call makes a RPC call to the remote endpoint using the default codec, namely encoding/gob. -func (rpcClient *ReconnectRPCClient) Call(method string, args LockArgs) (status bool, err error) { +// Call makes a REST call to the remote endpoint using the msgp codec +func (restClient *ReconnectRESTClient) Call(method string, args LockArgs) (status bool, err error) { buf, err := args.MarshalMsg(nil) if err != nil { return false, err } body := bytes.NewReader(buf) - respBody, err := rpcClient.rpc.Call(context.Background(), method, + respBody, err := restClient.rest.Call(context.Background(), method, url.Values{}, body, body.Size()) defer xhttp.DrainBody(respBody) @@ -120,30 +120,30 @@ func (rpcClient *ReconnectRPCClient) Call(method string, args LockArgs) (status } } -func (rpcClient *ReconnectRPCClient) RLock(ctx context.Context, args LockArgs) (status bool, err error) { - return rpcClient.Call("/v1/rlock", args) +func (restClient *ReconnectRESTClient) RLock(ctx context.Context, args LockArgs) (status bool, err error) { + return restClient.Call("/v1/rlock", args) } -func (rpcClient *ReconnectRPCClient) Lock(ctx context.Context, args LockArgs) (status bool, err error) { - return rpcClient.Call("/v1/lock", args) +func (restClient *ReconnectRESTClient) Lock(ctx context.Context, args LockArgs) (status bool, err error) { + return restClient.Call("/v1/lock", args) } -func (rpcClient *ReconnectRPCClient) RUnlock(ctx context.Context, args LockArgs) (status bool, err error) { - return rpcClient.Call("/v1/runlock", args) +func (restClient *ReconnectRESTClient) RUnlock(ctx context.Context, args LockArgs) (status bool, err error) { + return restClient.Call("/v1/runlock", args) } -func (rpcClient *ReconnectRPCClient) Unlock(ctx context.Context, args LockArgs) (status bool, err error) { - return rpcClient.Call("/v1/unlock", args) +func (restClient *ReconnectRESTClient) Unlock(ctx context.Context, args LockArgs) (status bool, err error) { + return restClient.Call("/v1/unlock", args) } -func (rpcClient *ReconnectRPCClient) Refresh(ctx context.Context, args LockArgs) (refreshed bool, err error) { - return rpcClient.Call("/v1/refresh", args) +func (restClient *ReconnectRESTClient) Refresh(ctx context.Context, args LockArgs) (refreshed bool, err error) { + return restClient.Call("/v1/refresh", args) } -func (rpcClient *ReconnectRPCClient) ForceUnlock(ctx context.Context, args LockArgs) (reply bool, err error) { - return rpcClient.Call("/v1/force-unlock", args) +func (restClient *ReconnectRESTClient) ForceUnlock(ctx context.Context, args LockArgs) (reply bool, err error) { + return restClient.Call("/v1/force-unlock", args) } -func (rpcClient *ReconnectRPCClient) String() string { - return rpcClient.u.String() +func (restClient *ReconnectRESTClient) String() string { + return restClient.u.String() } diff --git a/internal/dsync/dsync-server_test.go b/internal/dsync/dsync-server_test.go index fb8153804..065a95d41 100644 --- a/internal/dsync/dsync-server_test.go +++ b/internal/dsync/dsync-server_test.go @@ -148,13 +148,13 @@ func (lh *lockServerHandler) RLockHandler(w http.ResponseWriter, r *http.Request } } -func stopRPCServers() { +func stopLockServers() { for i := 0; i < numberOfNodes; i++ { nodes[i].Close() } } -func startRPCServers() { +func startLockServers() { for i := 0; i < numberOfNodes; i++ { lsrv := &lockServer{ mutex: sync.Mutex{}, diff --git a/internal/dsync/dsync_test.go b/internal/dsync/dsync_test.go index 43ee5e899..3154112d3 100644 --- a/internal/dsync/dsync_test.go +++ b/internal/dsync/dsync_test.go @@ -30,9 +30,9 @@ import ( // TestMain initializes the testing framework func TestMain(m *testing.M) { - startRPCServers() + startLockServers() - // Initialize net/rpc clients for dsync. + // Initialize locker clients for dsync. var clnts []NetLocker for i := 0; i < len(nodes); i++ { clnts = append(clnts, newClient(nodes[i].URL)) @@ -43,7 +43,7 @@ func TestMain(m *testing.M) { } code := m.Run() - stopRPCServers() + stopLockServers() os.Exit(code) } @@ -224,7 +224,7 @@ func TestFailedRefreshLock(t *testing.T) { t.Skip("skipping test in short mode.") } - // Simulate Refresh RPC response to return no locking found + // Simulate Refresh response to return no locking found for i := range lockServers[:3] { lockServers[i].setRefreshReply(false) defer lockServers[i].setRefreshReply(true)