Skip to content

Commit

Permalink
Log proposal response differences (backport #3420)
Browse files Browse the repository at this point in the history
Cherry-pick of #3420

Signed-off-by: andrew-coleman <[email protected]>
  • Loading branch information
andrew-coleman authored and denyeart committed May 23, 2022
1 parent 4c6ef91 commit 29fea4f
Show file tree
Hide file tree
Showing 4 changed files with 999 additions and 0 deletions.
33 changes: 33 additions & 0 deletions internal/pkg/gateway/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"context"
"fmt"
"io"
"strings"
"testing"
"time"

Expand All @@ -23,6 +24,8 @@ import (
ab "github.com/hyperledger/fabric-protos-go/orderer"
"github.com/hyperledger/fabric-protos-go/peer"
"github.com/hyperledger/fabric/common/crypto/tlsgen"
"github.com/hyperledger/fabric/common/flogging"
"github.com/hyperledger/fabric/common/flogging/mock"
commonledger "github.com/hyperledger/fabric/common/ledger"
"github.com/hyperledger/fabric/gossip/api"
"github.com/hyperledger/fabric/gossip/common"
Expand All @@ -36,6 +39,7 @@ import (
"github.com/pkg/errors"
"github.com/spf13/viper"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zapcore"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
Expand Down Expand Up @@ -167,6 +171,8 @@ type preparedTest struct {
ledgerProvider *mocks.LedgerProvider
ledger *mocks.Ledger
blockIterator *mocks.ResultsIterator
logLevel string
logFields []string
}

type contextKey string
Expand Down Expand Up @@ -770,6 +776,26 @@ func TestEndorse(t *testing.T) {
Message: "ProposalResponsePayloads do not match",
},
},
postSetup: func(t *testing.T, def *preparedTest) {
def.logLevel = flogging.LoggerLevel("gateway")
flogging.ActivateSpec("debug")
logObserver := &mock.Observer{}
logObserver.WriteEntryStub = func(entry zapcore.Entry, fields []zapcore.Field) {
if strings.HasPrefix(entry.Message, "Proposal response mismatch") {
for _, field := range fields {
def.logFields = append(def.logFields, field.String)
}
}
}
flogging.SetObserver(logObserver)
},
postTest: func(t *testing.T, def *preparedTest) {
require.Equal(t, "chaincode response mismatch", def.logFields[0])
require.Equal(t, "status: 200, message: , payload: different_response", def.logFields[1])
require.Equal(t, "status: 200, message: , payload: mock_response", def.logFields[2])
flogging.ActivateSpec(def.logLevel)
flogging.SetObserver(nil)
},
},
{
name: "discovery fails",
Expand Down Expand Up @@ -963,6 +989,9 @@ func TestEndorse(t *testing.T) {

if checkError(t, &tt, err) {
require.Nil(t, response, "response on error")
if tt.postTest != nil {
tt.postTest(t, test)
}
return
}

Expand All @@ -979,6 +1008,10 @@ func TestEndorse(t *testing.T) {

// check the correct endorsers (mocks) were called with the right parameters
checkEndorsers(t, tt.expectedEndorsers, test)

if tt.postTest != nil {
tt.postTest(t, test)
}
})
}
}
Expand Down
Loading

0 comments on commit 29fea4f

Please sign in to comment.