Skip to content

Commit 6478442

Browse files
committed
Fix flakiness with TestCreds
Modified the test to use the test logger provided by the floggingtest package rather than using flogging directly Change-Id: I6e2d7939df4622169867a42741f17a5565c1194b Signed-off-by: Gari Singh <gari.r.singh@gmail.com>
1 parent c858fee commit 6478442

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

core/comm/creds_test.go

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ SPDX-License-Identifier: Apache-2.0
77
package comm_test
88

99
import (
10-
"bytes"
1110
"crypto/tls"
1211
"crypto/x509"
1312
"fmt"
@@ -18,7 +17,7 @@ import (
1817

1918
"google.golang.org/grpc/credentials"
2019

21-
"github.com/hyperledger/fabric/common/flogging"
20+
"github.com/hyperledger/fabric/common/flogging/floggingtest"
2221
"github.com/hyperledger/fabric/core/comm"
2322
"github.com/stretchr/testify/assert"
2423
)
@@ -37,21 +36,16 @@ func TestCreds(t *testing.T) {
3736
}
3837
cert, err := tls.LoadX509KeyPair(
3938
filepath.Join("testdata", "certs", "Org1-server1-cert.pem"),
40-
filepath.Join("testdata", "certs", "Org1-server1-key.pem"))
39+
filepath.Join("testdata", "certs", "Org1-server1-key.pem"),
40+
)
4141
if err != nil {
4242
t.Fatalf("failed to load TLS certificate [%s]", err)
4343
}
4444
tlsConfig := &tls.Config{
4545
Certificates: []tls.Certificate{cert}}
4646

47-
buf := &bytes.Buffer{}
48-
conf := flogging.Config{
49-
Writer: buf}
50-
logging, err := flogging.New(conf)
51-
if err != nil {
52-
t.Fatalf("error creating logger [%s]", err)
53-
}
54-
logger := logging.Logger("creds")
47+
logger, recorder := floggingtest.NewTestLogger(t)
48+
5549
var creds credentials.TransportCredentials
5650
creds = comm.NewServerTransportCredentials(tlsConfig, logger)
5751
_, _, err = creds.ClientHandshake(nil, "", nil)
@@ -101,6 +95,6 @@ func TestCreds(t *testing.T) {
10195
RootCAs: certPool,
10296
MaxVersion: tls.VersionTLS10})
10397
assert.Contains(t, err.Error(), "protocol version not supported")
104-
assert.Contains(t, buf.String(), "TLS handshake failed with error")
98+
assert.Contains(t, recorder.Messages()[0], "TLS handshake failed with error")
10599

106100
}

0 commit comments

Comments
 (0)