apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rpl...@apache.org
Subject svn commit: r565290 - /apr/apr-util/branches/1.2.x/test/testreslist.c
Date Mon, 13 Aug 2007 10:06:28 GMT
Author: rpluem
Date: Mon Aug 13 03:06:27 2007
New Revision: 565290

URL: http://svn.apache.org/viewvc?view=rev&rev=565290
Log:
Merge r563104 from trunk:

* Add a test case for PR 40348.

Submitted by: rpluem
Reviewed by: pluem

Modified:
    apr/apr-util/branches/1.2.x/test/testreslist.c

Modified: apr/apr-util/branches/1.2.x/test/testreslist.c
URL: http://svn.apache.org/viewvc/apr/apr-util/branches/1.2.x/test/testreslist.c?view=diff&rev=565290&r1=565289&r2=565290
==============================================================================
--- apr/apr-util/branches/1.2.x/test/testreslist.c (original)
+++ apr/apr-util/branches/1.2.x/test/testreslist.c Mon Aug 13 03:06:27 2007
@@ -185,6 +185,60 @@
     }
 }
 
+static void test_shrinking(apr_reslist_t *rl)
+{
+    apr_status_t rv;
+    my_resource_t *resources[RESLIST_HMAX];
+    my_resource_t *res;
+    int i;
+    int sleep_time = RESLIST_TTL / RESLIST_HMAX;
+
+    /* deplete all possible resources from the resource list */
+    for (i = 0; i < RESLIST_HMAX; i++) {
+        rv = apr_reslist_acquire(rl, (void**)&resources[i]);
+        if (rv != APR_SUCCESS) {
+            fprintf(stderr, "couldn't acquire resource: %d\n", rv);
+            exit(1);
+        }
+    }
+
+    /* Free all resources above RESLIST_SMAX - 1 */
+    for (i = RESLIST_SMAX - 1; i < RESLIST_HMAX; i++) {
+        rv = apr_reslist_release(rl, resources[i]);
+        if (rv != APR_SUCCESS) {
+            fprintf(stderr, "couldn't release resource: %d\n", rv);
+            exit(1);
+        }
+    }
+
+    for (i = 0; i < RESLIST_HMAX; i++) {
+        rv = apr_reslist_acquire(rl, (void**)&res);
+        if (rv != APR_SUCCESS) {
+            fprintf(stderr, "couldn't acquire resource: %d\n", rv);
+            exit(1);
+        }
+        apr_sleep(sleep_time);
+        rv = apr_reslist_release(rl, res);
+        if (rv != APR_SUCCESS) {
+            fprintf(stderr, "couldn't release resource: %d\n", rv);
+            exit(1);
+        }
+    }
+    apr_sleep(sleep_time);
+
+    /*
+     * Now free the remaining elements. This should trigger the shrinking of
+     * the list
+     */
+    for (i = 0; i < RESLIST_SMAX - 1; i++) {
+        rv = apr_reslist_release(rl, resources[i]);
+        if (rv != APR_SUCCESS) {
+            fprintf(stderr, "couldn't release resource: %d\n", rv);
+            exit(1);
+        }
+    }
+}
+
 static apr_status_t test_reslist(apr_pool_t *parpool)
 {
     apr_status_t rv;
@@ -253,6 +307,15 @@
     printf("\nDone!\n");
 
     test_timeout(rl);
+
+    test_shrinking(rl);
+    if (params->c_count - params->d_count != RESLIST_SMAX) {
+        printf("FAILED: Resourcelist has not shrinked back to RESLIST_SMAX\n");
+        return APR_EGENERAL;
+    }
+    else {
+        printf("OK: Resource list shrinked back to RESLIST_SMAX\n");
+    }
 
     printf("Destroying resource list.................");
     rv = apr_reslist_destroy(rl);



Mime
View raw message