Flaky test: TestEventServer fails with connection refused due to startup race

Aperta Adatta ai principianti
#1,441 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
86/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
go
Ambito
testing

Direzione di ricerca

Leggi internal/server/event_server_test.go, in particolare l’avvio del server intorno alla riga 143, il primo POST intorno alla riga 309 e il controllo di disponibilità esistente intorno alle righe 412–418. Aggiungi l’attesa della disponibilità dopo aver avviato la goroutine del server, poi esegui TestEventServer con le condizioni segnalate come soggette a race; il lavoro è completato quando il primo POST non è più in race con l’avvio del server.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Environment: main at d4eaa7a, Go 1.27.4, Ubuntu on WSL2

What I saw

During a full make test run, I hit a failure on the forwards_when_source_is_a_match subtest in TestEventServer with this exact error:
Post "http://localhost:<port>": dial tcp 127.0.0.1:<port>: connect: connection refused

It passed on a re-run. I ran it 30 separate times in a loop and they all passed, so it's a rare timing flake.

Cause

The server is started in a background goroutine (internal/server/event_server_test.go:143), but there is no readiness wait before the first http.Post executes (around line 309). If the Go scheduler delays the goroutine slightly, which is more likely under heavy load, such as during a full parallel make test with -race, the POST request fires before the server is actually listening.

Proof

I added a temporary time.Sleep(200 * time.Millisecond) at the top of EventServer.ListenAndServe in internal/server/event_server.go. With that delay, all 13 subtests instantly fail with connection refused (because the tests execute quickly enough that all of them run and fail inside that 200ms window).

Proposed fix

Add a readiness wait immediately after the server goroutine starts. We can use the exact same g.Eventually(net.Dial...) block that is already used elsewhere in the file (internal/server/event_server_test.go lines 412–418). Adding this check makes the test pass reliably, even with the artificial 200ms delay injected.

I can open a PR with this fix if you'd like.

Lingua principale
Go
Stelle
182
Fork
183
Merge medio
9h 20m
PR unite (30g)
26

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di fluxcd/notification-controller

Tutte le issue di fluxcd/notification-controller

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.