From 33c2bd354aa28b1c466aa1628726874c40f549fc Mon Sep 17 00:00:00 2001 From: xubaisheng <> Date: Wed, 10 Aug 2022 00:12:10 +0800 Subject: [PATCH 1/7] getty tests --- pkg/remoting/getty/getty_client_test.go | 157 ++++++++++++++++++++ pkg/remoting/getty/getty_remoting_test.go | 173 ++++++++++++++++++++++ pkg/remoting/getty/listener_test.go | 85 +++++++++++ 3 files changed, 415 insertions(+) create mode 100644 pkg/remoting/getty/getty_client_test.go create mode 100644 pkg/remoting/getty/getty_remoting_test.go create mode 100644 pkg/remoting/getty/listener_test.go diff --git a/pkg/remoting/getty/getty_client_test.go b/pkg/remoting/getty/getty_client_test.go new file mode 100644 index 000000000..dc3006add --- /dev/null +++ b/pkg/remoting/getty/getty_client_test.go @@ -0,0 +1,157 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package getty + +import ( + "fmt" + "github.com/agiledragon/gomonkey" + getty "github.com/apache/dubbo-getty" + "github.com/seata/seata-go/pkg/protocol/message" + "github.com/stretchr/testify/assert" + "reflect" + "testing" +) + +func TestGettyRemotingClient_SendSyncRequest(t *testing.T) { + respMsg := message.GlobalBeginResponse{ + AbstractTransactionResponse: message.AbstractTransactionResponse{ + AbstractResultMessage: message.AbstractResultMessage{ + ResultCode: message.ResultCodeSuccess, + }, + }, + } + mock := gomonkey.ApplyMethod(reflect.TypeOf(GetGettyRemotingInstance()), "SendSync", + func(_ *GettyRemoting, msg message.RpcMessage, s getty.Session, callback callbackMethod) (interface{}, + error) { + return respMsg, nil + }) + resp, err := GetGettyRemotingClient().SendSyncRequest("message") + assert.Empty(t, err) + assert.Equal(t, respMsg, resp.(message.GlobalBeginResponse)) + mock.Reset() +} + +func TestGettyRemotingClient_SendAsyncResponse(t *testing.T) { + mock := gomonkey.ApplyMethod(reflect.TypeOf(GetGettyRemotingInstance()), "SendASync", + func(_ *GettyRemoting, msg message.RpcMessage, s getty.Session, callback callbackMethod) error { + return nil + }) + err := GetGettyRemotingClient().SendAsyncResponse(1, "message") + assert.Empty(t, err) + mock.Reset() +} + +func TestGettyRemotingClient_SendAsyncRequest(t *testing.T) { + var tests = []struct { + name string + message interface{} + }{ + { + name: "HeartBeatMessage", + message: message.HeartBeatMessage{}, + }, + { + name: "not HeartBeatMessage", + message: "message", + }, + } + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + mock := gomonkey.ApplyMethod(reflect.TypeOf(GetGettyRemotingInstance()), "SendASync", + func(_ *GettyRemoting, msg message.RpcMessage, s getty.Session, callback callbackMethod) error { + return nil + }) + err := GetGettyRemotingClient().SendAsyncRequest(test.message) + assert.Empty(t, err) + mock.Reset() + }) + } +} + +func Test_syncCallback(t *testing.T) { + var tests = []struct { + name string + respMsg *message.MessageFuture + reqMsg message.RpcMessage + wantErr bool + }{ + { + name: "timeout", + respMsg: message.NewMessageFuture(message.RpcMessage{ + ID: 1, + }), + reqMsg: message.RpcMessage{ + ID: 2, + }, + wantErr: true, + }, + { + name: "Done", + respMsg: message.NewMessageFuture(message.RpcMessage{ + ID: 1, + }), + reqMsg: message.RpcMessage{ + ID: 2, + }, + wantErr: false, + }, + } + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + if test.wantErr { + response, err := GetGettyRemotingClient().syncCallback(test.reqMsg, test.respMsg) + assert.EqualError(t, err, fmt.Sprintf("wait response timeout, request: %#v", test.reqMsg)) + assert.Empty(t, response) + } else { + go func() { + test.respMsg.Done <- struct{}{} + }() + response, err := GetGettyRemotingClient().syncCallback(test.reqMsg, test.respMsg) + assert.Empty(t, err) + assert.Empty(t, response) + } + }) + } +} + +func Test_asyncCallback(t *testing.T) { + var tests = []struct { + name string + respMsg *message.MessageFuture + reqMsg message.RpcMessage + wantErr bool + }{ + { + name: "Done", + respMsg: message.NewMessageFuture(message.RpcMessage{ + ID: 1, + }), + reqMsg: message.RpcMessage{ + ID: 2, + }, + wantErr: false, + }, + } + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + response, err := GetGettyRemotingClient().asyncCallback(test.reqMsg, test.respMsg) + assert.Empty(t, err) + assert.Empty(t, response) + }) + } +} diff --git a/pkg/remoting/getty/getty_remoting_test.go b/pkg/remoting/getty/getty_remoting_test.go new file mode 100644 index 000000000..5b00b4561 --- /dev/null +++ b/pkg/remoting/getty/getty_remoting_test.go @@ -0,0 +1,173 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package getty + +import ( + _ "github.com/golang/mock/mockgen/model" + "github.com/seata/seata-go/pkg/protocol/message" + "github.com/stretchr/testify/assert" + "testing" +) + +func TestGettyRemoting_GetMessageFuture(t *testing.T) { + var tests = []struct { + name string + msgID int32 + messageFuture *message.MessageFuture + }{ + { + name: "futures is null", + msgID: 1, + messageFuture: nil, + }, + { + name: "futures not null", + msgID: 1, + messageFuture: &message.MessageFuture{ + ID: 1, + Err: nil, + Response: nil, + Done: nil, + }, + }, + } + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + if test.messageFuture != nil { + GetGettyRemotingInstance().futures.Store(test.msgID, test.messageFuture) + messageFuture := GetGettyRemotingInstance().GetMessageFuture(test.msgID) + assert.Equal(t, *test.messageFuture, *messageFuture) + } else { + messageFuture := GetGettyRemotingInstance().GetMessageFuture(test.msgID) + assert.Empty(t, messageFuture) + } + }) + } +} + +func TestGettyRemoting_RemoveMessageFuture(t *testing.T) { + var tests = []struct { + name string + msgID int32 + messageFuture *message.MessageFuture + }{ + { + name: "futures is null", + msgID: 1, + messageFuture: nil, + }, + { + name: "futures not null", + msgID: 1, + messageFuture: &message.MessageFuture{ + ID: 1, + Err: nil, + Response: nil, + Done: nil, + }, + }, + } + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + if test.messageFuture != nil { + GetGettyRemotingInstance().futures.Store(test.msgID, test.messageFuture) + messageFuture := GetGettyRemotingInstance().GetMessageFuture(test.msgID) + assert.NotEmpty(t, messageFuture) + GetGettyRemotingInstance().RemoveMessageFuture(test.msgID) + messageFuture = GetGettyRemotingInstance().GetMessageFuture(test.msgID) + assert.Empty(t, messageFuture) + } else { + GetGettyRemotingInstance().RemoveMessageFuture(test.msgID) + messageFuture := GetGettyRemotingInstance().GetMessageFuture(test.msgID) + assert.Empty(t, messageFuture) + } + }) + } +} + +func TestGettyRemoting_GetMergedMessage(t *testing.T) { + var tests = []struct { + name string + msgID int32 + mergedWarpMessage *message.MergedWarpMessage + }{ + { + name: "mergeMsgMap is null", + msgID: 1, + mergedWarpMessage: nil, + }, + { + name: "mergeMsgMap not null", + msgID: 1, + mergedWarpMessage: &message.MergedWarpMessage{ + Msgs: []message.MessageTypeAware{}, + MsgIds: []int32{1, 2}, + }, + }, + } + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + if test.mergedWarpMessage != nil { + GetGettyRemotingInstance().mergeMsgMap.Store(test.msgID, test.mergedWarpMessage) + mergedWarpMessage := GetGettyRemotingInstance().GetMergedMessage(test.msgID) + assert.Equal(t, *test.mergedWarpMessage, *mergedWarpMessage) + } else { + mergedWarpMessage := GetGettyRemotingInstance().GetMessageFuture(test.msgID) + assert.Empty(t, mergedWarpMessage) + } + }) + } +} + +func TestGettyRemoting_RemoveMergedMessageFuture(t *testing.T) { + var tests = []struct { + name string + msgID int32 + mergedWarpMessage *message.MergedWarpMessage + }{ + { + name: "mergeMsgMap is null", + msgID: 1, + mergedWarpMessage: nil, + }, + { + name: "mergeMsgMap not null", + msgID: 1, + mergedWarpMessage: &message.MergedWarpMessage{ + Msgs: []message.MessageTypeAware{}, + MsgIds: []int32{1, 2}, + }, + }, + } + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + if test.mergedWarpMessage != nil { + GetGettyRemotingInstance().mergeMsgMap.Store(test.msgID, test.mergedWarpMessage) + mergedWarpMessage := GetGettyRemotingInstance().GetMergedMessage(test.msgID) + assert.NotEmpty(t, mergedWarpMessage) + GetGettyRemotingInstance().RemoveMergedMessageFuture(test.msgID) + mergedWarpMessage = GetGettyRemotingInstance().GetMergedMessage(test.msgID) + assert.Empty(t, mergedWarpMessage) + } else { + GetGettyRemotingInstance().RemoveMergedMessageFuture(test.msgID) + mergedWarpMessage := GetGettyRemotingInstance().GetMergedMessage(test.msgID) + assert.Empty(t, mergedWarpMessage) + } + }) + } +} diff --git a/pkg/remoting/getty/listener_test.go b/pkg/remoting/getty/listener_test.go new file mode 100644 index 000000000..65f5a2685 --- /dev/null +++ b/pkg/remoting/getty/listener_test.go @@ -0,0 +1,85 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package getty + +import ( + "context" + "github.com/seata/seata-go/pkg/protocol/message" + "github.com/seata/seata-go/pkg/remoting/processor" + "github.com/stretchr/testify/assert" + "testing" +) + +func TestGettyClientHandler_OnMessage(t *testing.T) { + var tests = []struct { + name string + pkg interface{} + }{ + { + name: "RpcMessage", + pkg: message.RpcMessage{ + ID: 1, + Type: 0, + Codec: 0, + Compressor: 0, + HeadMap: nil, + Body: message.GlobalBeginRequest{ + Timeout: 3, + TransactionName: "test", + }, + }, + }, + { + name: "Other", + pkg: "pkg", + }, + } + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + GetGettyClientHandlerInstance().OnMessage(nil, test.pkg) + }) + } +} + +type mockProcessor struct { +} + +func (m mockProcessor) Process(ctx context.Context, rpcMessage message.RpcMessage) error { + return nil +} + +func TestGettyClientHandler_RegisterProcessor(t *testing.T) { + var tests = []struct { + name string + msgType message.MessageType + processor processor.RemotingProcessor + }{ + { + name: "", + msgType: message.MessageType_GlobalBegin, + processor: &mockProcessor{}, + }, + } + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + ins := GetGettyClientHandlerInstance() + ins.RegisterProcessor(test.msgType, test.processor) + assert.Equal(t, test.processor, ins.processorMap[test.msgType]) + }) + } +} From 09be9977c82172d0c940c6eb281ab089bcc586cf Mon Sep 17 00:00:00 2001 From: Bison <1251604436@qq.com> Date: Wed, 10 Aug 2022 10:37:26 +0800 Subject: [PATCH 2/7] test --- pkg/remoting/getty/getty_remoting_test.go | 25 ++----- pkg/remoting/getty/listener_test.go | 85 ----------------------- 2 files changed, 7 insertions(+), 103 deletions(-) delete mode 100644 pkg/remoting/getty/listener_test.go diff --git a/pkg/remoting/getty/getty_remoting_test.go b/pkg/remoting/getty/getty_remoting_test.go index 5b00b4561..492e5e09f 100644 --- a/pkg/remoting/getty/getty_remoting_test.go +++ b/pkg/remoting/getty/getty_remoting_test.go @@ -67,12 +67,7 @@ func TestGettyRemoting_RemoveMessageFuture(t *testing.T) { messageFuture *message.MessageFuture }{ { - name: "futures is null", - msgID: 1, - messageFuture: nil, - }, - { - name: "futures not null", + name: "test remove message future", msgID: 1, messageFuture: &message.MessageFuture{ ID: 1, @@ -84,18 +79,12 @@ func TestGettyRemoting_RemoveMessageFuture(t *testing.T) { } for _, test := range tests { t.Run(test.name, func(t *testing.T) { - if test.messageFuture != nil { - GetGettyRemotingInstance().futures.Store(test.msgID, test.messageFuture) - messageFuture := GetGettyRemotingInstance().GetMessageFuture(test.msgID) - assert.NotEmpty(t, messageFuture) - GetGettyRemotingInstance().RemoveMessageFuture(test.msgID) - messageFuture = GetGettyRemotingInstance().GetMessageFuture(test.msgID) - assert.Empty(t, messageFuture) - } else { - GetGettyRemotingInstance().RemoveMessageFuture(test.msgID) - messageFuture := GetGettyRemotingInstance().GetMessageFuture(test.msgID) - assert.Empty(t, messageFuture) - } + GetGettyRemotingInstance().futures.Store(test.msgID, test.messageFuture) + messageFuture := GetGettyRemotingInstance().GetMessageFuture(test.msgID) + assert.Equal(t, messageFuture, test.messageFuture) + GetGettyRemotingInstance().RemoveMessageFuture(test.msgID) + messageFuture = GetGettyRemotingInstance().GetMessageFuture(test.msgID) + assert.Empty(t, messageFuture) }) } } diff --git a/pkg/remoting/getty/listener_test.go b/pkg/remoting/getty/listener_test.go deleted file mode 100644 index 65f5a2685..000000000 --- a/pkg/remoting/getty/listener_test.go +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package getty - -import ( - "context" - "github.com/seata/seata-go/pkg/protocol/message" - "github.com/seata/seata-go/pkg/remoting/processor" - "github.com/stretchr/testify/assert" - "testing" -) - -func TestGettyClientHandler_OnMessage(t *testing.T) { - var tests = []struct { - name string - pkg interface{} - }{ - { - name: "RpcMessage", - pkg: message.RpcMessage{ - ID: 1, - Type: 0, - Codec: 0, - Compressor: 0, - HeadMap: nil, - Body: message.GlobalBeginRequest{ - Timeout: 3, - TransactionName: "test", - }, - }, - }, - { - name: "Other", - pkg: "pkg", - }, - } - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - GetGettyClientHandlerInstance().OnMessage(nil, test.pkg) - }) - } -} - -type mockProcessor struct { -} - -func (m mockProcessor) Process(ctx context.Context, rpcMessage message.RpcMessage) error { - return nil -} - -func TestGettyClientHandler_RegisterProcessor(t *testing.T) { - var tests = []struct { - name string - msgType message.MessageType - processor processor.RemotingProcessor - }{ - { - name: "", - msgType: message.MessageType_GlobalBegin, - processor: &mockProcessor{}, - }, - } - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - ins := GetGettyClientHandlerInstance() - ins.RegisterProcessor(test.msgType, test.processor) - assert.Equal(t, test.processor, ins.processorMap[test.msgType]) - }) - } -} From aa798faa8b83543ae54c2fd2f15291393c9be89f Mon Sep 17 00:00:00 2001 From: Bison <1251604436@qq.com> Date: Wed, 10 Aug 2022 10:42:23 +0800 Subject: [PATCH 3/7] test --- pkg/remoting/getty/getty_client_test.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/remoting/getty/getty_client_test.go b/pkg/remoting/getty/getty_client_test.go index dc3006add..16883412d 100644 --- a/pkg/remoting/getty/getty_client_test.go +++ b/pkg/remoting/getty/getty_client_test.go @@ -27,6 +27,7 @@ import ( "testing" ) +// TestGettyRemotingClient_SendSyncRequest unit test for SendSyncRequest function func TestGettyRemotingClient_SendSyncRequest(t *testing.T) { respMsg := message.GlobalBeginResponse{ AbstractTransactionResponse: message.AbstractTransactionResponse{ @@ -46,6 +47,7 @@ func TestGettyRemotingClient_SendSyncRequest(t *testing.T) { mock.Reset() } +// TestGettyRemotingClient_SendAsyncResponse unit test for SendAsyncResponse function func TestGettyRemotingClient_SendAsyncResponse(t *testing.T) { mock := gomonkey.ApplyMethod(reflect.TypeOf(GetGettyRemotingInstance()), "SendASync", func(_ *GettyRemoting, msg message.RpcMessage, s getty.Session, callback callbackMethod) error { @@ -56,6 +58,7 @@ func TestGettyRemotingClient_SendAsyncResponse(t *testing.T) { mock.Reset() } +// TestGettyRemotingClient_SendAsyncRequest unit test for SendAsyncRequest function func TestGettyRemotingClient_SendAsyncRequest(t *testing.T) { var tests = []struct { name string @@ -83,6 +86,7 @@ func TestGettyRemotingClient_SendAsyncRequest(t *testing.T) { } } +// Test_syncCallback unit test for syncCallback function func Test_syncCallback(t *testing.T) { var tests = []struct { name string @@ -129,6 +133,7 @@ func Test_syncCallback(t *testing.T) { } } +// Test_asyncCallback unit test for asyncCallback function func Test_asyncCallback(t *testing.T) { var tests = []struct { name string From 88fb5c3fedea388521bd9bab65fc4dccb1bd11d7 Mon Sep 17 00:00:00 2001 From: Bison <1251604436@qq.com> Date: Wed, 10 Aug 2022 11:13:48 +0800 Subject: [PATCH 4/7] style --- pkg/remoting/getty/getty_remoting_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/pkg/remoting/getty/getty_remoting_test.go b/pkg/remoting/getty/getty_remoting_test.go index 492e5e09f..2f29f6b92 100644 --- a/pkg/remoting/getty/getty_remoting_test.go +++ b/pkg/remoting/getty/getty_remoting_test.go @@ -18,7 +18,6 @@ package getty import ( - _ "github.com/golang/mock/mockgen/model" "github.com/seata/seata-go/pkg/protocol/message" "github.com/stretchr/testify/assert" "testing" From 2e940398cdae83ab90930c04ae0f45885c850592 Mon Sep 17 00:00:00 2001 From: Bison <1251604436@qq.com> Date: Wed, 10 Aug 2022 11:19:01 +0800 Subject: [PATCH 5/7] style go mod --- go.sum | 3 +++ 1 file changed, 3 insertions(+) diff --git a/go.sum b/go.sum index 636c9fa39..47bd82679 100644 --- a/go.sum +++ b/go.sum @@ -841,6 +841,7 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3 h1:0es+/5331RGQPcXlMfP+WrnIIS6dNnNRe0WB02W0F4M= golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -880,6 +881,8 @@ golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzB golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/net v0.0.0-20180530234432-1e491301e022/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= From fbc71fa9e3fce4a101afd274b548eb63c7055527 Mon Sep 17 00:00:00 2001 From: Bison <1251604436@qq.com> Date: Wed, 10 Aug 2022 12:49:55 +0800 Subject: [PATCH 6/7] style:format imports --- pkg/remoting/getty/getty_client_test.go | 5 +++-- pkg/remoting/getty/getty_remoting_test.go | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/pkg/remoting/getty/getty_client_test.go b/pkg/remoting/getty/getty_client_test.go index 16883412d..6cee78c43 100644 --- a/pkg/remoting/getty/getty_client_test.go +++ b/pkg/remoting/getty/getty_client_test.go @@ -19,12 +19,13 @@ package getty import ( "fmt" + "reflect" + "testing" + "github.com/agiledragon/gomonkey" getty "github.com/apache/dubbo-getty" "github.com/seata/seata-go/pkg/protocol/message" "github.com/stretchr/testify/assert" - "reflect" - "testing" ) // TestGettyRemotingClient_SendSyncRequest unit test for SendSyncRequest function diff --git a/pkg/remoting/getty/getty_remoting_test.go b/pkg/remoting/getty/getty_remoting_test.go index 2f29f6b92..d57ff38e4 100644 --- a/pkg/remoting/getty/getty_remoting_test.go +++ b/pkg/remoting/getty/getty_remoting_test.go @@ -18,9 +18,10 @@ package getty import ( + "testing" + "github.com/seata/seata-go/pkg/protocol/message" "github.com/stretchr/testify/assert" - "testing" ) func TestGettyRemoting_GetMessageFuture(t *testing.T) { From 92727996d71f27403f7b736bf9740b9d2f9d078b Mon Sep 17 00:00:00 2001 From: Bison <1251604436@qq.com> Date: Wed, 10 Aug 2022 14:13:05 +0800 Subject: [PATCH 7/7] style:Delete the useless gomonkey Reset method --- pkg/remoting/getty/getty_client_test.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/pkg/remoting/getty/getty_client_test.go b/pkg/remoting/getty/getty_client_test.go index 6cee78c43..5e9e62a16 100644 --- a/pkg/remoting/getty/getty_client_test.go +++ b/pkg/remoting/getty/getty_client_test.go @@ -37,7 +37,7 @@ func TestGettyRemotingClient_SendSyncRequest(t *testing.T) { }, }, } - mock := gomonkey.ApplyMethod(reflect.TypeOf(GetGettyRemotingInstance()), "SendSync", + gomonkey.ApplyMethod(reflect.TypeOf(GetGettyRemotingInstance()), "SendSync", func(_ *GettyRemoting, msg message.RpcMessage, s getty.Session, callback callbackMethod) (interface{}, error) { return respMsg, nil @@ -45,18 +45,16 @@ func TestGettyRemotingClient_SendSyncRequest(t *testing.T) { resp, err := GetGettyRemotingClient().SendSyncRequest("message") assert.Empty(t, err) assert.Equal(t, respMsg, resp.(message.GlobalBeginResponse)) - mock.Reset() } // TestGettyRemotingClient_SendAsyncResponse unit test for SendAsyncResponse function func TestGettyRemotingClient_SendAsyncResponse(t *testing.T) { - mock := gomonkey.ApplyMethod(reflect.TypeOf(GetGettyRemotingInstance()), "SendASync", + gomonkey.ApplyMethod(reflect.TypeOf(GetGettyRemotingInstance()), "SendASync", func(_ *GettyRemoting, msg message.RpcMessage, s getty.Session, callback callbackMethod) error { return nil }) err := GetGettyRemotingClient().SendAsyncResponse(1, "message") assert.Empty(t, err) - mock.Reset() } // TestGettyRemotingClient_SendAsyncRequest unit test for SendAsyncRequest function @@ -76,13 +74,12 @@ func TestGettyRemotingClient_SendAsyncRequest(t *testing.T) { } for _, test := range tests { t.Run(test.name, func(t *testing.T) { - mock := gomonkey.ApplyMethod(reflect.TypeOf(GetGettyRemotingInstance()), "SendASync", + gomonkey.ApplyMethod(reflect.TypeOf(GetGettyRemotingInstance()), "SendASync", func(_ *GettyRemoting, msg message.RpcMessage, s getty.Session, callback callbackMethod) error { return nil }) err := GetGettyRemotingClient().SendAsyncRequest(test.message) assert.Empty(t, err) - mock.Reset() }) } }