Should a Mock inside a synctest test follow synctest's clock?
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Accessibilité débutants
- 8/100
- Type d'issue
- Fonctionnalité
- Clarté
- Plutôt claire
- Activité
- Active
- Stack technique
- go
- Domaine
- testing-qa
Piste de recherche
This is a design question, not a patch: the issue asks whether a *Mock inside a synctest test should follow synctest's fake clock or keep its own time. Read the mock clock implementation and the NewReal() clock in the quartz package, along with the prototype behaviour described in the issue (Advance, timers, ctx.Deadline). Done means a maintainer-agreed answer to the design question and the README wording that follows from it, which needs input from @spikecurtis first.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Go 1.25 made testing/synctest stable. In a synctest test, the time package runs on a fake clock that jumps forward whenever every goroutine in the test is blocked. That overlaps with what quartz does, so the README needs to say when to use which (#34). Before writing that, we want to agree on one design question:
Should a *Mock created inside a synctest test follow synctest's fake clock, or keep its own time as it does today?
Today the two clocks are independent. Calling time.Sleep(time.Hour) inside the test does not move the mock, and mClock.Advance(time.Hour) does not move time.Now(). quartz.NewReal() already follows synctest's clock, because it calls the time package.
We prototyped a mock that follows synctest's clock: timers are real time timers, and Advance(d) is time.Sleep(d) followed by synctest.Wait(). Compared with today's *Mock:
- Better:
ctx.Deadline()agrees withtime.Now(), andAdvancecan move past several timers at once, firing them in order. TodayAdvancestops at the next timer. - Worse, time moves without
Advance: a test that forgot to callAdvanceand then waited for the code to start its next timer still passed, because synctest moved time forward by 10s on its own. Today's mock fails that test. - Worse, real I/O: a 5s timeout never fired during a real TCP read.
Advance(5s)blocked until the read finished, because synctest does not move time while a goroutine waits on the network. Today's mock canceled the read after 67µs.
We also tried keeping the mock's own timers but sleeping the same amount on every Advance, so both clocks stay equal. They drift apart as soon as code in the test sleeps on its own. After a 1-minute time.Sleep in library code, the mock was 1 minute behind.
The one thing a synctest-following mock adds over NewReal() is traps.
Our recommendation: keep the *Mock independent. The README would say: use synctest with NewReal() when the whole test can run inside synctest, and use a *Mock when it does real I/O or needs to control exactly when time moves. If traps turn out to be wanted with synctest, a separate option is to add traps to the real clock rather than changing the mock.
@spikecurtis, does that match your view?
🤖 This issue was created with the help of Coder Agents.
- Langage dominant
- Go
- Étoiles
- 273
- Forks
- 9
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Préparer son environnement
Ce projet ne fournit ni conteneur de développement, ni Dockerfile, ni guide de contribution : l'installation est à votre charge. Commencez par son README, et consultez notre guide de la première contribution pour les étapes générales.
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de coder/quartz
-
Add support for contextsPeut-être pris @mafredri l’a pris il y a 187 jours. Ouverte
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 35/100
-
Why is there no Sleep function?Ouverte
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 25/100
Toutes les issues de coder/quartz
Issues similaires
-
[bug]: scan-all update-schedule does not auto-convert 5-field cron expressions as documentedPeut-être pris @vishnums2k5 l’a pris aujourd’hui. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
goharbor/harbor-cli#1143 · 1 commentaire ·
Les mainteneurs répondent en général sous 8 jours
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
-
--info inline-right:PREFIX leaves the first character of the prefix when the info gets shorterOuverte
Difficulté 2/5 1-3 heures Accessibilité débutants 73/100
-
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
rossoctl/context-guru#1053 ·
Les mainteneurs répondent en général sous 1 jour
-
[BUG] EphemeralJob matches every pod in the namespace when spec.selector is emptyPeut-être pris @vishnums2k5 l’a pris aujourd’hui. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
openkruise/kruise#2656 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour