Skip to content

Commit 791330d

Browse files
committed
[FAB-9103] Improve test time for comm pkg
Upgrading the grpc-go pkg increased the overall test time from ~6sec to ~30s. With a few tweaks the total time is now ~11s Change-Id: I37a62d7dba36b44e20f56117c2a943090f7a874a Signed-off-by: Gari Singh <gari.r.singh@gmail.com>
1 parent 32ece67 commit 791330d

File tree

3 files changed

+20
-19
lines changed

3 files changed

+20
-19
lines changed

core/comm/client_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626

2727
var caPEM, certPEM, keyPEM, serverKey, serverPEM []byte
2828
var testClientCert, testServerCert tls.Certificate
29-
var testTimeout = 10 * time.Second // conservative
29+
var testTimeout = 1 * time.Second // conservative
3030

3131
type echoServer struct{}
3232

core/comm/connection_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ func TestClientConnections(t *testing.T) {
137137

138138
// utility function to load up our test root certificates from testdata/certs
139139
func loadRootCAs() [][]byte {
140-
141140
rootCAs := [][]byte{}
142141
for i := 1; i <= numOrgs; i++ {
143142
root, err := ioutil.ReadFile(fmt.Sprintf(orgCACert, i))
@@ -157,7 +156,7 @@ func loadRootCAs() [][]byte {
157156
}
158157

159158
func TestCASupport(t *testing.T) {
160-
159+
t.Parallel()
161160
rootCAs := loadRootCAs()
162161
t.Logf("loaded %d root certificates", len(rootCAs))
163162
if len(rootCAs) != 6 {
@@ -190,7 +189,7 @@ func TestCASupport(t *testing.T) {
190189
}
191190

192191
func TestCredentialSupport(t *testing.T) {
193-
192+
t.Parallel()
194193
rootCAs := loadRootCAs()
195194
t.Logf("loaded %d root certificates", len(rootCAs))
196195
if len(rootCAs) != 6 {
@@ -303,6 +302,7 @@ func newServer(org string, port int) *srv {
303302
}
304303

305304
func TestImpersonation(t *testing.T) {
305+
t.Parallel()
306306
// Scenario: We have 2 organizations: orgA, orgB
307307
// and each of them are in their respected channels- A, B.
308308
// The test would obtain credentials.TransportCredentials by calling GetDeliverServiceCredentials.

core/comm/server_test.go

+16-15
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,6 @@ func (tss *testServiceServer) EmptyCall(context.Context, *testpb.Empty) (*testpb
109109

110110
//invoke the EmptyCall RPC
111111
func invokeEmptyCall(address string, dialOptions []grpc.DialOption) (*testpb.Empty, error) {
112-
113-
//add DialOptions
114-
dialOptions = append(
115-
dialOptions,
116-
grpc.WithDefaultCallOptions(grpc.FailFast(true)),
117-
grpc.FailOnNonTempDialError(true),
118-
grpc.WithBlock())
119112
ctx := context.Background()
120113
ctx, _ = context.WithTimeout(ctx, timeout)
121114
//create GRPC client conn
@@ -650,7 +643,8 @@ func TestNewSecureGRPCServer(t *testing.T) {
650643
RootCAs: certPool,
651644
MinVersion: tlsVersion,
652645
MaxVersion: tlsVersion,
653-
}))})
646+
})),
647+
grpc.WithBlock()})
654648
t.Logf("TLSVersion [%d] failed with [%s]", tlsVersion, err)
655649
assert.Error(t, err, "Should not have been able to connect with TLS version < 1.2")
656650
assert.Contains(t, err.Error(), "context deadline exceeded")
@@ -1386,8 +1380,8 @@ func TestKeepaliveNoClientResponse(t *testing.T) {
13861380
t.Parallel()
13871381
// set up GRPCServer instance
13881382
kap := &comm.KeepaliveOptions{
1389-
ServerInterval: time.Duration(2) * time.Second,
1390-
ServerTimeout: time.Duration(1) * time.Second,
1383+
ServerInterval: 2 * time.Second,
1384+
ServerTimeout: 1 * time.Second,
13911385
}
13921386
testAddress := "localhost:9400"
13931387
srv, err := comm.NewGRPCServer(testAddress, comm.ServerConfig{KaOpts: kap})
@@ -1417,8 +1411,8 @@ func TestKeepaliveClientResponse(t *testing.T) {
14171411
t.Parallel()
14181412
// set up GRPCServer instance
14191413
kap := &comm.KeepaliveOptions{
1420-
ServerInterval: time.Duration(2) * time.Second,
1421-
ServerTimeout: time.Duration(1) * time.Second,
1414+
ServerInterval: 1 * time.Second,
1415+
ServerTimeout: 1 * time.Second,
14221416
}
14231417
testAddress := "localhost:9401"
14241418
srv, err := comm.NewGRPCServer(testAddress, comm.ServerConfig{KaOpts: kap})
@@ -1427,16 +1421,22 @@ func TestKeepaliveClientResponse(t *testing.T) {
14271421
defer srv.Stop()
14281422

14291423
// test that connection does not close with response to ping
1430-
clientTransport, err := transport.NewClientTransport(
1424+
connectCtx, cancel := context.WithDeadline(
14311425
context.Background(),
1426+
time.Now().Add(1*time.Second))
1427+
clientTransport, err := transport.NewClientTransport(
1428+
connectCtx,
14321429
context.Background(),
14331430
transport.TargetInfo{Addr: testAddress},
14341431
transport.ConnectOptions{},
14351432
func() {})
1433+
if err != nil {
1434+
cancel()
1435+
}
14361436
assert.NoError(t, err, "Unexpected error creating client transport")
14371437
defer clientTransport.Close()
14381438
// sleep past keepalive timeout
1439-
time.Sleep(4 * time.Second)
1439+
time.Sleep(1500 * time.Millisecond)
14401440
// try to create a stream
14411441
_, err = clientTransport.NewStream(context.Background(), &transport.CallHdr{})
14421442
assert.NoError(t, err, "Unexpected error creating stream")
@@ -1480,7 +1480,8 @@ func TestUpdateTLSCert(t *testing.T) {
14801480
_, err = invokeEmptyCall("localhost:8333",
14811481
[]grpc.DialOption{grpc.WithTransportCredentials(
14821482
credentials.NewTLS(&tls.Config{
1483-
RootCAs: certPool}))})
1483+
RootCAs: certPool})),
1484+
grpc.WithBlock()})
14841485
return err
14851486
}
14861487

0 commit comments

Comments
 (0)