0
0
mirror of https://github.com/go-gitea/gitea.git synced 2026-05-16 19:07:41 +02:00

fix(websocket): avoid data race with timeutil.MockUnset in tests

Replace timeutil.TimeStampNow() calls in the websocket notifier with a
nowTS() helper that reads time.Now().Unix() directly. TimeStampNow reads
a package-level mock variable that TestIncomingEmail writes concurrently,
causing a race detected by the race detector in test-pgsql CI.
This commit is contained in:
Epid 2026-03-24 01:22:03 +03:00
parent 3076f902ea
commit 096bdd0902

View File

@ -18,6 +18,12 @@ import (
"code.gitea.io/gitea/services/pubsub" "code.gitea.io/gitea/services/pubsub"
) )
// nowTS returns the current time as a TimeStamp using the real wall clock,
// avoiding data races with timeutil.MockUnset during tests.
func nowTS() timeutil.TimeStamp {
return timeutil.TimeStamp(time.Now().Unix())
}
type notificationCountEvent struct { type notificationCountEvent struct {
Type string `json:"type"` Type string `json:"type"`
Count int64 `json:"count"` Count int64 `json:"count"`
@ -42,7 +48,7 @@ func run(ctx context.Context) {
return return
} }
then := timeutil.TimeStampNow().Add(-2) then := nowTS().Add(-2)
timer := time.NewTicker(setting.UI.Notification.EventSourceUpdateTime) timer := time.NewTicker(setting.UI.Notification.EventSourceUpdateTime)
defer timer.Stop() defer timer.Stop()
@ -51,7 +57,7 @@ func run(ctx context.Context) {
case <-ctx.Done(): case <-ctx.Done():
return return
case <-timer.C: case <-timer.C:
now := timeutil.TimeStampNow().Add(-2) now := nowTS().Add(-2)
uidCounts, err := activities_model.GetUIDsAndNotificationCounts(ctx, then, now) uidCounts, err := activities_model.GetUIDsAndNotificationCounts(ctx, then, now)
if err != nil { if err != nil {