svn commit: r1920387 - in /apr/apr-util/branches/1.7.x: ./ test/testmemcache.c test/testredis.c

[email protected]
Newsgroups gmane.comp.apache.apr.cvs
Message-ID <[email protected]>
Author: ivan
Date: Mon Sep  2 11:17:02 2024
New Revision: 1920387

URL: http://svn.apache.org/viewvc?rev=1920387&view=rev
Log:
Merge r1902015 from apr/trunk:
* tests: Check for memcache/redis servers only if memcache/redis tests configured
  to run.

Modified:
    apr/apr-util/branches/1.7.x/   (props changed)
    apr/apr-util/branches/1.7.x/test/testmemcache.c
    apr/apr-util/branches/1.7.x/test/testredis.c

Propchange: apr/apr-util/branches/1.7.x/
------------------------------------------------------------------------------
  Merged /apr/apr/trunk:r1902015

Modified: apr/apr-util/branches/1.7.x/test/testmemcache.c
URL: http://svn.apache.org/viewvc/apr/apr-util/branches/1.7.x/test/testmemcache.c?rev=1920387&r1=1920386&r2=1920387&view=diff
==============================================================================
--- apr/apr-util/branches/1.7.x/test/testmemcache.c (original)
+++ apr/apr-util/branches/1.7.x/test/testmemcache.c Mon Sep  2 11:17:02 2024
@@ -125,6 +125,94 @@ static int randval(apr_uint32_t high)
     return i > 0 ? i : 1;
 }
 
