[ 
https://issues.apache.org/jira/browse/YUNIKORN-3337?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

weichen lai updated YUNIKORN-3337:
----------------------------------
    Description: 
When running unit tests in `pkg/webservice` locally (e.g., under WSL via `make 
test`), tests can fail with `connection refused` errors:             

{code:java}
    2026-07-26T10:09:29.611+0800    INFO    core.rest       
webservice/webservice.go:74     web-app started {"port": 9080}                  
            
    --- FAIL: Test_RedirectDebugHandler (0.00s)                                 
                                                                        
        --- FAIL: Test_RedirectDebugHandler/statedump (0.00s)                   
                                                                        
            webservice_test.go:67: assertion failed: error is not nil: Get 
"http://localhost:9080/ws/v1/fullstatedump": dial tcp 127.0.0.1:9080:           
                                                                                
                                                
            webservice_test.go:67: assertion failed: error is not nil: Get 
"http://localhost:9080/ws/v1/fullstatedump": dial tcp 127.0.0.1:9080:
  connect: connection refused: unexpected error returned
    --- FAIL: Test_RouterHandling (0.00s)                                       
                                                                        
        webservice_test.go:86: assertion failed: error is not nil: Post 
"http://localhost:9080/ws/v1/clusters": dial tcp 127.0.0.1:9080: connect:
  connection refused: unexpected error returned
{code}
                                                                                
                                                                 
This happens because WebService.StartWebApp() launches 
httpServer.ListenAndServe() asynchronously in a goroutine and returns 
immediately. Under local environments like WSL with slight CPU scheduling or 
socket binding delays, test cases issue HTTP requests in less than 1 ms 
(0.00s), attempting to connect before the OS finishes binding port 9080.

  was:
When running unit tests in `pkg/webservice` locally (e.g., under WSL via `make 
test`), tests can fail with `connection refused` errors:             
                                                                                
                                                                        ```text 
                                                                                
                                                            
    2026-07-26T10:09:29.611+0800    INFO    core.rest       
webservice/webservice.go:74     web-app started {"port": 9080}                  
            
    --- FAIL: Test_RedirectDebugHandler (0.00s)                                 
                                                                        
        --- FAIL: Test_RedirectDebugHandler/statedump (0.00s)                   
                                                                        
            webservice_test.go:67: assertion failed: error is not nil: Get 
"http://localhost:9080/ws/v1/fullstatedump": dial tcp 127.0.0.1:9080:           
                                                                                
                                                
            webservice_test.go:67: assertion failed: error is not nil: Get 
"http://localhost:9080/ws/v1/fullstatedump": dial tcp 127.0.0.1:9080:
  connect: connection refused: unexpected error returned
    --- FAIL: Test_RouterHandling (0.00s)                                       
                                                                        
        webservice_test.go:86: assertion failed: error is not nil: Post 
"http://localhost:9080/ws/v1/clusters": dial tcp 127.0.0.1:9080: connect:
  connection refused: unexpected error returned
```
                                                                                
                                                                        
This happens because WebService.StartWebApp() launches 
httpServer.ListenAndServe() asynchronously in a goroutine and returns 
immediately. Under local environments like WSL with slight CPU scheduling or 
socket binding delays, test cases issue HTTP requests in less than 1 ms 
(0.00s), attempting to connect before the OS finishes binding port 9080.


> Fix connection refused error in webservice unit tests 
> ------------------------------------------------------
>
>                 Key: YUNIKORN-3337
>                 URL: https://issues.apache.org/jira/browse/YUNIKORN-3337
>             Project: Apache YuniKorn
>          Issue Type: Bug
>          Components: test - unit
>            Reporter: weichen lai
>            Assignee: weichen lai
>            Priority: Minor
>
> When running unit tests in `pkg/webservice` locally (e.g., under WSL via 
> `make test`), tests can fail with `connection refused` errors:             
> {code:java}
>     2026-07-26T10:09:29.611+0800    INFO    core.rest       
> webservice/webservice.go:74     web-app started {"port": 9080}                
>               
>     --- FAIL: Test_RedirectDebugHandler (0.00s)                               
>                                                                           
>         --- FAIL: Test_RedirectDebugHandler/statedump (0.00s)                 
>                                                                           
>             webservice_test.go:67: assertion failed: error is not nil: Get 
> "http://localhost:9080/ws/v1/fullstatedump": dial tcp 127.0.0.1:9080:         
>                                                                               
>                                                     
>             webservice_test.go:67: assertion failed: error is not nil: Get 
> "http://localhost:9080/ws/v1/fullstatedump": dial tcp 127.0.0.1:9080:
>   connect: connection refused: unexpected error returned
>     --- FAIL: Test_RouterHandling (0.00s)                                     
>                                                                           
>         webservice_test.go:86: assertion failed: error is not nil: Post 
> "http://localhost:9080/ws/v1/clusters": dial tcp 127.0.0.1:9080: connect:
>   connection refused: unexpected error returned
> {code}
>                                                                               
>                                                                    
> This happens because WebService.StartWebApp() launches 
> httpServer.ListenAndServe() asynchronously in a goroutine and returns 
> immediately. Under local environments like WSL with slight CPU scheduling or 
> socket binding delays, test cases issue HTTP requests in less than 1 ms 
> (0.00s), attempting to connect before the OS finishes binding port 9080.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

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

Reply via email to