From 06332b91b193c0ab362e7f0a96cd715b8556acd5 Mon Sep 17 00:00:00 2001 From: Thomas Pantelis Date: Tue, 24 Dec 2019 07:56:08 -0500 Subject: [PATCH] E2E: make connection timeout configurable (#268) * E2E: make connection timeout configurable Added 'connection-timeout' and `connection-attempts' test params. Defaults are 6 and 10 for total timeout of 60 s. Signed-off-by: Tom Pantelis * E2E: make timeout used by AwaitResultOrError configurable Signed-off-by: Tom Pantelis --- test/e2e/dataplane/tcp_pod_connectivity.go | 29 +++++++++++++--------- test/e2e/framework/framework.go | 2 +- test/e2e/framework/network_pods.go | 22 ++++++++-------- test/e2e/framework/test_context.go | 6 +++++ 4 files changed, 35 insertions(+), 24 deletions(-) diff --git a/test/e2e/dataplane/tcp_pod_connectivity.go b/test/e2e/dataplane/tcp_pod_connectivity.go index 2078356f7..14d2392e0 100644 --- a/test/e2e/dataplane/tcp_pod_connectivity.go +++ b/test/e2e/dataplane/tcp_pod_connectivity.go @@ -66,7 +66,8 @@ var _ = Describe("[dataplane] Basic TCP connectivity tests across clusters witho func RunConnectivityTest(f *framework.Framework, useService bool, listenerScheduling framework.NetworkPodScheduling, connectorScheduling framework.NetworkPodScheduling, listenerCluster framework.ClusterIndex, connectorCluster framework.ClusterIndex) (*framework.NetworkPod, *framework.NetworkPod) { - listenerPod, connectorPod := createPods(f, useService, listenerScheduling, connectorScheduling, listenerCluster, connectorCluster, 45) + listenerPod, connectorPod := createPods(f, useService, listenerScheduling, connectorScheduling, listenerCluster, connectorCluster, + framework.TestContext.ConnectionTimeout, framework.TestContext.ConnectionAttempts) listenerPod.CheckSuccessfulFinish() connectorPod.CheckSuccessfulFinish() @@ -82,7 +83,7 @@ func RunConnectivityTest(f *framework.Framework, useService bool, listenerSchedu } func RunNoConnectivityTest(f *framework.Framework, useService bool, listenerScheduling framework.NetworkPodScheduling, connectorScheduling framework.NetworkPodScheduling, listenerCluster framework.ClusterIndex, connectorCluster framework.ClusterIndex) (*framework.NetworkPod, *framework.NetworkPod) { - listenerPod, connectorPod := createPods(f, useService, listenerScheduling, connectorScheduling, listenerCluster, connectorCluster, 5) + listenerPod, connectorPod := createPods(f, useService, listenerScheduling, connectorScheduling, listenerCluster, connectorCluster, 5, 1) By("Verifying that listener pod exits with non-zero code and timed out message") Expect(listenerPod.TerminationMessage).To(ContainSubstring("nc: timeout")) @@ -96,13 +97,16 @@ func RunNoConnectivityTest(f *framework.Framework, useService bool, listenerSche return listenerPod, connectorPod } -func createPods(f *framework.Framework, useService bool, listenerScheduling framework.NetworkPodScheduling, connectorScheduling framework.NetworkPodScheduling, listenerCluster framework.ClusterIndex, connectorCluster framework.ClusterIndex, connectionTimeout int) (*framework.NetworkPod, *framework.NetworkPod) { +func createPods(f *framework.Framework, useService bool, listenerScheduling framework.NetworkPodScheduling, connectorScheduling framework.NetworkPodScheduling, listenerCluster framework.ClusterIndex, + connectorCluster framework.ClusterIndex, connectionTimeout uint, connectionAttempts uint) (*framework.NetworkPod, *framework.NetworkPod) { + By(fmt.Sprintf("Creating a listener pod in cluster %q, which will wait for a handshake over TCP", framework.TestContext.KubeContexts[listenerCluster])) listenerPod := f.NewNetworkPod(&framework.NetworkPodConfig{ - Type: framework.ListenerPod, - Cluster: listenerCluster, - Scheduling: listenerScheduling, - ConnectionTimeout: connectionTimeout, + Type: framework.ListenerPod, + Cluster: listenerCluster, + Scheduling: listenerScheduling, + ConnectionTimeout: connectionTimeout, + ConnectionAttempts: connectionAttempts, }) remoteIP := listenerPod.Pod.Status.PodIP @@ -116,11 +120,12 @@ func createPods(f *framework.Framework, useService bool, listenerScheduling fram By(fmt.Sprintf("Creating a connector pod in cluster %q, which will attempt the specific UUID handshake over TCP", framework.TestContext.KubeContexts[connectorCluster])) connectorPod := f.NewNetworkPod(&framework.NetworkPodConfig{ - Type: framework.ConnectorPod, - Cluster: connectorCluster, - Scheduling: connectorScheduling, - RemoteIP: remoteIP, - ConnectionTimeout: connectionTimeout, + Type: framework.ConnectorPod, + Cluster: connectorCluster, + Scheduling: connectorScheduling, + RemoteIP: remoteIP, + ConnectionTimeout: connectionTimeout, + ConnectionAttempts: connectionAttempts, }) By(fmt.Sprintf("Waiting for the listener pod %q to exit, returning what listener sent", listenerPod.Pod.Name)) diff --git a/test/e2e/framework/framework.go b/test/e2e/framework/framework.go index d68e8ea8e..8b24179af 100644 --- a/test/e2e/framework/framework.go +++ b/test/e2e/framework/framework.go @@ -331,7 +331,7 @@ func AwaitUntil(opMsg string, doOperation DoOperationFunc, checkResult CheckResu func AwaitResultOrError(opMsg string, doOperation DoOperationFunc, checkResult CheckResultFunc) (interface{}, string, error) { var finalResult interface{} var lastMsg string - err := wait.PollImmediate(5*time.Second, 1*time.Minute, func() (bool, error) { + err := wait.PollImmediate(5*time.Second, time.Duration(TestContext.OperationTimeout)*time.Second, func() (bool, error) { result, err := doOperation() if err != nil { if IsTransientError(err, opMsg) { diff --git a/test/e2e/framework/network_pods.go b/test/e2e/framework/network_pods.go index fe2ca1b07..224db3969 100644 --- a/test/e2e/framework/network_pods.go +++ b/test/e2e/framework/network_pods.go @@ -29,13 +29,14 @@ const ( ) type NetworkPodConfig struct { - Type NetworkPodType - Cluster ClusterIndex - Scheduling NetworkPodScheduling - Port int - Data string - RemoteIP string - ConnectionTimeout int + Type NetworkPodType + Cluster ClusterIndex + Scheduling NetworkPodScheduling + Port int + Data string + RemoteIP string + ConnectionTimeout uint + ConnectionAttempts uint // TODO: namespace, once https://github.com/submariner-io/submariner/pull/141 is merged } @@ -159,7 +160,7 @@ func (np *NetworkPod) buildTCPCheckListenerPod() { Env: []v1.EnvVar{ {Name: "LISTEN_PORT", Value: strconv.Itoa(np.Config.Port)}, {Name: "SEND_STRING", Value: np.Config.Data}, - {Name: "CONN_TIMEOUT", Value: strconv.Itoa(np.Config.ConnectionTimeout)}, + {Name: "CONN_TIMEOUT", Value: strconv.Itoa(int(np.Config.ConnectionTimeout * np.Config.ConnectionAttempts))}, }, }, }, @@ -179,7 +180,6 @@ func (np *NetworkPod) buildTCPCheckListenerPod() { // exit with 0 status func (np *NetworkPod) buildTCPCheckConnectorPod() { - ncatConnectTimeout := 4 // seconds tcpCheckConnectorPod := v1.Pod{ ObjectMeta: metav1.ObjectMeta{ GenerateName: "tcp-check-pod", @@ -201,8 +201,8 @@ func (np *NetworkPod) buildTCPCheckConnectorPod() { {Name: "REMOTE_PORT", Value: strconv.Itoa(np.Config.Port)}, {Name: "SEND_STRING", Value: np.Config.Data}, {Name: "REMOTE_IP", Value: np.Config.RemoteIP}, - {Name: "CONN_TRIES", Value: strconv.Itoa(np.Config.ConnectionTimeout / ncatConnectTimeout)}, - {Name: "CONN_TIMEOUT", Value: strconv.Itoa(ncatConnectTimeout)}, + {Name: "CONN_TRIES", Value: strconv.Itoa(int(np.Config.ConnectionAttempts))}, + {Name: "CONN_TIMEOUT", Value: strconv.Itoa(int(np.Config.ConnectionTimeout))}, }, }, }, diff --git a/test/e2e/framework/test_context.go b/test/e2e/framework/test_context.go index 4d2db8708..94b7c966b 100644 --- a/test/e2e/framework/test_context.go +++ b/test/e2e/framework/test_context.go @@ -16,6 +16,9 @@ type TestContextType struct { ReportDir string ReportPrefix string SubmarinerNamespace string + ConnectionTimeout uint + ConnectionAttempts uint + OperationTimeout uint } func (contexts *contextArray) String() string { @@ -36,6 +39,9 @@ func registerFlags(t *TestContextType) { flag.StringVar(&TestContext.ReportPrefix, "report-prefix", "", "Optional prefix for JUnit XML reports. Default is empty, which doesn't prepend anything to the default name.") flag.StringVar(&TestContext.ReportDir, "report-dir", "", "Path to the directory where the JUnit XML reports should be saved. Default is empty, which doesn't generate these reports.") flag.StringVar(&TestContext.SubmarinerNamespace, "submariner-namespace", "submariner", "Namespace in which the submariner components are deployed.") + flag.UintVar(&TestContext.ConnectionTimeout, "connection-timeout", 6, "The timeout in seconds per connection attempt when verifying communication between clusters.") + flag.UintVar(&TestContext.ConnectionAttempts, "connection-attempts", 10, "The number of connection attempts when verifying communication between clusters.") + flag.UintVar(&TestContext.OperationTimeout, "operation-timeout", 60, "The general operation timeout in seconds.") } func validateFlags(t *TestContextType) {