@@ -11,6 +11,7 @@ import (
11
11
12
12
"github.com/google/uuid"
13
13
"github.com/stretchr/testify/require"
14
+ "golang.org/x/sync/errgroup"
14
15
15
16
"github.com/coder/coder/coderd/coderdtest"
16
17
"github.com/coder/coder/coderd/rbac"
@@ -1102,38 +1103,48 @@ func TestPaginatedUsers(t *testing.T) {
1102
1103
require .NoError (t , err )
1103
1104
orgID := me .OrganizationIDs [0 ]
1104
1105
1105
- allUsers := make ([]codersdk.User , 0 )
1106
- allUsers = append (allUsers , me )
1107
- specialUsers := make ([]codersdk.User , 0 )
1108
-
1109
1106
// When 100 users exist
1110
1107
total := 100
1108
+ allUsers := make ([]codersdk.User , total + 1 )
1109
+ allUsers [0 ] = me
1110
+ specialUsers := make ([]codersdk.User , total / 2 )
1111
+
1112
+ eg , egCtx := errgroup .WithContext (ctx )
1111
1113
// Create users
1112
1114
for i := 0 ; i < total ; i ++ {
1113
- email := fmt .Sprintf ("%d@coder.com" , i )
1114
- username := fmt .Sprintf ("user%d" , i )
1115
- if i % 2 == 0 {
1116
- email = fmt .Sprintf ("%d@gmail.com" , i )
1117
- username = fmt .Sprintf ("specialuser%d" , i )
1118
- }
1119
- // One side effect of having to use the api vs the db calls directly, is you cannot
1120
- // mock time. Ideally I could pass in mocked times and space these users out.
1121
- //
1122
- // But this also serves as a good test. Postgres has microsecond precision on its timestamps.
1123
- // If 2 users share the same created_at, that could cause an issue if you are strictly paginating via
1124
- // timestamps. The pagination goes by timestamps and uuids.
1125
- newUser , err := client .CreateUser (ctx , codersdk.CreateUserRequest {
1126
- Email : email ,
1127
- Username : username ,
1128
- Password : "password" ,
1129
- OrganizationID : orgID ,
1115
+ i := i
1116
+ eg .Go (func () error {
1117
+ email := fmt .Sprintf ("%d@coder.com" , i )
1118
+ username := fmt .Sprintf ("user%d" , i )
1119
+ if i % 2 == 0 {
1120
+ email = fmt .Sprintf ("%d@gmail.com" , i )
1121
+ username = fmt .Sprintf ("specialuser%d" , i )
1122
+ }
1123
+ // One side effect of having to use the api vs the db calls directly, is you cannot
1124
+ // mock time. Ideally I could pass in mocked times and space these users out.
1125
+ //
1126
+ // But this also serves as a good test. Postgres has microsecond precision on its timestamps.
1127
+ // If 2 users share the same created_at, that could cause an issue if you are strictly paginating via
1128
+ // timestamps. The pagination goes by timestamps and uuids.
1129
+ newUser , err := client .CreateUser (egCtx , codersdk.CreateUserRequest {
1130
+ Email : email ,
1131
+ Username : username ,
1132
+ Password : "password" ,
1133
+ OrganizationID : orgID ,
1134
+ })
1135
+ if err != nil {
1136
+ return err
1137
+ }
1138
+ allUsers [i + 1 ] = newUser
1139
+ if i % 2 == 0 {
1140
+ specialUsers [i / 2 ] = newUser
1141
+ }
1142
+
1143
+ return nil
1130
1144
})
1131
- require .NoError (t , err )
1132
- allUsers = append (allUsers , newUser )
1133
- if i % 2 == 0 {
1134
- specialUsers = append (specialUsers , newUser )
1135
- }
1136
1145
}
1146
+ err = eg .Wait ()
1147
+ require .NoError (t , err , "create users failed" )
1137
1148
1138
1149
// Sorting the users will sort by (created_at, uuid). This is to handle
1139
1150
// the off case that created_at is identical for 2 users.
0 commit comments