[X2Go-Commits] [libx2goclient] 10/132: src/test/sshtest.c: split up connection testing and create connect-connect-disconnect-connect cycle.

git-admin at x2go.org git-admin at x2go.org
Fri Dec 3 15:26:28 CET 2021


This is an automated email from the git hooks/post-receive script.

x2go pushed a commit to branch master
in repository libx2goclient.

commit 4477232a05841f048a3d7cbfd5e6e577ecefbf16
Author: Mihai Moldovan <ionic at ionic.de>
Date:   Sat Oct 31 03:42:12 2020 +0100

    src/test/sshtest.c: split up connection testing and create connect-connect-disconnect-connect cycle.
---
 src/test/sshtest.c | 70 ++++++++++++++++++++++++++++++++++++++++++------------
 1 file changed, 55 insertions(+), 15 deletions(-)

diff --git a/src/test/sshtest.c b/src/test/sshtest.c
index 200ebc9..710b6a1 100644
--- a/src/test/sshtest.c
+++ b/src/test/sshtest.c
@@ -220,15 +220,17 @@ static _Bool test_x2goclient_network_ssh_connect_after_connect (X2GoClientNetwor
   return (ret);
 }
 
-static _Bool test_x2goclient_network_ssh_connect (X2GoClientNetworkSSH *net_ssh) {
-  _Bool ret = TRUE;
+static _Bool test_x2goclient_network_ssh_connect (X2GoClientNetworkSSH *net_ssh, gboolean * const conn_ret) {
+  _Bool ret = (!(!(conn_ret)));
 
-  /* Actually connect. */
-  g_printf ("Trying to connect...\n");
-  gboolean conn_ret = x2goclient_network_ssh_connect (net_ssh, NULL);
-  g_printf ("Connection status: %s.\n", x2goclient_bool_to_str (conn_ret));
+  if (ret) {
+    /* Actually connect. */
+    g_printf ("Trying to connect...\n");
+    (*conn_ret) = x2goclient_network_ssh_connect (net_ssh, NULL);
+    g_printf ("Connection status: %s.\n", x2goclient_bool_to_str (*conn_ret));
+  }
 
-  ret &= conn_ret;
+  ret &= (*conn_ret);
 
   if (ret) {
     /* Check connection status getter sync. */
@@ -236,15 +238,29 @@ static _Bool test_x2goclient_network_ssh_connect (X2GoClientNetworkSSH *net_ssh)
     g_object_get (G_OBJECT (net_ssh), "connected", &conn_ret_new, NULL);
     g_printf ("Current connection status (via getter): %s\n", x2goclient_bool_to_str (conn_ret_new));
 
-    ret &= (conn_ret == conn_ret_new);
+    ret &= ((*conn_ret) == conn_ret_new);
   }
 
-  /*
-   * Cannot move this to test_x2goclient_network_ssh because we need conn_ret.
-   * Bummer, but likely not too bad.
-   */
+  return (ret);
+}
+
+static _Bool test_x2goclient_network_ssh_disconnect (X2GoClientNetworkSSH *net_ssh) {
+  _Bool ret = TRUE;
+
+  /* Actually disconnect. */
+  g_printf ("Trying to disconnect...\n");
+  gboolean disconn_ret = x2goclient_network_ssh_disconnect (net_ssh, NULL);
+  g_printf ("Disconnection status: %s.\n", x2goclient_bool_to_str (disconn_ret));
+
+  ret &= disconn_ret;
+
   if (ret) {
-    ret &= test_x2goclient_network_ssh_connect_after_connect (net_ssh, conn_ret);
+    /* Check connection status getter sync. */
+    gboolean conn_ret_new = FALSE;
+    g_object_get (G_OBJECT (net_ssh), "connected", &conn_ret_new, NULL);
+    g_printf ("Current connection status (via getter): %s\n", x2goclient_bool_to_str (conn_ret_new));
+
+    ret &= (disconn_ret == (!(conn_ret_new)));
   }
 
   return (ret);
@@ -276,13 +292,37 @@ static _Bool test_x2goclient_network_ssh (const GString * const ssh_uri) {
     ret &= test_x2goclient_network_ssh_set_conn_ret (net_ssh);
   }
 
+  /* We'll use that for the connect-after-connect test. */
+  gboolean conn_ret = FALSE;
+
   if (ret) {
-    ret &= test_x2goclient_network_ssh_connect (net_ssh);
+    ret &= test_x2goclient_network_ssh_connect (net_ssh, &conn_ret);
+  }
+
+  if (ret) {
+    ret &= test_x2goclient_network_ssh_connect_after_connect (net_ssh, conn_ret);
+  }
+
+  if (ret) {
+    /* Let ssh connection live for a few seconds, give or take. */
+    sleep (15);
+  }
+
+  if (ret) {
+    ret &= test_x2goclient_network_ssh_disconnect (net_ssh);
+  }
+
+  if (ret) {
+    /*
+     * Connect again, checking whether a connect-disconnect-connect cycle works
+     * correctly.
+     */
+    ret &= test_x2goclient_network_ssh_connect (net_ssh, &conn_ret);
   }
 
   if (ret) {
     /* Let ssh connection live for a few seconds, give or take. */
-    sleep (30);
+    sleep (15);
   }
 
   g_clear_object (&net_ssh);

--
Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/libx2goclient.git


More information about the x2go-commits mailing list