Skip to content

Commit bebe4f0

Browse files
chore: sort inserted users on dbmem (#15483)
1 parent 97b3bbf commit bebe4f0

File tree

1 file changed

+3
-15
lines changed

1 file changed

+3
-15
lines changed

coderd/database/dbmem/dbmem.go

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7714,21 +7714,6 @@ func (q *FakeQuerier) InsertUser(_ context.Context, arg database.InsertUserParam
77147714
return database.User{}, err
77157715
}
77167716

7717-
// There is a common bug when using dbmem that 2 inserted users have the
7718-
// same created_at time. This causes user order to not be deterministic,
7719-
// which breaks some unit tests.
7720-
// To fix this, we make sure that the created_at time is always greater
7721-
// than the last user's created_at time.
7722-
allUsers, _ := q.GetUsers(context.Background(), database.GetUsersParams{})
7723-
if len(allUsers) > 0 {
7724-
lastUser := allUsers[len(allUsers)-1]
7725-
if arg.CreatedAt.Before(lastUser.CreatedAt) ||
7726-
arg.CreatedAt.Equal(lastUser.CreatedAt) {
7727-
// 1 ms is a good enough buffer.
7728-
arg.CreatedAt = lastUser.CreatedAt.Add(time.Millisecond)
7729-
}
7730-
}
7731-
77327717
q.mutex.Lock()
77337718
defer q.mutex.Unlock()
77347719

@@ -7756,6 +7741,9 @@ func (q *FakeQuerier) InsertUser(_ context.Context, arg database.InsertUserParam
77567741
LoginType: arg.LoginType,
77577742
}
77587743
q.users = append(q.users, user)
7744+
sort.Slice(q.users, func(i, j int) bool {
7745+
return q.users[i].CreatedAt.Before(q.users[j].CreatedAt)
7746+
})
77597747
return user, nil
77607748
}
77617749

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy