Isolate fix: Remove 5s sleep for 99% speedup. Discarded unwanted code.

Signed-off-by: 3Juhwan <13selfesteem91@naver.com>
Signed-off-by: Sammy Tran <sammyqtran@gmail.com>
This commit is contained in:
3Juhwan
2025-11-04 16:51:41 -08:00
committed by Sammy
parent 03d0c18c79
commit e3e1048166

View File

@@ -118,12 +118,10 @@ func TestReadyAndHealthy(t *testing.T) {
}
}()
// Give some time for the web goroutine to run since we need the server
// to be up before starting tests.
time.Sleep(5 * time.Second)
baseURL := "http://localhost" + port
waitForServerReady(t, baseURL, 5*time.Second)
resp, err := http.Get(baseURL + "/-/healthy")
require.NoError(t, err)
require.Equal(t, http.StatusOK, resp.StatusCode)
@@ -235,12 +233,10 @@ func TestRoutePrefix(t *testing.T) {
}
}()
// Give some time for the web goroutine to run since we need the server
// to be up before starting tests.
time.Sleep(5 * time.Second)
baseURL := "http://localhost" + port
waitForServerReady(t, baseURL+opts.RoutePrefix, 5*time.Second)
resp, err := http.Get(baseURL + opts.RoutePrefix + "/-/healthy")
require.NoError(t, err)
require.Equal(t, http.StatusOK, resp.StatusCode)
@@ -426,9 +422,9 @@ func TestShutdownWithStaleConnection(t *testing.T) {
close(closed)
}()
// Give some time for the web goroutine to run since we need the server
// to be up before starting tests.
time.Sleep(5 * time.Second)
baseURL := "http://localhost" + port
waitForServerReady(t, baseURL, 5*time.Second)
// Open a socket, and don't use it. This connection should then be closed
// after the ReadTimeout.
@@ -477,12 +473,10 @@ func TestHandleMultipleQuitRequests(t *testing.T) {
close(closed)
}()
// Give some time for the web goroutine to run since we need the server
// to be up before starting tests.
time.Sleep(5 * time.Second)
baseURL := opts.ExternalURL.Scheme + "://" + opts.ExternalURL.Host
waitForServerReady(t, baseURL, 5*time.Second)
start := make(chan struct{})
var wg sync.WaitGroup
for range 3 {
@@ -555,11 +549,10 @@ func TestAgentAPIEndPoints(t *testing.T) {
}
}()
// Give some time for the web goroutine to run since we need the server
// to be up before starting tests.
time.Sleep(5 * time.Second)
baseURL := "http://localhost" + port + "/api/v1"
waitForServerReady(t, "http://localhost"+port, 5*time.Second)
// Test for non-available endpoints in the Agent mode.
for path, methods := range map[string][]string{
"/labels": {http.MethodGet, http.MethodPost},
@@ -688,9 +681,7 @@ func TestMultipleListenAddresses(t *testing.T) {
}
}()
// Give some time for the web goroutine to run since we need the server
// to be up before starting tests.
time.Sleep(5 * time.Second)
waitForServerReady(t, "http://localhost"+port1, 5*time.Second)
// Set to ready.
webHandler.SetReady(Ready)
@@ -709,3 +700,24 @@ func TestMultipleListenAddresses(t *testing.T) {
cleanupTestResponse(t, resp)
}
}
// Give some time for the web goroutine to run since we need the server
// to be up before starting tests.
func waitForServerReady(t *testing.T, baseURL string, timeout time.Duration) {
t.Helper()
interval := 100 * time.Millisecond
deadline := time.Now().Add(timeout)
for time.Now().Before(deadline) {
resp, err := http.Get(baseURL + "/-/healthy")
if resp != nil {
cleanupTestResponse(t, resp)
}
if err == nil && resp.StatusCode == http.StatusOK {
return
}
time.Sleep(interval)
}
t.Fatalf("Server did not become ready within %v", timeout)
}