[Libosinfo] [libosinfo PATCH 1/2] tests: Avoid re-using the curl handler on URIs tests

Fabiano Fidêncio fidencio at redhat.com
Mon Feb 4 13:44:25 UTC 2019


On CentOS, we've hit an issue that when a curl handler is re-used we end
up receiving malfunctioning responses from NetBSD CDN.

Dan investigated the issue and suggested that the problem may be a
timing issue happening only in certain versions of libcurl (as it only
hit us when testing on el7).

The main difference of a working and a non-working system is that in the
former when trying to re-use connection, we always get it's dead, and a new
connection is opened; while in the latter sometimes the connection is
detected as dead (but sometimes not), causing then the issue described
above when the connection is not detected as dead.

In order to work the issue around, let's no re-use the curl handler but
always open a new one for each of the URIs.

Signed-off-by: Fabiano Fidêncio <fidencio at redhat.com>
---
 tests/test-imageuris.c | 37 ++++++++++++++++++-------------------
 tests/test-mediauris.c | 37 ++++++++++++++++++-------------------
 tests/test-treeuris.c  | 38 ++++++++++++++++++--------------------
 3 files changed, 54 insertions(+), 58 deletions(-)

diff --git a/tests/test-imageuris.c b/tests/test-imageuris.c
index d58df02..4fb0675 100644
--- a/tests/test-imageuris.c
+++ b/tests/test-imageuris.c
@@ -24,7 +24,7 @@
 #include <osinfo/osinfo.h>
 #include <curl/curl.h>
 
-static void test_image(OsinfoImageList *imagelist, GError **error, CURL *curl)
+static void test_image(OsinfoImageList *imagelist, GError **error)
 {
     GList *imageel = NULL, *tmp;
 
@@ -32,6 +32,8 @@ static void test_image(OsinfoImageList *imagelist, GError **error, CURL *curl)
     while (tmp) {
         OsinfoImage *image = tmp->data;
         const gchar *url = osinfo_image_get_url(image);
+        const gchar *debugstr;
+        CURL *curl;
         CURLcode res;
         long response_code;
 
@@ -40,6 +42,19 @@ static void test_image(OsinfoImageList *imagelist, GError **error, CURL *curl)
             continue;
         }
 
+        curl = curl_easy_init();
+        curl_easy_setopt(curl, CURLOPT_NOBODY, 1L);
+        curl_easy_setopt(curl, CURLOPT_TIMEOUT, 60L);
+        curl_easy_setopt(curl, CURLOPT_TCP_KEEPALIVE, 1L);
+        curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
+        curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1L);
+
+        if ((debugstr = g_getenv("LIBOSINFO_TEST_DEBUG"))) {
+            int debug_level = atoi(debugstr);
+
+            curl_easy_setopt(curl, CURLOPT_VERBOSE, debug_level > 0 ? 1L : 0L);
+        }
+
         g_test_message("%s", url);
         curl_easy_setopt(curl, CURLOPT_URL, url);
         res = curl_easy_perform(curl);
@@ -58,6 +73,7 @@ static void test_image(OsinfoImageList *imagelist, GError **error, CURL *curl)
         }
 
         tmp = tmp->next;
+        curl_easy_cleanup(curl);
     }
 
     g_list_free(imageel);
@@ -67,32 +83,15 @@ static void
 test_uris(gconstpointer data)
 {
     OsinfoOs *os = OSINFO_OS(data);
-    CURL *curl;
     GError *error = NULL;
-    const gchar *debugstr;
-
-    curl = curl_easy_init();
-    curl_easy_setopt(curl, CURLOPT_NOBODY, 1L);
-    curl_easy_setopt(curl, CURLOPT_TIMEOUT, 60L);
-    curl_easy_setopt(curl, CURLOPT_TCP_KEEPALIVE, 1L);
-    curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
-    curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1L);
-
-    if ((debugstr = g_getenv("LIBOSINFO_TEST_DEBUG"))) {
-        int debug_level = atoi(debugstr);
-
-        curl_easy_setopt(curl, CURLOPT_VERBOSE, debug_level > 0 ? 1L : 0L);
-    }
 
     OsinfoImageList *imagelist = osinfo_os_get_image_list(os);
 
-    test_image(imagelist, &error, curl);
+    test_image(imagelist, &error);
 
     g_assert_no_error(error);
 
     g_object_unref(imagelist);
-
-    curl_easy_cleanup(curl);
 }
 
 
diff --git a/tests/test-mediauris.c b/tests/test-mediauris.c
index c5cde0d..6d7319c 100644
--- a/tests/test-mediauris.c
+++ b/tests/test-mediauris.c
@@ -24,7 +24,7 @@
 #include <osinfo/osinfo.h>
 #include <curl/curl.h>
 
