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

Đang mở Phù hợp với người mới
#1,441 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
86/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
go
Lĩnh vực
testing

Hướng nghiên cứu

Đọc internal/server/event_server_test.go, đặc biệt là phần khởi động máy chủ quanh dòng 143, POST đầu tiên quanh dòng 309 và kiểm tra trạng thái sẵn sàng hiện có quanh các dòng 412–418. Thêm bước chờ máy chủ sẵn sàng sau khi khởi chạy goroutine của máy chủ, rồi chạy TestEventServer trong các điều kiện được báo cáo là dễ xảy ra race; hoàn tất khi POST đầu tiên không còn race với quá trình khởi động máy chủ.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Go
Star
182
Fork
183
Merge trung bình
9 giờ 20 phút
Pull request đã merge (30 ngày)
26

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của fluxcd/notification-controller

Tất cả issue của fluxcd/notification-controller

Issue tương tự

Thêm issue về Go

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.