From fe516bc16655e338bce8078c35d618732ab3e40a Mon Sep 17 00:00:00 2001 From: Garrick Aden-Buie Date: Fri, 2 Feb 2024 11:56:41 -0500 Subject: [PATCH 1/2] test(runStaticServer): Improve testing failure when port is in use --- tests/testthat/test-staticServer.R | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/tests/testthat/test-staticServer.R b/tests/testthat/test-staticServer.R index d49b6c94..ead02a6b 100644 --- a/tests/testthat/test-staticServer.R +++ b/tests/testthat/test-staticServer.R @@ -73,16 +73,10 @@ test_that("runStaticServer() throws an error for invalid ports", { test_that("runStaticServer() throws an error if the requested port is used", { on.exit({ stopAllServers() }) # in case of a test failure - find_unsafe_port <- function() { - for (port in unsafe_ports) { - if (!is_port_available(port)) { - return(port) - } - } - } + s1 <- runStaticServer(path_example_site(), background = TRUE, browse = FALSE) expect_error( - runStaticServer(path_example_site(), port = find_unsafe_port(), background = TRUE) + runStaticServer(path_example_site(), port = s1$getPort(), background = TRUE, browse = FALSE) ) }) From bbf849261ceae792ccb49985a5032059ba7e8e30 Mon Sep 17 00:00:00 2001 From: Garrick Aden-Buie Date: Thu, 8 Feb 2024 14:49:59 -0600 Subject: [PATCH 2/2] docs: Add NEWS entry --- NEWS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS.md b/NEWS.md index 6db797b4..bf91d0d8 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,8 @@ * `runStaticServer()` no longer fails if `browse = TRUE` but `utils::browseURL()` is unable to open the server. (#395) +* Improved testing of `runStaticServer()` to accurately test that `runStaticServer()` throws an error when a requested port is not available on FreeBSD. (#396) + # httpuv 1.6.14 * Updated Makevars.ucrt for upcoming release of Rtools (thanks to Tomas Kalibera).