-static void test_media(OsinfoMediaList *medialist, GError **error, CURL *curl)
+static void test_media(OsinfoMediaList *medialist, GError **error)
 {
     GList *mediael = NULL, *tmp;
 
@@ -32,6 +32,8 @@ static void test_media(OsinfoMediaList *medialist, GError **error, CURL *curl)
     while (tmp) {
         OsinfoMedia *media = tmp->data;
         const gchar *url = osinfo_media_get_url(media);
+        const gchar *debugstr;
+        CURL *curl;
         CURLcode res;
         long response_code;
 
@@ -40,6 +42,19 @@ static void test_media(OsinfoMediaList *medialist, GError **error, CURL *curl)
             continue;
         }
 
+        curl = curl_easy_init();
+        curl_easy_setopt(curl, CURLOPT_NOBODY, 1L);
+        curl_easy_setopt(curl, CURLOPT_TIMEOUT, 60L);
+        curl_easy_setopt(curl, CURLOPT_TCP_KEEPALIVE, 1L);
+        curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
+        curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1L);
+
+        if ((debugstr = g_getenv("LIBOSINFO_TEST_DEBUG"))) {
+            int debug_level = atoi(debugstr);
+
+            curl_easy_setopt(curl, CURLOPT_VERBOSE, debug_level > 0 ? 1L : 0L);
+        }
+
         g_test_message("%s", url);
         curl_easy_setopt(curl, CURLOPT_URL, url);
         res = curl_easy_perform(curl);
@@ -58,6 +73,7 @@ static void test_media(OsinfoMediaList *medialist, GError **error, CURL *curl)
         }
 
         tmp = tmp->next;
+        curl_easy_cleanup(curl);
     }
 
     g_list_free(mediael);
@@ -67,32 +83,15 @@ static void
 test_uris(gconstpointer data)
 {
     OsinfoOs *os = OSINFO_OS(data);
-    CURL *curl;
     GError *error = NULL;
-    const gchar *debugstr;
-
-    curl = curl_easy_init();
-    curl_easy_setopt(curl, CURLOPT_NOBODY, 1L);
-    curl_easy_setopt(curl, CURLOPT_TIMEOUT, 60L);
-    curl_easy_setopt(curl, CURLOPT_TCP_KEEPALIVE, 1L);
-    curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
-    curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1L);
-
-    if ((debugstr = g_getenv("LIBOSINFO_TEST_DEBUG"))) {
-        int debug_level = atoi(debugstr);
-
-        curl_easy_setopt(curl, CURLOPT_VERBOSE, debug_level > 0 ? 1L : 0L);
-    }
 
     OsinfoMediaList *medialist = osinfo_os_get_media_list(os);
 
-    test_media(medialist, &error, curl);
+    test_media(medialist, &error);
 
     g_assert_no_error(error);
 
     g_object_unref(medialist);
-
-    curl_easy_cleanup(curl);
 }
 
 
diff --git a/tests/test-treeuris.c b/tests/test-treeuris.c
index 547696b..42376d9 100644
--- a/tests/test-treeuris.c
+++ b/tests/test-treeuris.c
@@ -24,7 +24,7 @@
 #include <osinfo/osinfo.h>
 #include <curl/curl.h>
 
-static void test_tree(OsinfoTreeList *treelist, GError **error, CURL *curl)
+static void test_tree(OsinfoTreeList *treelist, GError **error)
 {
     GList *treeel = NULL, *tmp;
 
@@ -32,6 +32,8 @@ static void test_tree(OsinfoTreeList *treelist, GError **error, CURL *curl)
     while (tmp) {
         OsinfoTree *tree = tmp->data;
         const gchar *url = osinfo_tree_get_url(tree);
+        const gchar *debugstr;
+        CURL *curl;
         CURLcode res;
         long response_code;
 
@@ -40,6 +42,19 @@ static void test_tree(OsinfoTreeList *treelist, GError **error, CURL *curl)
             continue;
         }
 
+        curl = curl_easy_init();
+        curl_easy_setopt(curl, CURLOPT_NOBODY, 1L);
+        curl_easy_setopt(curl, CURLOPT_TIMEOUT, 60L);
+        curl_easy_setopt(curl, CURLOPT_TCP_KEEPALIVE, 1L);
+        curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
+        curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1L);
+
+        if ((debugstr = g_getenv("LIBOSINFO_TEST_DEBUG"))) {
+            int debug_level = atoi(debugstr);
+
+            curl_easy_setopt(curl, CURLOPT_VERBOSE, debug_level > 0 ? 1L : 0L);
+        }
+
         g_test_message("%s", url);
         curl_easy_setopt(curl, CURLOPT_URL, url);
         res = curl_easy_perform(curl);
@@ -58,6 +73,7 @@ static void test_tree(OsinfoTreeList *treelist, GError **error, CURL *curl)
         }
 
         tmp = tmp->next;
+        curl_easy_cleanup(curl);
     }
 
     g_list_free(treeel);
@@ -67,32 +83,14 @@ static void
 test_uris(gconstpointer data)
 {
     OsinfoOs *os = OSINFO_OS(data);
-    CURL *curl;
     GError *error = NULL;
-    const gchar *debugstr;
-
-    curl = curl_easy_init();
-    curl_easy_setopt(curl, CURLOPT_NOBODY, 1L);
-    curl_easy_setopt(curl, CURLOPT_TIMEOUT, 60L);
-    curl_easy_setopt(curl, CURLOPT_TCP_KEEPALIVE, 1L);
-    curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
-    curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1L);
-
-    if ((debugstr = g_getenv("LIBOSINFO_TEST_DEBUG"))) {
-        int debug_level = atoi(debugstr);
-
-        curl_easy_setopt(curl, CURLOPT_VERBOSE, debug_level > 0 ? 1L : 0L);
-    }
-
     OsinfoTreeList *treelist = osinfo_os_get_tree_list(os);
 
-    test_tree(treelist, &error, curl);
+    test_tree(treelist, &error);
 
     g_assert_no_error(error);
 
     g_object_unref(treelist);
-
-    curl_easy_cleanup(curl);
 }
 
 
-- 
2.20.1




More information about the Libosinfo mailing list