Make GenericApiServer.Run interruptable and fail on first listen
This commit is contained in:
@@ -65,12 +65,13 @@ func runDiscoverySummarizer(t *testing.T) string {
|
||||
return serverURL
|
||||
}
|
||||
|
||||
func runAPIServer(t *testing.T) string {
|
||||
func runAPIServer(t *testing.T, stopCh <-chan struct{}) string {
|
||||
serverRunOptions := apiserver.NewServerRunOptions()
|
||||
// Change the port, because otherwise it will fail if examples/apiserver/apiserver_test and this are run in parallel.
|
||||
serverRunOptions.InsecurePort = 8083
|
||||
// Change the ports, because otherwise it will fail if examples/apiserver/apiserver_test and this are run in parallel.
|
||||
serverRunOptions.SecurePort = 6443 + 3
|
||||
serverRunOptions.InsecurePort = 8080 + 3
|
||||
go func() {
|
||||
if err := apiserver.Run(serverRunOptions); err != nil {
|
||||
if err := apiserver.Run(serverRunOptions, stopCh); err != nil {
|
||||
t.Fatalf("Error in bringing up the example apiserver: %v", err)
|
||||
}
|
||||
}()
|
||||
@@ -98,7 +99,9 @@ func TestRunDiscoverySummarizer(t *testing.T) {
|
||||
testResponse(t, discoveryURL, "/randomPath", http.StatusNotFound)
|
||||
|
||||
// Run the APIServer now to test the good case.
|
||||
runAPIServer(t)
|
||||
stopCh := make(chan struct{})
|
||||
runAPIServer(t, stopCh)
|
||||
defer close(stopCh)
|
||||
|
||||
// Test /api path.
|
||||
// There is no server running at that URL, so we will get a 500.
|
||||
|
@@ -42,11 +42,13 @@ var groupVersionForDiscovery = unversioned.GroupVersionForDiscovery{
|
||||
|
||||
func TestRunServer(t *testing.T) {
|
||||
serverIP := fmt.Sprintf("http://localhost:%d", apiserver.InsecurePort)
|
||||
stopCh := make(chan struct{})
|
||||
go func() {
|
||||
if err := apiserver.Run(apiserver.NewServerRunOptions()); err != nil {
|
||||
if err := apiserver.Run(apiserver.NewServerRunOptions(), stopCh); err != nil {
|
||||
t.Fatalf("Error in bringing up the server: %v", err)
|
||||
}
|
||||
}()
|
||||
defer close(stopCh)
|
||||
if err := waitForApiserverUp(serverIP); err != nil {
|
||||
t.Fatalf("%v", err)
|
||||
}
|
||||
@@ -58,14 +60,16 @@ func TestRunServer(t *testing.T) {
|
||||
|
||||
func TestRunSecureServer(t *testing.T) {
|
||||
serverIP := fmt.Sprintf("https://localhost:%d", apiserver.SecurePort)
|
||||
stopCh := make(chan struct{})
|
||||
go func() {
|
||||
options := apiserver.NewServerRunOptions()
|
||||
options.InsecurePort = 0
|
||||
options.SecurePort = apiserver.SecurePort
|
||||
if err := apiserver.Run(options); err != nil {
|
||||
if err := apiserver.Run(options, stopCh); err != nil {
|
||||
t.Fatalf("Error in bringing up the server: %v", err)
|
||||
}
|
||||
}()
|
||||
defer close(stopCh)
|
||||
if err := waitForApiserverUp(serverIP); err != nil {
|
||||
t.Fatalf("%v", err)
|
||||
}
|
||||
|
@@ -77,7 +77,8 @@ func TestLongRunningRequestRegexp(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
var insecurePort = 8082
|
||||
var securePort = 6443 + 2
|
||||
var insecurePort = 8080 + 2
|
||||
var serverIP = fmt.Sprintf("http://localhost:%v", insecurePort)
|
||||
var groupVersions = []unversioned.GroupVersion{
|
||||
fed_v1b1.SchemeGroupVersion,
|
||||
@@ -86,6 +87,7 @@ var groupVersions = []unversioned.GroupVersion{
|
||||
|
||||
func TestRun(t *testing.T) {
|
||||
s := options.NewServerRunOptions()
|
||||
s.GenericServerRunOptions.SecurePort = securePort
|
||||
s.GenericServerRunOptions.InsecurePort = insecurePort
|
||||
_, ipNet, _ := net.ParseCIDR("10.10.10.0/24")
|
||||
s.GenericServerRunOptions.ServiceClusterIPRange = *ipNet
|
||||
|
Reference in New Issue
Block a user