Use test context in tests and new loop system in benchmarks (#33648)

Replace all contexts in tests with go1.24 t.Context()

---------

Co-authored-by: Giteabot <teabot@gitea.io>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
TheFox0x7 2025-02-20 10:57:40 +01:00 committed by GitHub
parent 3bbc482879
commit cc1fdc84ca
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
108 changed files with 712 additions and 794 deletions

View file

@ -4,7 +4,6 @@
package user_test
import (
"context"
"crypto/rand"
"fmt"
"strings"
@ -201,7 +200,7 @@ func BenchmarkHashPassword(b *testing.B) {
pass := "password1337"
u := &user_model.User{Passwd: pass}
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
u.SetPassword(pass)
}
}
@ -279,7 +278,7 @@ func TestCreateUserCustomTimestamps(t *testing.T) {
err := user_model.CreateUser(db.DefaultContext, user, &user_model.Meta{})
assert.NoError(t, err)
fetched, err := user_model.GetUserByID(context.Background(), user.ID)
fetched, err := user_model.GetUserByID(t.Context(), user.ID)
assert.NoError(t, err)
assert.Equal(t, creationTimestamp, fetched.CreatedUnix)
assert.Equal(t, creationTimestamp, fetched.UpdatedUnix)
@ -306,7 +305,7 @@ func TestCreateUserWithoutCustomTimestamps(t *testing.T) {
timestampEnd := time.Now().Unix()
fetched, err := user_model.GetUserByID(context.Background(), user.ID)
fetched, err := user_model.GetUserByID(t.Context(), user.ID)
assert.NoError(t, err)
assert.LessOrEqual(t, timestampStart, fetched.CreatedUnix)