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

オープン 初心者向け
#1,441 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
86/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
go
領域
testing

調査の方向性

internal/server/event_server_test.goを読み、特に143行目付近のサーバー起動、309行目付近の最初のPOST、412~418行目付近の既存の準備完了チェックを確認してください。サーバーのgoroutineを起動した後に準備完了を待つ処理を追加し、報告されている競合が起きやすい条件でTestEventServerを実行してください。最初のPOSTがサーバー起動と競合しなくなれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
Go
スター
182
フォーク
183
平均マージ
9時間 20分
マージ済み PR(30日)
26

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

fluxcd/notification-controller のほかの issue

fluxcd/notification-controller の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。