Skip to content

Commit

Permalink
Fix flaky test TestTSHConfigConnectWithOpenSSHClient (#35861)
Browse files Browse the repository at this point in the history
* Add retry to event check in TestTSHConfigConnectWithOpenSSHClient.

* Resolve comments.

* Restore nodelogin assertion.
  • Loading branch information
Joerger authored Dec 23, 2023
1 parent 6c9bf5e commit 781c870
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions tool/tsh/common/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1086,28 +1086,25 @@ func mustFailToRunOpenSSHCommand(t *testing.T, configFile string, sshConnString
require.Error(t, err)
}

func mustSearchEvents(t *testing.T, auth *auth.Server) []apievents.AuditEvent {
now := time.Now()
ctx := context.Background()
events, _, err := auth.SearchEvents(ctx, events.SearchEventsRequest{
From: now.Add(-time.Hour),
To: now.Add(time.Hour),
Order: types.EventOrderDescending,
})

require.NoError(t, err)
return events
}

func mustFindFailedNodeLoginAttempt(t *testing.T, s *suite, nodeLogin string) {
av := mustSearchEvents(t, s.root.GetAuthServer())
for _, e := range av {
if e.GetCode() == events.AuthAttemptFailureCode {
require.Equal(t, e.(*apievents.AuthAttempt).Login, nodeLogin)
return
require.EventuallyWithT(t, func(t *assert.CollectT) {
now := time.Now()
ctx := context.Background()
es, _, err := s.root.GetAuthServer().SearchEvents(ctx, events.SearchEventsRequest{
From: now.Add(-time.Hour),
To: now.Add(time.Hour),
Order: types.EventOrderDescending,
})
assert.NoError(t, err)

for _, e := range es {
if e.GetCode() == events.AuthAttemptFailureCode {
assert.Equal(t, e.(*apievents.AuthAttempt).Login, nodeLogin)
return
}
}
}
t.Errorf("failed to find AuthAttemptFailureCode event (0/%d events matched)", len(av))
t.Errorf("failed to find AuthAttemptFailureCode event (0/%d events matched)", len(es))
}, 5*time.Second, 500*time.Millisecond)
}

func TestFormatCommand(t *testing.T) {
Expand Down

0 comments on commit 781c870

Please sign in to comment.