| 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 "testing" |
| 20 | |
| 21 | func TestGRPCServerAndAgentReadiness(t *testing.T) { |
| 22 | ps := runGRPCProxyServerWithServerCount(t, 1) |
| 23 | defer ps.Stop() |
| 24 | |
| 25 | if ps.Ready() { |
| 26 | t.Fatalf("expected not ready") |
| 27 | } |
| 28 | |
| 29 | a := runAgent(t, ps.AgentAddr()) |
| 30 | defer a.Stop() |
| 31 | waitForConnectedServerCount(t, 1, a) |
| 32 | |
| 33 | // check the agent connected status |
| 34 | isAgentReady := a.Ready() |
| 35 | if !isAgentReady { |
| 36 | t.Fatalf("expected connection status 'true', got: %t", isAgentReady) |
| 37 | } |
| 38 | if !ps.Ready() { |
| 39 | t.Fatalf("expected ready") |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | func TestHTTPConnServerAndAgentReadiness(t *testing.T) { |
| 44 | ps := runHTTPConnProxyServer(t) |
| 45 | defer ps.Stop() |
| 46 | |
| 47 | a := runAgent(t, ps.AgentAddr()) |
| 48 | defer a.Stop() |
| 49 | waitForConnectedServerCount(t, 1, a) |
| 50 | |
| 51 | // check the agent connected status |
| 52 | isAgentReady := a.Ready() |
| 53 | if !isAgentReady { |
| 54 | t.Fatalf("expected connection status 'true', got: %t", isAgentReady) |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | func TestAgentReadinessWithoutServer(t *testing.T) { |
| 59 | a := runAgent(t, "localhost:8080") |
| 60 | defer a.Stop() |
| 61 | // check the agent connected status |
| 62 | isAgentReady := a.Ready() |
| 63 | if isAgentReady { |
| 64 | t.Fatalf("expected connection status 'false', got: %t", isAgentReady) |
| 65 | } |
| 66 | } |