+/* use apr_socket stuff to see if there is in fact a memcached server
+ * running on PORT.
+ */
+static apr_status_t check_mc(void)
+{
+    apr_pool_t *pool = p;
+    apr_status_t rv;
+    apr_socket_t *sock = NULL;
+    apr_sockaddr_t *sa;
+    struct iovec vec[2];
+    apr_size_t written;
+    char buf[128];
+    apr_size_t len;
+
+    rv = apr_socket_create(&sock, APR_INET, SOCK_STREAM, 0, pool);
+    if (rv != APR_SUCCESS) {
+        return rv;
+    }
+
+    rv = apr_sockaddr_info_get(&sa, HOST, APR_INET, PORT, 0, pool);
+    if (rv != APR_SUCCESS) {
+        return rv;
+    }
+
+    rv = apr_socket_timeout_set(sock, 1 * APR_USEC_PER_SEC);
+    if (rv != APR_SUCCESS) {
+        return rv;
+    }
+
+    rv = apr_socket_connect(sock, sa);
+    if (rv != APR_SUCCESS) {
+        return rv;
+    }
+
+    rv = apr_socket_timeout_set(sock, -1);
+    if (rv != APR_SUCCESS) {
+        return rv;
+    }
+
+    vec[0].iov_base = "version";
+    vec[0].iov_len = sizeof("version") - 1;
+
+    vec[1].iov_base = "\r\n";
+    vec[1].iov_len = sizeof("\r\n") - 1;
+
+    rv = apr_socket_sendv(sock, vec, 2, &written);
+    if (rv != APR_SUCCESS) {
+        return rv;
+    }
+
+    len = sizeof(buf);
+    rv = apr_socket_recv(sock, buf, &len);
+    if (rv != APR_SUCCESS) {
+        return rv;
+    }
+
+    if (strncmp(buf, "VERSION", sizeof("VERSION") - 1) != 0) {
+        rv = APR_EGENERAL;
+    }
+
+    apr_socket_close(sock);
+    return rv;
+}
+
+static int has_memcache_server()
+{
+    static int has_memcache_server_state = -1;
+
+    if (has_memcache_server_state < 0) {
+        apr_status_t rv;
+
+        /* check for a running memcached on the typical port before
+         * trying to run the tests. succeed if we don't find one.
+         */
+        rv = check_mc();
+        if (rv == APR_SUCCESS) {
+            has_memcache_server_state = 1;
+        }
+        else {
+            has_memcache_server_state = 0;
+            abts_log_message("Error %d occurred attempting to reach memcached "
+                             "on %s:%d.  Skipping apr_memcache tests...",
+                             rv, HOST, PORT);
+        }
+    }
+
+    return has_memcache_server_state;
+}
 /*
  * general test to make sure we can create the memcache struct and add
  * some servers, but not more than we tell it we can add
@@ -140,6 +228,11 @@ static void test_memcache_create(abts_ca
   apr_uint32_t i;
   apr_uint32_t hash;
 
+  if (!has_memcache_server()) {
+      ABTS_SKIP(tc, data, "Memcache server not found.");
+      return;
+  }
+
   rv = apr_memcache_create(pool, max_servers, 0, &memcache);
   ABTS_ASSERT(tc, "memcache create failed", rv == APR_SUCCESS);
 
@@ -208,6 +301,11 @@ static void test_memcache_user_funcs(abt
   my_hash_server_baton *baton =
     apr_pcalloc(pool, sizeof(my_hash_server_baton));
 
+  if (!has_memcache_server()) {
+      ABTS_SKIP(tc, data, "Memcache server not found.");
+      return;
+  }
+
   rv = apr_memcache_create(pool, max_servers, 0, &memcache);
   ABTS_ASSERT(tc, "memcache create failed", rv == APR_SUCCESS);
 
@@ -252,6 +350,11 @@ static void test_memcache_meta(abts_case
     char *result;
     apr_status_t rv;
 
+    if (!has_memcache_server()) {
+        ABTS_SKIP(tc, data, "Memcache server not found.");
+        return;
+    }
+
     rv = apr_memcache_create(pool, 1, 0, &memcache);
     ABTS_ASSERT(tc, "memcache create failed", rv == APR_SUCCESS);
 
@@ -316,6 +419,11 @@ static void test_memcache_addreplace(abt
  char *result;
  apr_size_t len;
 
+  if (!has_memcache_server()) {
+      ABTS_SKIP(tc, data, "Memcache server not found.");
+      return;
+  }
+ 
   rv = apr_memcache_create(pool, 1, 0, &memcache);
   ABTS_ASSERT(tc, "memcache create failed", rv == APR_SUCCESS);
 
@@ -375,6 +483,11 @@ static void test_memcache_incrdecr(abts_
  apr_size_t len;
  apr_uint32_t i;
 
+  if (!has_memcache_server()) {
+      ABTS_SKIP(tc, data, "Memcache server not found.");
+      return;
+  }
+ 
   rv = apr_memcache_create(pool, 1, 0, &memcache);
   ABTS_ASSERT(tc, "memcache create failed", rv == APR_SUCCESS);
 
@@ -427,6 +540,11 @@ static void test_memcache_multiget(abts_
   apr_hash_index_t *hi;
   apr_uint32_t i;
 
+  if (!has_memcache_server()) {
+      ABTS_SKIP(tc, data, "Memcache server not found.");
+      return;
+  }
+
   rv = apr_memcache_create(pool, 1, 0, &memcache);
   ABTS_ASSERT(tc, "memcache create failed", rv == APR_SUCCESS);
 
@@ -495,6 +613,11 @@ static void test_memcache_setget(abts_ca
     char *result;
     apr_size_t len;
 
+    if (!has_memcache_server()) {
+        ABTS_SKIP(tc, data, "Memcache server not found.");
+        return;
+    }
+
     rv = apr_memcache_create(pool, 1, 0, &memcache);
     ABTS_ASSERT(tc, "memcache create failed", rv == APR_SUCCESS);
 
@@ -538,70 +661,6 @@ static void test_memcache_setget(abts_ca
     }
 }
 
-/* use apr_socket stuff to see if there is in fact a memcached server
- * running on PORT.
- */
-static apr_status_t check_mc(void)
-{
-  apr_pool_t *pool = p;
-  apr_status_t rv;
-  apr_socket_t *sock = NULL;
-  apr_sockaddr_t *sa;
-  struct iovec vec[2];
-  apr_size_t written;
-  char buf[128];
-  apr_size_t len;
-
-  rv = apr_socket_create(&sock, APR_INET, SOCK_STREAM, 0, pool);
-  if(rv != APR_SUCCESS) {
-    return rv;
-  }
-
-  rv = apr_sockaddr_info_get(&sa, HOST, APR_INET, PORT, 0, pool);
-  if(rv != APR_SUCCESS) {
-    return rv;
-  }
-
-  rv = apr_socket_timeout_set(sock, 1 * APR_USEC_PER_SEC);
-  if (rv != APR_SUCCESS) {
-    return rv;
-  }
-
-  rv = apr_socket_connect(sock, sa);
-  if (rv != APR_SUCCESS) {
-    return rv;
-  }
-
-  rv = apr_socket_timeout_set(sock, -1);
-  if (rv != APR_SUCCESS) {
-    return rv;
-  }
-
-  vec[0].iov_base = "version";
-  vec[0].iov_len  = sizeof("version") - 1;
-
-  vec[1].iov_base = "\r\n";
-  vec[1].iov_len  = sizeof("\r\n") -1;
-
-  rv = apr_socket_sendv(sock, vec, 2, &written);
-  if (rv != APR_SUCCESS) {
-    return rv;
-  }
-
-  len = sizeof(buf);
-  rv = apr_socket_recv(sock, buf, &len);
-  if(rv != APR_SUCCESS) {
-    return rv;
-  }
-
-  if(strncmp(buf, "VERSION", sizeof("VERSION")-1) != 0) {
-    rv = APR_EGENERAL;
-  }
-
-  apr_socket_close(sock);
-  return rv;
-}
-
 static void test_connection_validation(abts_case *tc, void *data)
 {
     apr_status_t rv;
@@ -675,24 +734,13 @@ abts_suite *testmemcache(abts_suite * su
 {
     apr_status_t rv;
     suite = ADD_SUITE(suite);
-    /* check for a running memcached on the typical port before
-     * trying to run the tests. succeed if we don't find one.
-     */
-    rv = check_mc();
-    if (rv == APR_SUCCESS) {
-      abts_run_test(suite, test_memcache_create, NULL);
-      abts_run_test(suite, test_memcache_user_funcs, NULL);
-      abts_run_test(suite, test_memcache_meta, NULL);
-      abts_run_test(suite, test_memcache_setget, NULL);
-      abts_run_test(suite, test_memcache_multiget, NULL);
-      abts_run_test(suite, test_memcache_addreplace, NULL);
-      abts_run_test(suite, test_memcache_incrdecr, NULL);
-    }
-    else {
-        abts_log_message("Error %d occurred attempting to reach memcached "
-                         "on %s:%d.  Skipping apr_memcache tests...",
-                         rv, HOST, PORT);
-    }
+    abts_run_test(suite, test_memcache_create, NULL);
+    abts_run_test(suite, test_memcache_user_funcs, NULL);
+    abts_run_test(suite, test_memcache_meta, NULL);
+    abts_run_test(suite, test_memcache_setget, NULL);
+    abts_run_test(suite, test_memcache_multiget, NULL);
+    abts_run_test(suite, test_memcache_addreplace, NULL);
+    abts_run_test(suite, test_memcache_incrdecr, NULL);
     abts_run_test(suite, test_connection_validation, NULL);
 
     return suite;

Modified: apr/apr-util/branches/1.7.x/test/testredis.c
URL: http://svn.apache.org/viewvc/apr/apr-util/branches/1.7.x/test/testredis.c?rev=1920387&r1=1920386&r2=1920387&view=diff
==============================================================================
--- apr/apr-util/branches/1.7.x/test/testredis.c (original)
+++ apr/apr-util/branches/1.7.x/test/testredis.c Mon Sep  2 11:17:02 2024
@@ -123,6 +123,96 @@ static int randval(apr_uint32_t high)
     return i > 0 ? i : 1;
 }
 
+/* use apr_socket stuff to see if there is in fact a Redis server
+ * running on PORT.
+ */
+static apr_status_t check_redis(void)
+{
+    apr_pool_t *pool = p;
+    apr_status_t rv;
+    apr_socket_t *sock = NULL;
+    apr_sockaddr_t *sa;
+    struct iovec vec[2];
+    apr_size_t written;
+    char buf[128];
+    apr_size_t len;
+
+    rv = apr_socket_create(&sock, APR_INET, SOCK_STREAM, 0, pool);
+    if (rv != APR_SUCCESS) {
+        return rv;
+    }
+
+    rv = apr_sockaddr_info_get(&sa, HOST, APR_INET, PORT, 0, pool);
+    if (rv != APR_SUCCESS) {
+        return rv;
+    }
+
+    rv = apr_socket_timeout_set(sock, 1 * APR_USEC_PER_SEC);
+    if (rv != APR_SUCCESS) {
+        return rv;
+    }
+
+    rv = apr_socket_connect(sock, sa);
+    if (rv != APR_SUCCESS) {
+        return rv;
+    }
+
+    rv = apr_socket_timeout_set(sock, -1);
+    if (rv != APR_SUCCESS) {
+        return rv;
+    }
+
+    vec[0].iov_base = "PING";
+    vec[0].iov_len = sizeof("PING") - 1;
+
+    vec[1].iov_base = "\r\n";
+    vec[1].iov_len = sizeof("\r\n") - 1;
+
+    rv = apr_socket_sendv(sock, vec, 2, &written);
+    if (rv != APR_SUCCESS) {
+        return rv;
+    }
+
+    len = sizeof(buf);
+    rv = apr_socket_recv(sock, buf, &len);
+    if (rv != APR_SUCCESS) {
+        return rv;
+    }
+    if (strncmp(buf, "+PONG", sizeof("+PONG") - 1) != 0) {
+        rv = APR_EGENERAL;
+    }
+
+    apr_socket_close(sock);
+    return rv;
+}
+
+static int has_redis_server()
+{
+    static int has_redis_server_state = -1;
+
+    if (has_redis_server_state < 0) {
+        apr_status_t rv;
+
+        /* check for a running redis on the typical port before
+         * trying to run the tests. succeed if we don't find one.
+         */
+        rv = check_redis();
+
+        if (rv == APR_SUCCESS) {
+            has_redis_server_state = 1;
+        }
+        else {
+            has_redis_server_state = 0;
+
+            abts_log_message("Error %d occurred attempting to reach Redis "
+                             "on %s:%d.  Skipping apr_redis tests...",
+                             rv, HOST, PORT);
+        }
+    }
+
+    return has_redis_server_state;
+}
+
 /*
  * general test to make sure we can create the redis struct and add
  * some servers, but not more than we tell it we can add
@@ -138,6 +228,11 @@ static void test_redis_create(abts_case
   apr_uint32_t i;
   apr_uint32_t hash;
 
+  if (!has_redis_server()) {
+      ABTS_SKIP(tc, data, "Redis server not found.");
+      return;
+  }
+
   rv = apr_redis_create(pool, max_servers, 0, &redis);
   ABTS_ASSERT(tc, "redis create failed", rv == APR_SUCCESS);
   
@@ -206,6 +301,11 @@ static void test_redis_user_funcs(abts_c
   my_hash_server_baton *baton = 
     apr_pcalloc(pool, sizeof(my_hash_server_baton));
 
+  if (!has_redis_server()) {
+      ABTS_SKIP(tc, data, "Redis server not found.");
+      return;
+  }
+
   rv = apr_redis_create(pool, max_servers, 0, &redis);
   ABTS_ASSERT(tc, "redis create failed", rv == APR_SUCCESS);
 
@@ -250,6 +350,11 @@ static void test_redis_meta(abts_case *
     char *result;
     apr_status_t rv;
 
+    if (!has_redis_server()) {
+        ABTS_SKIP(tc, data, "Redis server not found.");
+        return;
+    }
+
     rv = apr_redis_create(pool, 1, 0, &redis);
     ABTS_ASSERT(tc, "redis create failed", rv == APR_SUCCESS);
 
@@ -306,6 +411,11 @@ static void test_redis_incrdecr(abts_cas
  apr_size_t len;
  apr_uint32_t i;
 
+ if (!has_redis_server()) {
+     ABTS_SKIP(tc, data, "Redis server not found.");
+     return;
+ }
+  
   rv = apr_redis_create(pool, 1, 0, &redis);
   ABTS_ASSERT(tc, "redis create failed", rv == APR_SUCCESS);
   
@@ -361,6 +471,11 @@ static void test_redis_setget(abts_case
     char *result;
     apr_size_t len;
 
+    if (!has_redis_server()) {
+        ABTS_SKIP(tc, data, "Redis server not found.");
+        return;
+    }
+
     rv = apr_redis_create(pool, 1, 0, &redis);
     ABTS_ASSERT(tc, "redis create failed", rv == APR_SUCCESS);
 
@@ -417,6 +532,11 @@ static void test_redis_setexget(abts_cas
     char *result;
     apr_size_t len;
 
+    if (!has_redis_server()) {
+        ABTS_SKIP(tc, data, "Redis server not found.");
+        return;
+    }
+
     rv = apr_redis_create(pool, 1, 0, &redis);
     ABTS_ASSERT(tc, "redis create failed", rv == APR_SUCCESS);
 
@@ -462,91 +582,18 @@ static void test_redis_setexget(abts_cas
     }
 }
 
-/* use apr_socket stuff to see if there is in fact a Redis server
- * running on PORT.
- */
-static apr_status_t check_redis(void)
-{
-  apr_pool_t *pool = p;
-  apr_status_t rv;
-  apr_socket_t *sock = NULL;
-  apr_sockaddr_t *sa;
-  struct iovec vec[2];
-  apr_size_t written;
-  char buf[128];
-  apr_size_t len;
-
-  rv = apr_socket_create(&sock, APR_INET, SOCK_STREAM, 0, pool);
-  if(rv != APR_SUCCESS) {
-    return rv;
-  }
-
-  rv = apr_sockaddr_info_get(&sa, HOST, APR_INET, PORT, 0, pool);
-  if(rv != APR_SUCCESS) {
-    return rv;
-  }
-
-  rv = apr_socket_timeout_set(sock, 1 * APR_USEC_PER_SEC);
-  if (rv != APR_SUCCESS) {
-    return rv;
-  }
-
-  rv = apr_socket_connect(sock, sa);
-  if (rv != APR_SUCCESS) {
-    return rv;
-  }
-
-  rv = apr_socket_timeout_set(sock, -1);
-  if (rv != APR_SUCCESS) {
-    return rv;
-  }
-
-  vec[0].iov_base = "PING";
-  vec[0].iov_len  = sizeof("PING") - 1;
-
-  vec[1].iov_base = "\r\n";
-  vec[1].iov_len  = sizeof("\r\n") -1;
-
-  rv = apr_socket_sendv(sock, vec, 2, &written);
-  if (rv != APR_SUCCESS) {
-    return rv;
-  }
-
-  len = sizeof(buf);
-  rv = apr_socket_recv(sock, buf, &len);
-  if(rv != APR_SUCCESS) {
-    return rv;
-  }
-  if(strncmp(buf, "+PONG", sizeof("+PONG")-1) != 0) {
-    rv = APR_EGENERAL;
-  }
-
-  apr_socket_close(sock);
-  return rv;
-}
-
 abts_suite *testredis(abts_suite * suite)
 {
     apr_status_t rv;
     suite = ADD_SUITE(suite);
-    /* check for a running redis on the typical port before
-     * trying to run the tests. succeed if we don't find one.
-     */
-    rv = check_redis();
-    if (rv == APR_SUCCESS) {
-        abts_run_test(suite, test_redis_create, NULL);
-        abts_run_test(suite, test_redis_user_funcs, NULL);
-        abts_run_test(suite, test_redis_meta, NULL);
-        abts_run_test(suite, test_redis_setget, NULL);
-        abts_run_test(suite, test_redis_setexget, NULL);
-        /* abts_run_test(suite, test_redis_multiget, NULL); */
-        abts_run_test(suite, test_redis_incrdecr, NULL);
-    }
-    else {
-        abts_log_message("Error %d occurred attempting to reach Redis "
-                         "on %s:%d.  Skipping apr_redis tests...",
-                         rv, HOST, PORT);
-    }
+
+    abts_run_test(suite, test_redis_create, NULL);
+    abts_run_test(suite, test_redis_user_funcs, NULL);
+    abts_run_test(suite, test_redis_meta, NULL);
+    abts_run_test(suite, test_redis_setget, NULL);
+    abts_run_test(suite, test_redis_setexget, NULL);
+    /* abts_run_test(suite, test_redis_multiget, NULL); */
+    abts_run_test(suite, test_redis_incrdecr, NULL);
 
     return suite;
 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.