Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to Fix Flaky Test #27939

Merged
merged 1 commit into from
Aug 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 42 additions & 5 deletions integration/helpers/ports.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func WebReverseTunnelMuxPortSetup(t *testing.T, fds *[]servicecfg.FileDescriptor
}
}

// WebReverseTunnelMuxPortSetup generates a listener config with a defined port for Postgres
// SeparatePostgresPortSetup generates a listener config with a defined port for Postgres
func SeparatePostgresPortSetup(t *testing.T, fds *[]servicecfg.FileDescriptor) *InstanceListeners {
return &InstanceListeners{
Web: NewListener(t, service.ListenerProxyWeb, fds),
Expand All @@ -120,7 +120,7 @@ func SeparatePostgresPortSetup(t *testing.T, fds *[]servicecfg.FileDescriptor) *
}
}

// WebReverseTunnelMuxPortSetup generates a listener config with a defined port for MongoDB
// SeparateMongoPortSetup generates a listener config with a defined port for MongoDB
func SeparateMongoPortSetup(t *testing.T, fds *[]servicecfg.FileDescriptor) *InstanceListeners {
return &InstanceListeners{
Web: NewListener(t, service.ListenerProxyWeb, fds),
Expand All @@ -133,7 +133,7 @@ func SeparateMongoPortSetup(t *testing.T, fds *[]servicecfg.FileDescriptor) *Ins
}
}

