fix: 等待 Runner facade 就绪
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
package runnerbootstrap
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestWaitForFacadeRetriesTransientGatewayFailure(t *testing.T) {
|
||||
var requests atomic.Int32
|
||||
server := httptest.NewServer(http.HandlerFunc(func(writer http.ResponseWriter, _ *http.Request) {
|
||||
if requests.Add(1) < 3 {
|
||||
writer.WriteHeader(http.StatusBadGateway)
|
||||
return
|
||||
}
|
||||
writer.WriteHeader(http.StatusNotFound)
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
||||
defer cancel()
|
||||
if err := waitForFacade(ctx, server.URL); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if requests.Load() != 3 {
|
||||
t.Fatalf("requests = %d", requests.Load())
|
||||
}
|
||||
}
|
||||
|
||||
func TestWaitForFacadeStopsWithContext(t *testing.T) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(writer http.ResponseWriter, _ *http.Request) {
|
||||
writer.WriteHeader(http.StatusServiceUnavailable)
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
|
||||
defer cancel()
|
||||
if err := waitForFacade(ctx, server.URL); err == nil {
|
||||
t.Fatal("expected readiness timeout")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user