Skip to content

Commit

Permalink
test/e2e: remove race, add debug log
Browse files Browse the repository at this point in the history
Signed-off-by: Krzysztof Ostrowski <kostrows@redhat.com>
  • Loading branch information
ibihim committed Sep 22, 2022
1 parent dd0c134 commit 2c5936c
Showing 1 changed file with 33 additions and 19 deletions.
52 changes: 33 additions & 19 deletions test/e2e/useroauthaccesstokens_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -571,24 +571,18 @@ func watchTokens(t *testing.T, adminConfig *rest.Config, testNS, frantaUID, mirk
}

tokensObserved := []*oauthv1.UserOAuthAccessToken{}
printTokens := func(tokens []*oauthv1.UserOAuthAccessToken) {
for _, token := range tokens {
t.Logf(`
UserOAuthAccessToken:
UserName: %s
Name: %s
`, token.UserName, token.Name)
}
}

finished := make(chan bool)
timedCtx, timedCtxCancel := context.WithTimeout(context.Background(), 15*time.Second)
go func() {
tokenChan := tokenWatcher.ResultChan()
for {
select {
case tokenEvent := <-tokenChan:
token, ok := tokenEvent.Object.(*oauthv1.UserOAuthAccessToken)
require.True(t, ok)
require.Equal(t, tc.userName, token.UserName)
tokensObserved = append(tokensObserved, token)
case <-timedCtx.Done():
finished <- true
return
}
}
}()
defer timedCtxCancel()

go func() {
if tc.watchActions != nil {
Expand All @@ -600,10 +594,30 @@ func watchTokens(t *testing.T, adminConfig *rest.Config, testNS, frantaUID, mirk
}
}()

<-finished
tokenChan := tokenWatcher.ResultChan()
for {
select {
case tokenEvent := <-tokenChan:
token, ok := tokenEvent.Object.(*oauthv1.UserOAuthAccessToken)
if !ok {
t.Logf("not a *oauthv1.UserOAuthAccessToken")
continue
}

require.Equal(t, tc.expectedResults, len(tokensObserved), "unexpected number of results, expected %d, got %d: %v", tc.expectedResults, len(tokensObserved), tokensObserved)
oauthTokenClient.OAuthAccessTokens()
require.Equal(t, tc.userName, token.UserName)
tokensObserved = append(tokensObserved, token)
case <-timedCtx.Done():
if tc.expectedResults != len(tokensObserved) {
printTokens(tokensObserved)
require.Equal(t,
tc.expectedResults, len(tokensObserved),
"unexpected number of results, expected %d, got %d: %v", tc.expectedResults, len(tokensObserved), tokensObserved,
)
}
oauthTokenClient.OAuthAccessTokens()
return
}
}
})
}
}
Expand Down

0 comments on commit 2c5936c

Please sign in to comment.