Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor p2p unit tests #425

Merged
merged 12 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.20

require (
github.com/VictoriaMetrics/fastcache v1.10.0
github.com/ava-labs/avalanchego v1.10.18-rc.0
github.com/ava-labs/avalanchego v1.10.18-0.20231212215606-cb0f72d18f35
github.com/cespare/cp v0.1.0
github.com/cockroachdb/pebble v0.0.0-20230209160836-829675f94811
github.com/davecgh/go-spew v1.1.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156 h1:eMwmnE/GDgah
github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/ava-labs/avalanchego v1.10.18-rc.0 h1:8tsu5qB/Fp5NFZuJQR48q6wMHGJxGfzvlGxvxdnjg6o=
github.com/ava-labs/avalanchego v1.10.18-rc.0/go.mod h1:ZbZteX1xINA3U31/akSGO/ZrcVAA7V6tDle0ENJ3DPI=
github.com/ava-labs/avalanchego v1.10.18-0.20231212215606-cb0f72d18f35 h1:arKzZnblbQiFWUZ9QDiVxLtDQkkgCiXJknw09NYOaJk=
github.com/ava-labs/avalanchego v1.10.18-0.20231212215606-cb0f72d18f35/go.mod h1:Nipo+jZEKDO8DgE5Z2IytDeplsT61DzvYQHhZoBqCG4=
github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
Expand Down
6 changes: 3 additions & 3 deletions peer/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ func (n *network) CrossChainAppRequest(ctx context.Context, requestingChainID id
// - request times out before a response is provided
// If [requestID] is not known, this function will emit a log and return a nil error.
// If the response handler returns an error it is propagated as a fatal error.
func (n *network) CrossChainAppRequestFailed(ctx context.Context, respondingChainID ids.ID, requestID uint32) error {
func (n *network) CrossChainAppRequestFailed(ctx context.Context, respondingChainID ids.ID, requestID uint32, _ *common.AppError) error {
log.Debug("received CrossChainAppRequestFailed from chain", "respondingChainID", respondingChainID, "requestID", requestID)

handler, exists := n.markRequestFulfilled(requestID)
Expand Down Expand Up @@ -382,13 +382,13 @@ func (n *network) AppResponse(ctx context.Context, nodeID ids.NodeID, requestID
// - request times out before a response is provided
// error returned by this function is expected to be treated as fatal by the engine
// returns error only when the response handler returns an error
func (n *network) AppRequestFailed(ctx context.Context, nodeID ids.NodeID, requestID uint32) error {
func (n *network) AppRequestFailed(ctx context.Context, nodeID ids.NodeID, requestID uint32, appErr *common.AppError) error {
log.Debug("received AppRequestFailed from peer", "nodeID", nodeID, "requestID", requestID)

handler, exists := n.markRequestFulfilled(requestID)
if !exists {
log.Debug("forwarding AppRequestFailed to SDK network", "nodeID", nodeID, "requestID", requestID)
return n.network.AppRequestFailed(ctx, nodeID, requestID)
return n.network.AppRequestFailed(ctx, nodeID, requestID, appErr)
}

// We must release the slot
Expand Down
13 changes: 3 additions & 10 deletions peer/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ func TestRequestMinVersion(t *testing.T) {
responseBytes, _, err := client.SendAppRequestAny(
context.Background(),
&version.Application{
Name: "avalanche",
joshua-kim marked this conversation as resolved.
Show resolved Hide resolved
Major: 2,
Minor: 0,
Patch: 0,
Expand Down Expand Up @@ -814,17 +815,9 @@ func TestNetworkCrossChainAppRequestAfterShutdown(t *testing.T) {

func TestNetworkRouting(t *testing.T) {
require := require.New(t)
sender := &testAppSender{
sendAppRequestFn: func(_ context.Context, s set.Set[ids.NodeID], u uint32, bytes []byte) error {
return nil
},
sendAppResponseFn: func(id ids.NodeID, u uint32, bytes []byte) error {
return nil
},
}
protocol := 0
handler := &testSDKHandler{}
p2pNetwork := p2p.NewNetwork(logging.NoLog{}, sender, prometheus.NewRegistry(), "")
p2pNetwork := p2p.NewNetwork(logging.NoLog{}, &common.FakeSender{}, prometheus.NewRegistry(), "")
_, err := p2pNetwork.NewAppProtocol(uint64(protocol), handler)
require.NoError(err)

Expand All @@ -850,7 +843,7 @@ func TestNetworkRouting(t *testing.T) {
err = network.AppResponse(context.Background(), ids.GenerateTestNodeID(), 0, foobar)
require.ErrorIs(err, p2p.ErrUnrequestedResponse)

err = network.AppRequestFailed(context.Background(), nodeID, 0)
err = network.AppRequestFailed(context.Background(), nodeID, 0, common.ErrTimeout)
require.ErrorIs(err, p2p.ErrUnrequestedResponse)
}

Expand Down
2 changes: 1 addition & 1 deletion plugin/evm/syncervm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func TestStateSyncToggleEnabledToDisabled(t *testing.T) {
reqCount++
// Fail all requests after number 50 to interrupt the sync
if reqCount > 50 {
if err := syncerVM.AppRequestFailed(context.Background(), nodeID, requestID); err != nil {
if err := syncerVM.AppRequestFailed(context.Background(), nodeID, requestID, commonEng.ErrTimeout); err != nil {
panic(err)
}
cancel := syncerVM.StateSyncClient.(*stateSyncerClient).cancel
Expand Down
Loading
Loading