| 1 |
/* |
| 2 |
Copyright 2022 The Kubernetes Authors. |
| 3 |
|
| 4 |
Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
you may not use this file except in compliance with the License. |
| 6 |
You may obtain a copy of the License at |
| 7 |
|
| 8 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
|
| 10 |
Unless required by applicable law or agreed to in writing, software |
| 11 |
distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
See the License for the specific language governing permissions and |
| 14 |
limitations under the License. |
| 15 |
*/ |
| 16 |
|
| 17 |
package tests |
| 18 |
|
| 19 |
import ( |
| 20 |
"testing" |
| 21 |
|
| 22 |
"sigs.k8s.io/apiserver-network-proxy/pkg/server" |
| 23 |
"sigs.k8s.io/apiserver-network-proxy/tests/framework" |
| 24 |
) |
| 25 |
|
| 26 |
func TestServerRestartAgentReconnect(t *testing.T) { |
| 27 |
agentPort, err := framework.FreePorts(1) |
| 28 |
if err != nil { |
| 29 |
t.Fatal(err) |
| 30 |
} |
| 31 |
opts := framework.ProxyServerOpts{ |
| 32 |
Mode: server.ModeGRPC, |
| 33 |
ServerCount: 1, |
| 34 |
AgentPort: agentPort[0], |
| 35 |
} |
| 36 |
ps, err := Framework.ProxyServerRunner.Start(t, opts) |
| 37 |
if err != nil { |
| 38 |
t.Fatalf("Failed to start gRPC proxy server: %v", err) |
| 39 |
} |
| 40 |
|
| 41 |
a := runAgentWithID(t, "test-id", ps.AgentAddr()) |
| 42 |
defer a.Stop() |
| 43 |
|
| 44 |
waitForConnectedServerCount(t, 1, a) |
| 45 |
ps.Stop() |
| 46 |
waitForConnectedServerCount(t, 0, a) |
| 47 |
|
| 48 |
ps2, err := Framework.ProxyServerRunner.Start(t, opts) |
| 49 |
if err != nil { |
| 50 |
t.Fatalf("Failed to start gRPC proxy server: %v", err) |
| 51 |
} |
| 52 |
defer ps2.Stop() |
| 53 |
|
| 54 |
waitForConnectedServerCount(t, 1, a) |
| 55 |
} |