// WebReverseTunnelMuxPortSetup generates a listener config with a defined port for Postgres and Mongo
// SeparateMongoAndPostgresPortSetup generates a listener config with a defined port for Postgres and Mongo
func SeparateMongoAndPostgresPortSetup(t *testing.T, fds *[]servicecfg.FileDescriptor) *InstanceListeners {
return &InstanceListeners{
Web: NewListener(t, service.ListenerProxyWeb, fds),
Expand All @@ -159,7 +159,7 @@ func PortStr(t *testing.T, addr string) string {
return portStr
}

// PortStr extracts the port number from the supplied string, which is assumed
// Port extracts the port number from the supplied string, which is assumed
// to be a host:port pair. The port value is returned as an integer. Any errors
// result in an immediately failed test.
func Port(t *testing.T, addr string) int {
Expand All @@ -172,7 +172,7 @@ func Port(t *testing.T, addr string) int {
return port
}

// NewListener creates a new TCP listener on `hostAddr`:0, adds it to the
// NewListenerOn creates a new TCP listener on `hostAddr`:0, adds it to the
// FileDescriptor slice (with the specified type) and returns its actual local
// address as a string (for use in configuration). The idea is to subvert
// Teleport's file-descriptor injection mechanism (used to share ports between
Expand Down Expand Up @@ -224,3 +224,40 @@ func NewListenerOn(t *testing.T, hostAddr string, ty service.ListenerType, fds *
func NewListener(t *testing.T, ty service.ListenerType, fds *[]servicecfg.FileDescriptor) string {
return NewListenerOn(t, Loopback, ty, fds)
}

// DynamicServiceAddr collects listeners addresses and sockets descriptors allowing to create and network listeners
// and pass the file descriptors to teleport service.
// This is usefully when Teleport service is created from config file where a port is allocated by OS.
type DynamicServiceAddr struct {
// Descriptors ia a list of descriptors associated with listens.
Descriptors []servicecfg.FileDescriptor
// WebAddr is a Teleport Proxy Web Address.
WebAddr string
// TunnelAddr is a Teleport Proxy Tunnel Address.
TunnelAddr string
// AuthAddr is a Teleport Auth Address.
AuthAddr string
// TunnelAddr is a Teleport Proxy SSH Address
ProxySSHAddr string
// TunnelAddr is a Teleport node SSH Address.
NodeSSHAddr string
}

// NewDynamicServiceAddr creates an instance of DynamicServiceAddr.
func NewDynamicServiceAddr(t *testing.T) *DynamicServiceAddr {
var fds []servicecfg.FileDescriptor
webAddr := NewListener(t, service.ListenerProxyWeb, &fds)
tunnelAddr := NewListener(t, service.ListenerProxyTunnel, &fds)
authAddr := NewListener(t, service.ListenerAuth, &fds)
proxySSHAddr := NewListener(t, service.ListenerProxySSH, &fds)
nodeSSHAddr := NewListener(t, service.ListenerNodeSSH, &fds)

return &DynamicServiceAddr{
Descriptors: fds,
WebAddr: webAddr,
TunnelAddr: tunnelAddr,
AuthAddr: authAddr,
ProxySSHAddr: proxySSHAddr,
NodeSSHAddr: nodeSSHAddr,
}
}
5 changes: 4 additions & 1 deletion lib/web/apiserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7563,7 +7563,10 @@ func newWebPack(t *testing.T, numProxies int, opts ...proxyOption) *webPack {
require.NoError(t, err)

require.NoError(t, node.Start())
t.Cleanup(func() { require.NoError(t, node.Close()) })
t.Cleanup(func() {
require.NoError(t, node.Close())
node.Wait()
})

var proxies []*testProxy
for p := 0; p < numProxies; p++ {
Expand Down
25 changes: 0 additions & 25 deletions tool/tctl/common/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import (

"github.com/gravitational/teleport/api/breaker"
apidefaults "github.com/gravitational/teleport/api/defaults"
"github.com/gravitational/teleport/integration/helpers"
"github.com/gravitational/teleport/lib/auth"
"github.com/gravitational/teleport/lib/auth/authclient"
"github.com/gravitational/teleport/lib/cloud"
Expand Down Expand Up @@ -294,27 +293,3 @@ func waitForDatabases(t *testing.T, auth *service.TeleportProcess, dbs []service
}
}
}

func newDynamicServiceAddr(t *testing.T) *dynamicServiceAddr {
var fds []servicecfg.FileDescriptor
webAddr := helpers.NewListener(t, service.ListenerProxyWeb, &fds)
tunnelAddr := helpers.NewListener(t, service.ListenerProxyTunnel, &fds)
authAddr := helpers.NewListener(t, service.ListenerAuth, &fds)

return &dynamicServiceAddr{
descriptors: fds,
webAddr: webAddr,
tunnelAddr: tunnelAddr,
authAddr: authAddr,
}
}

// dynamicServiceAddr collects listeners addresses and sockets descriptors allowing to create and network listeners
// and pass the file descriptors to teleport service.
// This is usefully when Teleport service is created from config file where a port is allocated by OS.
type dynamicServiceAddr struct {
webAddr string
tunnelAddr string
authAddr string
descriptors []servicecfg.FileDescriptor
}
11 changes: 6 additions & 5 deletions tool/tctl/common/lock_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ import (
"github.com/stretchr/testify/require"

"github.com/gravitational/teleport/api/types"
"github.com/gravitational/teleport/integration/helpers"
"github.com/gravitational/teleport/lib/config"
)

func TestLocks(t *testing.T) {
dynAddr := newDynamicServiceAddr(t)
dynAddr := helpers.NewDynamicServiceAddr(t)
fileConfig := &config.FileConfig{
Global: config.Global{
DataDir: t.TempDir(),
Expand All @@ -39,20 +40,20 @@ func TestLocks(t *testing.T) {
Service: config.Service{
EnabledFlag: "true",
},
WebAddr: dynAddr.webAddr,
TunAddr: dynAddr.tunnelAddr,
WebAddr: dynAddr.WebAddr,
TunAddr: dynAddr.TunnelAddr,
},
Auth: config.Auth{
Service: config.Service{
EnabledFlag: "true",
ListenAddress: dynAddr.authAddr,
ListenAddress: dynAddr.AuthAddr,
},
},
}

timeNow := time.Now().UTC()
fakeClock := clockwork.NewFakeClockAt(timeNow)
makeAndRunTestAuthServer(t, withFileConfig(fileConfig), withFileDescriptors(dynAddr.descriptors), withFakeClock(fakeClock))
makeAndRunTestAuthServer(t, withFileConfig(fileConfig), withFileDescriptors(dynAddr.Descriptors), withFakeClock(fakeClock))

t.Run("create", func(t *testing.T) {
err := runLockCommand(t, fileConfig, []string{"--user=bad@actor", "--message=Come see me"})
Expand Down
Loading