@@ -13,6 +13,7 @@ import (
13
13
"runtime"
14
14
"strings"
15
15
"testing"
16
+ "time"
16
17
17
18
"github.com/spf13/cobra"
18
19
"github.com/stretchr/testify/assert"
@@ -197,13 +198,32 @@ func prepareTestData(t *testing.T) (*codersdk.Client, map[string]string) {
197
198
IncludeProvisionerDaemon : true ,
198
199
})
199
200
firstUser := coderdtest .CreateFirstUser (t , rootClient )
200
- secondUser , err := rootClient .CreateUser (ctx , codersdk.CreateUserRequest {
201
- Email : "testuser2@coder.com" ,
202
- Username : "testuser2" ,
203
- Password : coderdtest .FirstUserParams .Password ,
204
- OrganizationID : firstUser .OrganizationID ,
205
- })
201
+
202
+ firstUserData , err := rootClient .User (ctx , firstUser .UserID .String ())
206
203
require .NoError (t , err )
204
+
205
+ var secondUser codersdk.User
206
+ for {
207
+ secondUser , err = rootClient .CreateUser (ctx , codersdk.CreateUserRequest {
208
+ Email : "testuser2@coder.com" ,
209
+ Username : "testuser2" ,
210
+ Password : coderdtest .FirstUserParams .Password ,
211
+ OrganizationID : firstUser .OrganizationID ,
212
+ })
213
+ require .NoError (t , err )
214
+
215
+ // If the second user has the same timestamp as the first user, delete it and try again.
216
+ // This is because user order is determined by creation time, and we want to ensure
217
+ // second user is listed after first user.
218
+ // Round to microsecond since that is the precision of the database.
219
+ if secondUser .CreatedAt .Round (time .Microsecond ).Equal (firstUserData .CreatedAt .Round (time .Microsecond )) {
220
+ err = rootClient .DeleteUser (ctx , secondUser .ID )
221
+ require .NoError (t , err )
222
+ continue
223
+ }
224
+ break
225
+ }
226
+
207
227
version := coderdtest .CreateTemplateVersion (t , rootClient , firstUser .OrganizationID , nil )
208
228
version = coderdtest .AwaitTemplateVersionJob (t , rootClient , version .ID )
209
229
template := coderdtest .CreateTemplate (t , rootClient , firstUser .OrganizationID , version .ID , func (req * codersdk.CreateTemplateRequest ) {
0 commit comments