[libgda] PostgreSQL: added tests for multiple simultaneous connections



commit 3f875d66ea8e96cca57fb7416642d85dfbd543b8
Author: Daniel Espinosa <esodan gmail com>
Date:   Fri Aug 2 14:37:55 2019 -0500

    PostgreSQL: added tests for multiple simultaneous connections

 tests/providers/check_postgres.c   |  1 +
 tests/providers/prov-test-common.c | 35 +++++++++++++++++++++++++++++++++++
 tests/providers/prov-test-common.h |  1 +
 tests/test-cnc-utils.c             | 10 +++++-----
 tests/test-cnc-utils.h             |  2 ++
 5 files changed, 44 insertions(+), 5 deletions(-)
---
diff --git a/tests/providers/check_postgres.c b/tests/providers/check_postgres.c
index 53fef8d48..fef2e32bb 100644
--- a/tests/providers/check_postgres.c
+++ b/tests/providers/check_postgres.c
@@ -79,6 +79,7 @@ main (G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv)
                number_failed += prov_test_common_check_data_select ();
     number_failed += prov_test_common_values ();
                number_failed += prov_test_common_clean ();
+    number_failed += priv_test_common_simultaneos_connections ();
        }
 
        g_strfreev (env);
diff --git a/tests/providers/prov-test-common.c b/tests/providers/prov-test-common.c
index 0dc13e480..8810e43b2 100644
--- a/tests/providers/prov-test-common.c
+++ b/tests/providers/prov-test-common.c
@@ -1437,3 +1437,38 @@ prov_test_common_values (void)
 
        return number_failed;
 }
+
+/**
+ * Test multiple simultaneous connections to same database
+ */
+int priv_test_common_simultaneos_connections (void)
+{
+       gchar *str, *upname;
+  const gchar *db_params;
+  GError *error = NULL;
+
+       upname = test_prov_name_upcase (pinfo->id);
+       str = g_strdup_printf ("%s_DBCREATE_PARAMS", upname);
+       db_params = getenv (str);
+  GdaConnection * connections[50];
+  if (db_params) {
+    for (gint i = 0; i < 50; i++) {
+      connections[i] = gda_connection_new_from_string (pinfo->id, db_params,
+                                                           NULL, GDA_CONNECTION_OPTIONS_NONE,
+                                                           &error);
+      if (connections[i] == NULL) {
+        for (gint j = 0; j < (i+1); j++) {
+          g_object_unref (connections[j]);
+        }
+        g_warning ("Error creating connection: %s",
+                 error && error->message ? error->message : "No datail");
+        g_clear_error (&error);
+        return 1;
+      }
+    }
+    for (gint i = 0; i < 50; i++) {
+      g_object_unref (connections[i]);
+    }
+  }
+  return 0;
+}
diff --git a/tests/providers/prov-test-common.h b/tests/providers/prov-test-common.h
index 94867964f..a22a911d7 100644
--- a/tests/providers/prov-test-common.h
+++ b/tests/providers/prov-test-common.h
@@ -39,5 +39,6 @@ int prov_test_common_check_date (void);
 int prov_test_common_clean (void);
 int prov_test_common_check_bigint (void);
 int prov_test_common_values (void);
+int priv_test_common_simultaneos_connections (void);
 
 #endif
diff --git a/tests/test-cnc-utils.c b/tests/test-cnc-utils.c
index d3dd5a763..b9976e3ad 100644
--- a/tests/test-cnc-utils.c
+++ b/tests/test-cnc-utils.c
@@ -74,8 +74,8 @@ cnc_quark_foreach_func (gchar *name, gchar *value, Data1 *data)
        }
 }
 
-static gchar *
-prov_name_upcase (const gchar *prov_name)
+gchar *
+test_prov_name_upcase (const gchar *prov_name)
 {
        gchar *str, *ptr;
 
@@ -107,7 +107,7 @@ test_cnc_open_connection (const gchar *provider, const gchar *dbname, GError **e
        }
 
        /* open connection to database */
-       upname = prov_name_upcase (prov_info->id);
+       upname = test_prov_name_upcase (prov_info->id);
        str = g_strdup_printf ("%s_CNC_PARAMS", upname);
        cnc_params = getenv (str);
        g_free (str);
@@ -208,7 +208,7 @@ test_cnc_setup_connection (const gchar *provider, const gchar *dbname, GError **
        }
 
        /* create database if requested */
-       upname = prov_name_upcase (prov_info->id);
+       upname = test_prov_name_upcase (prov_info->id);
        str = g_strdup_printf ("%s_DBCREATE_PARAMS", upname);
        db_params = getenv (str);
        g_free (str);
@@ -299,7 +299,7 @@ test_cnc_clean_connection (GdaConnection *cnc, GError **error)
 
        prov_id = g_strdup (gda_connection_get_provider_name (cnc));
 
-       upname = prov_name_upcase (prov_id);
+       upname = test_prov_name_upcase (prov_id);
        str = g_strdup_printf ("%s_DONT_REMOVE_DB", upname);
        if (getenv (str))
                destroy_db = FALSE;
diff --git a/tests/test-cnc-utils.h b/tests/test-cnc-utils.h
index 1cf3eedc7..6e3def88a 100644
--- a/tests/test-cnc-utils.h
+++ b/tests/test-cnc-utils.h
@@ -30,4 +30,6 @@ gboolean       test_cnc_clean_connection (GdaConnection *cnc, GError **error);
 
 gboolean       test_cnc_load_data_from_file (GdaConnection *cnc, const gchar *table, const gchar *full_file, 
GError **error);
 
+gchar         *test_prov_name_upcase (const gchar *prov_name);
+
 #endif


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]