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.
This commit is contained in:
parent
be9d4854ad
commit
31323ba0e9
@ -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.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user