apr_reslist: test for ttl = 0
The current reslist implementation handles ttl=0 as no TTL when acquiring
resources (expected and documented), but as zero TTL when releasing (immediate
expiry, so resources above smax are never recycled).
This test validates the upcoming fix (r1834023).
@@ -258,6 +258,44 @@ static void test_reslist(abts_case *tc, void *data)
ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
}
+static void test_reslist_no_ttl(abts_case *tc, void *data)
+{
+ apr_status_t rv;
+ apr_reslist_t *rl;
+ my_parameters_t *params;
+ my_resource_t *res;
+
+ /* Parameters (sleep not used) */
+ params = apr_pcalloc(p, sizeof(*params));
+
+ rv = apr_reslist_create(&rl,
+ /*no min*/0, /*no smax*/0, /*max*/1, /*no ttl*/0,
+ my_constructor, my_destructor, params, p);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+ /* Acquire/contruct one resource */
+ rv = apr_reslist_acquire(rl, (void **)&res);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+ ABTS_INT_EQUAL(tc, 0, res->id);
+
+ /* Release it before next check */
+ rv = apr_reslist_release(rl, res);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+ /* Re-acquire/release: the resource should be the same */
+ rv = apr_reslist_acquire(rl, (void **)&res);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+ ABTS_INT_EQUAL(tc, 0, res->id);
+
+ /* Release it before cleanup */
+ rv = apr_reslist_release(rl, res);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+ rv = apr_reslist_destroy(rl);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+ ABTS_INT_EQUAL(tc, params->d_count, 1);
+}
+
#endif /* APR_HAS_THREADS */
abts_suite *testreslist(abts_suite *suite)
@@ -266,6 +304,7 @@ abts_suite *testreslist(abts_suite *suite)
#if APR_HAS_THREADS
abts_run_test(suite, test_reslist, NULL);
+ abts_run_test(suite, test_reslist_no_ttl, NULL);
#endif
return suite;
