Skip to content

Commit

Permalink
add flay test fixes from #9516
Browse files Browse the repository at this point in the history
  • Loading branch information
rosstimothy committed Jan 11, 2022
1 parent 0ccd8f6 commit 24e73bf
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 11 deletions.
5 changes: 4 additions & 1 deletion lib/cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1820,8 +1820,11 @@ func TestCache_Backoff(t *testing.T) {
require.GreaterOrEqual(t, duration, stepMin)
require.LessOrEqual(t, duration, stepMax)

// wait for cache to get to retry.After
clock.BlockUntil(1)

// add some extra to the duration to ensure the retry occurs
clock.Advance(duration * 3)
clock.Advance(p.cache.MaxRetryPeriod)
case <-time.After(time.Minute):
t.Fatalf("timeout waiting for event")
}
Expand Down
6 changes: 5 additions & 1 deletion lib/service/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ type Config struct {

// MaxRetryPeriod is the maximum period between reconnection attempts to auth
MaxRetryPeriod time.Duration

// ConnectFailureC is a channel to notify of failures to connect to auth (used in tests).
ConnectFailureC chan time.Duration
}

// ApplyToken assigns a given token to all internal services but only if token
Expand Down Expand Up @@ -292,7 +295,7 @@ type ProxyConfig struct {
// Enabled turns proxy role on or off for this process
Enabled bool

//DisableTLS is enabled if we don't want self-signed certs
// DisableTLS is enabled if we don't want self-signed certs
DisableTLS bool

// DisableWebInterface allows to turn off serving the Web UI interface
Expand Down Expand Up @@ -853,6 +856,7 @@ func ApplyDefaults(cfg *Config) {
cfg.Databases.Enabled = false

cfg.MaxRetryPeriod = defaults.MaxWatcherBackoff
cfg.ConnectFailureC = make(chan time.Duration, 1)
}

// ApplyFIPSDefaults updates default configuration to be FedRAMP/FIPS 140-2
Expand Down
2 changes: 1 addition & 1 deletion lib/service/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (process *TeleportProcess) reconnectToAuthService(role teleport.Role) (*Con

// Used for testing that auth service will attempt to reconnect in the provided duration.
select {
case process.connectFailureC <- retry.Duration():
case process.Config.ConnectFailureC <- retry.Duration():
default:
}

Expand Down
4 changes: 0 additions & 4 deletions lib/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,6 @@ type TeleportProcess struct {

// clusterFeatures contain flags for supported and unsupported features.
clusterFeatures proto.Features

// connectFailureC is a channel to notify of failures to connect to auth (used in tests).
connectFailureC chan time.Duration
}

type keyPairKey struct {
Expand Down Expand Up @@ -671,7 +668,6 @@ func NewTeleport(cfg *Config) (*TeleportProcess, error) {
id: processID,
keyPairs: make(map[keyPairKey]KeyPair),
appDependCh: make(chan Event, 1024),
connectFailureC: make(chan time.Duration),
}

process.registerAppDepend()
Expand Down
10 changes: 8 additions & 2 deletions lib/service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,8 @@ func TestTeleportProcess_reconnectToAuth(t *testing.T) {
cfg.Auth.Enabled = false
cfg.Proxy.Enabled = false
cfg.SSH.Enabled = true
cfg.MaxRetryPeriod = defaults.MaxWatcherBackoff
cfg.ConnectFailureC = make(chan time.Duration, 5)
process, err := NewTeleport(cfg)
require.NoError(t, err)

Expand All @@ -478,14 +480,18 @@ func TestTeleportProcess_reconnectToAuth(t *testing.T) {
for i := 0; i < 5; i++ {
// wait for connection to fail
select {
case duration := <-process.connectFailureC:
case duration := <-process.Config.ConnectFailureC:
stepMin := step * time.Duration(i) / 2
stepMax := step * time.Duration(i+1)

require.GreaterOrEqual(t, duration, stepMin)
require.LessOrEqual(t, duration, stepMax)

// wait for connection to get to retry.After
clock.BlockUntil(1)

// add some extra to the duration to ensure the retry occurs
clock.Advance(duration * 3)
clock.Advance(cfg.MaxRetryPeriod)
case <-time.After(time.Minute):
t.Fatalf("timeout waiting for failure")
}
Expand Down
8 changes: 6 additions & 2 deletions lib/services/proxywatcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestProxyWatcher_Backoff(t *testing.T) {
Clock: clock,
MaxRetryPeriod: defaults.MaxWatcherBackoff,
Client: &errorWatcher{},
ProxiesC: make(chan []types.Server, 1),
ProxiesC: make(chan []types.Server, 5),
})
require.NoError(t, err)
t.Cleanup(func() { require.NoError(t, w.Close()) })
Expand All @@ -68,8 +68,12 @@ func TestProxyWatcher_Backoff(t *testing.T) {

require.GreaterOrEqual(t, duration, stepMin)
require.LessOrEqual(t, duration, stepMax)

// wait for watcher to get to retry.After
clock.BlockUntil(1)

// add some extra to the duration to ensure the retry occurs
clock.Advance(duration * 3)
clock.Advance(w.MaxRetryPeriod)
case <-time.After(time.Minute):
t.Fatalf("timeout waiting for reset")
}
Expand Down

0 comments on commit 24e73bf

Please sign in to comment.