This is an automated email from the ASF dual-hosted git repository.

manirajv06 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/yunikorn-core.git


The following commit(s) were added to refs/heads/master by this push:
     new 4055294d [YUNIKORN-3337] Fix race condition in webservice unit tests 
(#1109)
4055294d is described below

commit 4055294d7c9edec1843377a5a9de507c9d707ee8
Author: PoiBlackTea <[email protected]>
AuthorDate: Tue Jul 28 11:48:20 2026 +0530

    [YUNIKORN-3337] Fix race condition in webservice unit tests (#1109)
    
    Add waitForServerReady helper in webservice_test.go using 
common.WaitForCondition() and net.DialTimeout() to prevent connection refused 
failures during local test execution.
    
    Closes: #1109
    
    Signed-off-by: mani <[email protected]>
---
 pkg/webservice/webservice_test.go | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/pkg/webservice/webservice_test.go 
b/pkg/webservice/webservice_test.go
index 128023e6..aeec0f62 100644
--- a/pkg/webservice/webservice_test.go
+++ b/pkg/webservice/webservice_test.go
@@ -23,22 +23,38 @@ import (
        "compress/gzip"
        "fmt"
        "io"
+       "net"
        "net/http"
        "strings"
        "testing"
+       "time"
 
        "gotest.tools/v3/assert"
 
+       "github.com/apache/yunikorn-core/pkg/common"
        "github.com/apache/yunikorn-core/pkg/metrics/history"
        "github.com/apache/yunikorn-core/pkg/scheduler"
 )
 
 const base = "http://localhost:9080";
 
+func waitForServerReady(t *testing.T) {
+       err := common.WaitForCondition(10*time.Millisecond, 3*time.Second, 
func() bool {
+               conn, err := net.DialTimeout("tcp", 
net.JoinHostPort("127.0.0.1", "9080"), 100*time.Millisecond)
+               if err == nil {
+                       defer conn.Close()
+                       return true
+               }
+               return false
+       })
+       assert.NilError(t, err, "webapp failed to start in 3 seconds")
+}
+
 func Test_RedirectDebugHandler(t *testing.T) {
        defer ResetIMHistory()
        s := NewWebApp(&scheduler.ClusterContext{}, 
history.NewInternalMetricsHistory(5))
        s.StartWebApp()
+       waitForServerReady(t)
        defer func(s *WebService) {
                err := s.StopWebApp()
                if err != nil {
@@ -74,6 +90,7 @@ func Test_RedirectDebugHandler(t *testing.T) {
 func Test_RouterHandling(t *testing.T) {
        s := NewWebApp(&scheduler.ClusterContext{}, nil)
        s.StartWebApp()
+       waitForServerReady(t)
        defer func(s *WebService) {
                err := s.StopWebApp()
                if err != nil {
@@ -112,6 +129,7 @@ func Test_RouterHandling(t *testing.T) {
 func Test_HeaderChecks(t *testing.T) {
        s := NewWebApp(&scheduler.ClusterContext{}, nil)
        s.StartWebApp()
+       waitForServerReady(t)
        defer func(s *WebService) {
                err := s.StopWebApp()
                if err != nil {
@@ -173,6 +191,7 @@ func Test_GzipCompression(t *testing.T) {
 
        s := NewWebApp(&scheduler.ClusterContext{}, nil)
        s.StartWebApp()
+       waitForServerReady(t)
        defer func() {
                if err := s.StopWebApp(); err != nil {
                        t.Fatal("failed to stop webapp")
@@ -249,6 +268,7 @@ func Test_GzipCompression(t *testing.T) {
 func Test_GzipMinCompressionSize(t *testing.T) {
        s := NewWebApp(&scheduler.ClusterContext{}, nil)
        s.StartWebApp()
+       waitForServerReady(t)
        defer func() {
                if err := s.StopWebApp(); err != nil {
                        t.Fatal("failed to stop webapp")
@@ -315,6 +335,7 @@ func Test_GzipClientAcceptsGzip(t *testing.T) {
 func Test_GzipExcludesEventStream(t *testing.T) {
        s := NewWebApp(&scheduler.ClusterContext{}, nil)
        s.StartWebApp()
+       waitForServerReady(t)
        defer func() {
                if err := s.StopWebApp(); err != nil {
                        t.Fatal("failed to stop webapp")
@@ -345,6 +366,7 @@ func Test_GzipVaryHeaderNotDuplicated(t *testing.T) {
 
        s := NewWebApp(&scheduler.ClusterContext{}, nil)
        s.StartWebApp()
+       waitForServerReady(t)
        defer func() {
                if err := s.StopWebApp(); err != nil {
                        t.Fatal("failed to stop webapp")


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to