nealrichardson / httptest2

Utilities for testing R 📦s that use httr2
https://enpiar.com/httptest2/
Other
26 stars 5 forks source link

Support for recording requests made in parallel #46

Closed MMenchero closed 2 weeks ago

MMenchero commented 2 weeks ago

Description

I developed an R package that sends requests to a remote server. I then used httptest2 to record mock files for my package's vignettes. This setup worked correctly until I implemented parallel processing to my package, using the future and the future.apply packages. Although the requests return the expected responses when executed in parallel, I am no longer able to record these responses as mock files. If I revert to a version of my package without parallel processing, the recording of mock files works as expected.

Given this situation, I am curious to know whether httptest2 supports recording requests made in parallel. If it does, I would appreciate guidance on where the mock files might be located, as I can't find them anywhere.

nealrichardson commented 2 weeks ago

I'm not sure how future* packages would affect this, but if you can't find where your mocks are being recorded to, you can set options(httptest2.verbose = TRUE) to print the paths it writes. See https://enpiar.com/httptest2/articles/faq.html#where-are-my-mocks-recorded

I haven't experimented with either, but you may also want to look at https://httr2.r-lib.org/reference/req_perform_parallel.html for parallel requests.

MMenchero commented 2 weeks ago

Thanks for the quick response, @nealrichardson. Unfortunately, I'm still not getting any results even after setting options(httptest2.verbose = TRUE). For now, I have implemented both a sequential and a parallel version of my package's functions, which seems to prevent the issue with the mock files.

I also reviewed the documentation for req_perform_parallel, but it doesn't support retries with req_retry, a feature I currently use.

I'll continue working on my package, and if I manage to find a solution, I'll report back. However, for now, I think we can close this issue, as I'm not certain how the future packages might be interfering with httptest2, if at all.

nealrichardson commented 2 weeks ago

Sounds good! Keep me posted on what you learn.