lib2405: adjust for non-threaded builds

- Attempt to fix the flakiness set in 9726fc8259
- Reduce macro use

Closes #22414
This commit is contained in:
Daniel Stenberg 2026-07-28 11:53:42 +02:00
parent 27a4557c9e
commit c7328740ec
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
3 changed files with 44 additions and 27 deletions

View file

@ -4,7 +4,6 @@
<keywords>
multi
HTTP
flaky
</keywords>
</info>

View file

@ -5,7 +5,6 @@
multi
HTTP
HTTP/2
flaky
</keywords>
</info>

View file

@ -41,24 +41,6 @@
/* ---------------------------------------------------------------- */
#define test_check(expected_fds) \
if(result != CURLE_OK) { \
curl_mfprintf(stderr, "test failed with code: %d\n", (int)result); \
goto test_cleanup; \
} \
else if(fd_count != (expected_fds)) { \
curl_mfprintf(stderr, "Max number of waitfds: %u not as expected: %u\n", \
fd_count, expected_fds); \
result = TEST_ERR_FAILURE; \
goto test_cleanup; \
}
#define test_run_check(option, expected_fds) \
do { \
result = test_run(URL, option, &fd_count); \
test_check(expected_fds); \
} while(0)
/* ---------------------------------------------------------------- */
enum {
@ -302,6 +284,22 @@ test_cleanup:
return result;
}
static CURLcode test_run_check(const char *URL, long option,
unsigned int expected_fds)
{
unsigned int fd_count = 0;
CURLcode result = test_run(URL, option, &fd_count);
if(result)
curl_mfprintf(stderr, "test failed with code: %d\n", (int)result);
else if(fd_count != expected_fds) {
curl_mfprintf(stderr,
"Max number of waitfds: %u not as expected: %u\n",
fd_count, expected_fds);
result = TEST_ERR_FAILURE;
}
return result;
}
static CURLcode empty_multi_test(void)
{
CURLMcode mresult = CURLM_OK;
@ -360,29 +358,50 @@ test_cleanup:
return result;
}
static unsigned int uses_threaded(void)
{
curl_version_info_data *ver = curl_version_info(CURLVERSION_NOW);
const char * const *n = ver->feature_names;
int i;
unsigned int uses = 0;
/* the 'asyn-rr' feature tells us libcurl uses the threaded resolver */
for(i = 0; n[i]; i++) {
if(!strcmp("asyn-rr", n[i]))
uses = 1;
}
/* if not using asyn-rr, check if doing asynch DNS without using c-ares */
if(!uses && (ver->features & CURL_VERSION_ASYNCHDNS) && !ver->ares)
uses = 1;
return uses;
}
static CURLcode test_lib2405(const char *URL)
{
CURLcode result = CURLE_OK;
unsigned int fd_count = 0;
int uses_threaded_resolver;
global_init(CURL_GLOBAL_ALL);
uses_threaded_resolver = uses_threaded();
/* Testing curl_multi_waitfds on empty and not started handles */
result = empty_multi_test();
if(result != CURLE_OK)
goto test_cleanup;
if(testnum == 2405) {
/* HTTP1, expected 3 waitfds - one for each transfer + wakeup */
test_run_check(TEST_USE_HTTP1, 3U);
/* HTTP1, one for each transfer + possible wakeup */
result = test_run_check(URL, TEST_USE_HTTP1, 2 + uses_threaded_resolver);
}
#ifdef USE_HTTP2
else { /* 2407 */
/* HTTP2, expected 3 waitfds - one for each transfer + wakeup */
test_run_check(TEST_USE_HTTP2, 3U);
/* HTTP2, one for each transfer + possible wakeup */
result = test_run_check(URL, TEST_USE_HTTP2, 2 + uses_threaded_resolver);
/* HTTP2 with multiplexing, expected 2 waitfds - transfers + wakeup */
test_run_check(TEST_USE_HTTP2_MPLEX, 2U);
/* HTTP2 with multiplexing, expected one waitfds + possible wakeup */
if(!result)
result = test_run_check(URL, TEST_USE_HTTP2_MPLEX,
1 + uses_threaded_resolver);
}
#endif