Skip to content

Commit

Permalink
Deflake TestDynamicWindowsDiscovery (#49140)
Browse files Browse the repository at this point in the history
Use a require.Eventually instead of a hard-coded 10ms sleep to
allow time for the dynamic resources to be picked up.

Fixes #49082
  • Loading branch information
zmb3 authored Nov 18, 2024
1 parent 5939163 commit 0674f27
Showing 1 changed file with 32 additions and 22 deletions.
54 changes: 32 additions & 22 deletions lib/srv/desktop/discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (

"github.com/go-ldap/ldap/v3"
"github.com/jonboulle/clockwork"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/gravitational/teleport/api/types"
Expand Down Expand Up @@ -268,37 +269,46 @@ func TestDynamicWindowsDiscovery(t *testing.T) {
_, err = dynamicWindowsClient.CreateDynamicWindowsDesktop(ctx, desktop)
require.NoError(t, err)

time.Sleep(10 * time.Millisecond)
require.EventuallyWithT(t, func(t *assert.CollectT) {
desktops, err := client.GetWindowsDesktops(ctx, types.WindowsDesktopFilter{})
if !assert.NoError(t, err) {
return
}
if !assert.Len(t, desktops, testCase.expected) {
return
}

desktops, err := client.GetWindowsDesktops(ctx, types.WindowsDesktopFilter{})
require.NoError(t, err)
require.Len(t, desktops, testCase.expected)
if testCase.expected > 0 {
require.Equal(t, desktop.GetName(), desktops[0].GetName())
require.Equal(t, desktop.GetAddr(), desktops[0].GetAddr())
}
if testCase.expected > 0 {
assert.Equal(t, desktop.GetName(), desktops[0].GetName())
assert.Equal(t, desktop.GetAddr(), desktops[0].GetAddr())
}
}, 5*time.Second, 50*time.Millisecond)

desktop.Spec.Addr = "addr2"
_, err = dynamicWindowsClient.UpsertDynamicWindowsDesktop(ctx, desktop)
require.NoError(t, err)

time.Sleep(10 * time.Millisecond)
desktops, err = client.GetWindowsDesktops(ctx, types.WindowsDesktopFilter{})
require.NoError(t, err)
require.Len(t, desktops, testCase.expected)
if testCase.expected > 0 {
require.Equal(t, desktop.GetName(), desktops[0].GetName())
require.Equal(t, desktop.GetAddr(), desktops[0].GetAddr())
}
require.EventuallyWithT(t, func(t *assert.CollectT) {
desktops, err := client.GetWindowsDesktops(ctx, types.WindowsDesktopFilter{})
if !assert.NoError(t, err) {
return
}
if !assert.Len(t, desktops, testCase.expected) {
return
}
if testCase.expected > 0 {
assert.Equal(t, desktop.GetName(), desktops[0].GetName())
assert.Equal(t, desktop.GetAddr(), desktops[0].GetAddr())
}
}, 5*time.Second, 50*time.Millisecond)

require.NoError(t, dynamicWindowsClient.DeleteDynamicWindowsDesktop(ctx, "test"))

time.Sleep(10 * time.Millisecond)

desktops, err = client.GetWindowsDesktops(ctx, types.WindowsDesktopFilter{})
require.NoError(t, err)
require.Empty(t, desktops)
require.EventuallyWithT(t, func(t *assert.CollectT) {
desktops, err := client.GetWindowsDesktops(ctx, types.WindowsDesktopFilter{})
assert.NoError(t, err)
assert.Empty(t, desktops)
}, 5*time.Second, 50*time.Millisecond)
})

}
}

0 comments on commit 0674f27

Please sign in to comment.