0
0
mirror of https://github.com/go-gitea/gitea.git synced 2026-04-18 12:42:47 +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 f26aa2f520
commit 634b6383b4

View File

@ -18,6 +18,12 @@ import (
"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 string `json:"type"`
Count int64 `json:"count"`
@ -42,7 +48,7 @@ func run(ctx context.Context) {
return
}
then := timeutil.TimeStampNow().Add(-2)
then := nowTS().Add(-2)
timer := time.NewTicker(setting.UI.Notification.EventSourceUpdateTime)
defer timer.Stop()
@ -51,7 +57,7 @@ func run(ctx context.Context) {
case <-ctx.Done():
return
case <-timer.C:
now := timeutil.TimeStampNow().Add(-2)
now := nowTS().Add(-2)
uidCounts, err := activities_model.GetUIDsAndNotificationCounts(ctx, then, now)
if err != nil {