mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-12 02:54:20 +00:00
test(integration, user): fix flakiness (#7252)
* test: fix user integration test flakiness * assert with *assert.CollectT
This commit is contained in:
parent
35339162c9
commit
cdfcdec101
@ -5,6 +5,7 @@ package user_test
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -122,25 +123,20 @@ func TestServer_GetUserByID(t *testing.T) {
|
|||||||
username := fmt.Sprintf("%d@mouse.com", time.Now().UnixNano())
|
username := fmt.Sprintf("%d@mouse.com", time.Now().UnixNano())
|
||||||
err := tt.args.dep(tt.args.ctx, username, tt.args.req)
|
err := tt.args.dep(tt.args.ctx, username, tt.args.req)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
retryDuration := time.Minute
|
||||||
var got *user.GetUserByIDResponse
|
if ctxDeadline, ok := CTX.Deadline(); ok {
|
||||||
for {
|
retryDuration = time.Until(ctxDeadline)
|
||||||
got, err = Client.GetUserByID(tt.args.ctx, tt.args.req)
|
|
||||||
if err == nil || (tt.wantErr && err != nil) {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
select {
|
|
||||||
case <-CTX.Done():
|
|
||||||
t.Fatal(CTX.Err(), err)
|
|
||||||
case <-time.After(time.Second):
|
|
||||||
t.Log("retrying GetUserByID")
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if tt.wantErr {
|
require.EventuallyWithT(t, func(ttt *assert.CollectT) {
|
||||||
require.Error(t, err)
|
got, getErr := Client.GetUserByID(tt.args.ctx, tt.args.req)
|
||||||
} else {
|
assertErr := assert.NoError
|
||||||
require.NoError(t, err)
|
if tt.wantErr {
|
||||||
|
assertErr = assert.Error
|
||||||
|
}
|
||||||
|
assertErr(ttt, getErr)
|
||||||
|
if getErr != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
tt.want.User.UserId = tt.args.req.GetUserId()
|
tt.want.User.UserId = tt.args.req.GetUserId()
|
||||||
tt.want.User.Username = username
|
tt.want.User.Username = username
|
||||||
tt.want.User.PreferredLoginName = username
|
tt.want.User.PreferredLoginName = username
|
||||||
@ -148,9 +144,9 @@ func TestServer_GetUserByID(t *testing.T) {
|
|||||||
if human := tt.want.User.GetHuman(); human != nil {
|
if human := tt.want.User.GetHuman(); human != nil {
|
||||||
human.Email.Email = username
|
human.Email.Email = username
|
||||||
}
|
}
|
||||||
require.Equal(t, tt.want.User, got.User)
|
assert.Equal(ttt, tt.want.User, got.User)
|
||||||
integration.AssertDetails(t, tt.want, got)
|
integration.AssertDetails(t, tt.want, got)
|
||||||
}
|
}, retryDuration, time.Second)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -556,30 +552,24 @@ func TestServer_ListUsers(t *testing.T) {
|
|||||||
}
|
}
|
||||||
infos, err := tt.args.dep(tt.args.ctx, orgResp.OrganizationId, usernames, tt.args.req)
|
infos, err := tt.args.dep(tt.args.ctx, orgResp.OrganizationId, usernames, tt.args.req)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
retryDuration := time.Minute
|
||||||
var got *user.ListUsersResponse
|
if ctxDeadline, ok := CTX.Deadline(); ok {
|
||||||
for {
|
retryDuration = time.Until(ctxDeadline)
|
||||||
got, err = Client.ListUsers(tt.args.ctx, tt.args.req)
|
|
||||||
if err == nil || (tt.wantErr && err != nil) {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
select {
|
|
||||||
case <-CTX.Done():
|
|
||||||
t.Fatal(tt.args.ctx.Err(), err)
|
|
||||||
case <-time.After(time.Second):
|
|
||||||
t.Log("retrying ListUsers")
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if tt.wantErr {
|
require.EventuallyWithT(t, func(ttt *assert.CollectT) {
|
||||||
require.Error(t, err)
|
got, listErr := Client.ListUsers(tt.args.ctx, tt.args.req)
|
||||||
} else {
|
assertErr := assert.NoError
|
||||||
require.NoError(t, err)
|
if tt.wantErr {
|
||||||
|
assertErr = assert.Error
|
||||||
|
}
|
||||||
|
assertErr(ttt, listErr)
|
||||||
|
if listErr != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
// always only give back dependency infos which are required for the response
|
// always only give back dependency infos which are required for the response
|
||||||
require.Len(t, tt.want.Result, len(infos))
|
assert.Len(ttt, tt.want.Result, len(infos))
|
||||||
// always first check length, otherwise its failed anyway
|
// always first check length, otherwise its failed anyway
|
||||||
require.Len(t, got.Result, len(tt.want.Result))
|
assert.Len(ttt, got.Result, len(tt.want.Result))
|
||||||
// fill in userid and username as it is generated
|
// fill in userid and username as it is generated
|
||||||
for i := range infos {
|
for i := range infos {
|
||||||
tt.want.Result[i].UserId = infos[i].UserID
|
tt.want.Result[i].UserId = infos[i].UserID
|
||||||
@ -591,10 +581,10 @@ func TestServer_ListUsers(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for i := range tt.want.Result {
|
for i := range tt.want.Result {
|
||||||
require.Contains(t, got.Result, tt.want.Result[i])
|
assert.Contains(ttt, got.Result, tt.want.Result[i])
|
||||||
}
|
}
|
||||||
integration.AssertListDetails(t, tt.want, got)
|
integration.AssertListDetails(t, tt.want, got)
|
||||||
}
|
}, retryDuration, time.Millisecond*100, "timeout waiting for expected user result")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user