From 31323ba0e97432d0a7aefaefb069eee2f55bb423 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Mon, 4 May 2020 18:19:55 -0500 Subject: [PATCH] connmgr: Shore up TestMaxRetryDuration. This modifies TestmaxRetryDuration to assert the configured max retry duration is the expected value since the test relies on that and also switches to using a time.After for testing the timeout condition to ensure proper behavior regardless of the presence of a context timeout. --- connmgr/connmanager_test.go | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/connmgr/connmanager_test.go b/connmgr/connmanager_test.go index a8a8f019..cf87bf82 100644 --- a/connmgr/connmanager_test.go +++ b/connmgr/connmanager_test.go @@ -385,6 +385,13 @@ func TestRetryPermanent(t *testing.T) { // We have a timed dialer which initially returns err but after RetryDuration // hits maxRetryDuration returns a mock conn. func TestMaxRetryDuration(t *testing.T) { + // This test relies on the current value of the max retry duration defined + // in the tests, so assert it. + if maxRetryDuration != 2*time.Millisecond { + t.Fatalf("max retry duration of %v is not the required value for test", + maxRetryDuration) + } + networkUp := make(chan struct{}) time.AfterFunc(5*time.Millisecond, func() { close(networkUp) @@ -410,6 +417,7 @@ func TestMaxRetryDuration(t *testing.T) { if err != nil { t.Fatalf("New error: %v", err) } + cmgr.Start() cr := &ConnReq{ Addr: &net.TCPAddr{ @@ -418,21 +426,14 @@ func TestMaxRetryDuration(t *testing.T) { }, Permanent: true, } - ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond) - defer cancel() - go cmgr.Connect(ctx, cr) - cmgr.Start() + go cmgr.Connect(context.Background(), cr) // retry in 1ms // retry in 2ms - max retry duration reached // retry in 2ms - timedDialer returns mockDial -out: - for { - select { - case <-connected: - break out - case <-ctx.Done(): - t.Fatalf("max retry duration: connection timeout") - } + select { + case <-connected: + case <-time.After(20 * time.Millisecond): + t.Fatalf("max retry duration: connection timeout") } // Ensure clean shutdown of connection manager.