New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add skip_if_offline() #685
Comments
httptest provides a similar It uses One nice feature of |
@nealrichardson Unfortunately the In particular, if the hostname is in the DNS cache, but it is unreachable, Also, AFAIR the Btw. |
@gaborcsardi Thanks, that's good to know about the |
Feels like there are 3 components:
|
I have used variants of this without problems for years: has_internet <- function() {
!is.null(suppressWarnings(utils::nsl("www.google.com")))
}
skip_if_no_internet <- function() {
if (has_internet()) {
return()
}
testthat::skip("no internet")
} I'm sure there are cases where it can hang badly on poor connections or give false positive/negatives but I work a lot from trains and it seems to work |
@richfitz yeah, that's better than |
Do others agree it's a good idea to determine offline status for a test run vs individual tests? I can make a case for that, if necessary. But under that assumption, if |
Just in case this goes through, I looked up |
So yeah, it is not a good option, I am afraid. Thanks for reminding! |
Re: determining offline status once per run vs. once per test, seems not too difficult to memoize the result one way or another ( |
If I'm running all the tests on an API wrapping package, I want a uniform situation wrt to skipping tests due to being offline, because it makes the overall result easier to interpret. I have found that very sporadic internet problems can trigger a skip here and there and then ... I feel like I have to rerun the tests. But agree it's not clear if the added complexity is worth it. |
One could make the case that network/API flakiness means you should check connectivity closer to each test to rule out the scenario where the check at the beginning passed but then the connection dropped later in the run. Flaky skips are bad, but flaky failures are worse. So, what if we could have it both ways? Then we've at least reduced the question to how best to determine network status: what goes in |
This is useful for packages which test against online APIs. We use `curl::nslookup()` rather than `utils::nsl()` because the latter is not available on Windows. Fixes r-lib#685
Would a PR to add something like this be accepted? I suppose the ping-ee should be settable, possibly defaulting to google.
I'm using it in googledrive and adapted it from something @gaborcsardi did in gh.
It means Importing or Suggesting pingr, which doesn't have any dependencies but does require compilation.
The text was updated successfully, but these errors were encountered: