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

Abierto Apto para principiantes
#1,441 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
86/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
go
Área
testing

Línea de trabajo

Lee internal/server/event_server_test.go, especialmente el inicio del servidor alrededor de la línea 143, el primer POST alrededor de la línea 309 y la comprobación de disponibilidad existente alrededor de las líneas 412–418. Añade la espera de disponibilidad después de iniciar la goroutine del servidor y luego ejecuta TestEventServer con las condiciones propensas a carreras que se han informado; se considera terminado cuando el primer POST ya no compite con el inicio del servidor.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Go
Estrellas
182
Forks
183
Merge medio
9 h 20 min
PR fusionados (30 d)
26

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de fluxcd/notification-controller

Todos los issues de fluxcd/notification-controller

Issues similares

Más issues de Go

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.