From 25e406cb9dc10b86d0024d85d467f4b8e9468be6 Mon Sep 17 00:00:00 2001 From: weswc Date: Mon, 13 Jul 2026 14:50:47 -0400 Subject: [PATCH 1/2] add mock for multi_add for promise tests --- R/pooled-request.R | 14 +++++++++++++- tests/testthat/test-req-promise.R | 7 ++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/R/pooled-request.R b/R/pooled-request.R index de20ee7da..666b2378c 100644 --- a/R/pooled-request.R +++ b/R/pooled-request.R @@ -78,7 +78,7 @@ PooledRequest <- R6Class( ) handle_preflight(private$req_prep, private$handle) - curl::multi_add( + multi_add( handle = private$handle, pool = pool, data = private$path, @@ -155,3 +155,15 @@ PooledRequest <- R6Class( } ) ) + +# Wrapper around curl::multi_add() so that the pooled (async) request pathway +# has a mockable seam, mirroring curl_fetch() for the synchronous pathway. +multi_add <- function(handle, pool, data, done, fail) { + curl::multi_add( + handle = handle, + pool = pool, + data = data, + done = done, + fail = fail + ) +} diff --git a/tests/testthat/test-req-promise.R b/tests/testthat/test-req-promise.R index c31761d8f..3c8231d56 100644 --- a/tests/testthat/test-req-promise.R +++ b/tests/testthat/test-req-promise.R @@ -191,7 +191,12 @@ test_that("tracing works as expected", { p <- req_perform_promise(request("http://127.0.0.1")) try(extract_promise(p), silent = TRUE) }, - curl_fetch = function(...) abort("Failed to connect") + multi_add = function(handle, pool, data, done, fail) { + fail(structure( + "Failed to connect", + class = c("curl_error_couldnt_connect", "curl_error", "character") + )) + } ) # A request with no parent context. From 455bdc7bfd253881d0919ccae8883cbd0b32b414 Mon Sep 17 00:00:00 2001 From: weswc Date: Mon, 13 Jul 2026 15:28:57 -0400 Subject: [PATCH 2/2] also mock open for connections --- tests/testthat/test-req-perform-connection.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-req-perform-connection.R b/tests/testthat/test-req-perform-connection.R index 82d38b5cf..047c886c2 100644 --- a/tests/testthat/test-req-perform-connection.R +++ b/tests/testthat/test-req-perform-connection.R @@ -162,10 +162,10 @@ test_that("tracing works as expected", { resp <- req_perform_connection(request(url_build(parsed))) close(resp) - # A request with a curl error. + # A request with a curl error with_mocked_bindings( try(req_perform_connection(request("http://127.0.0.1")), silent = TRUE), - curl_fetch = function(...) abort("Failed to connect") + open = function(...) stop("Failed to connect") ) # A request that triggers retries, generating three individual spans.