PIP-Technical-Team / pipapi

What the Package Does (One Line, Title Case)
https://pip-technical-team.github.io/pipapi/
Other
3 stars 0 forks source link

Unit tests in `test-plumber-future.R` doesn't work #238

Open Aeilert opened 2 years ago

Aeilert commented 2 years ago

The unit tests to explicitly test the async parallel feature for the slow plumber endpoints no longer works for me locally. Flagging this since they test an important feature.

Basically the API doesn't start within future.callr::callr() even though the process it self is running. Tried a few different setups for this work, but so far unsuccessful.

In the initial PR these tests worked, so not sure what happened.

api1 <- future.callr::callr(function() {
  library(pipapi)
  lkups <<- pipapi::create_versioned_lkups(Sys.getenv("PIPAPI_DATA_ROOT_FOLDER"))
  pipapi::start_api(port = 8000)
}, workers = 2, # n workers for API
   #globals = list(lkups = lkups),
   #packages = c("pipapi")
)

cc: @tonyfujs

tonyfujs commented 2 years ago

@shahronak47 Can you check that you are able to run this test locally? I think this may be related to WB laptops security settings

shahronak47 commented 2 years ago

For me locally, this line works -

# Setup by starting APIs
root_path <- "http://localhost"
api1 <- future.callr::callr(function() {
  library(pipapi)
  lkups <<- pipapi::create_versioned_lkups(Sys.getenv("PIPAPI_DATA_ROOT_FOLDER"))
  pipapi::start_api(port = 8000)
}, workers = 2, # n workers for API
   #globals = list(lkups = lkups),
   #packages = c("pipapi")
)

By works, I mean I do not get any error/warning message.

This is the what it returns -

api1

#CallrFuture:
#Label: ‘<none>’
#Expression:
#function() {
#   library(pipapi)
#  lkups <<- pipapi::create_versioned_lkups(Sys.getenv("PIPAPI_DATA_ROOT_FOLDER"))
#    pipapi::start_api(port = 8000)
#}
#Lazy evaluation: FALSE
#Asynchronous evaluation: TRUE
#Local evaluation: TRUE
#Environment: R_GlobalEnv
#Capture standard output: TRUE
#Capture condition classes: ‘condition’ (excluding ‘nothing’)
#Globals: <none>
#Packages: <none>
#L'Ecuyer-CMRG RNG seed: <none> (seed = FALSE)
#Resolved: TRUE
#Value: <not collected>
#Conditions captured: <none>
#Early signaling: FALSE
#Owner process: 7350d459-f96f-d17b-c317-464356372e96
#Class: ‘CallrFuture’, ‘MultiprocessFuture’, ‘Future’, ‘environment’
#callr status: ‘finished’
#callr information: PID=8264, PROCESS 'R', finished.

If I run the next line it gives an error -

test_that("API is running", {
  # Send API request
  r <- httr::GET(root_path, port = 8000, path = "api/v1/health-check")

  # Check response
  expect_equal(r$status_code, 200)
  expect_equal(httr::content(r, encoding = "UTF-8"), list("PIP API is running"))
})

── Error (Line 3): API is running ────────────────────────────────────────────── Error: Failed to connect to localhost port 8000 after 0 ms: Connection refused Backtrace:

  1. httr::GET(root_path, port = 8000, path = "api/v1/health-check")
  2. httr:::request_perform(req, hu$handle$handle)
  3. httr:::request_fetch.write_memory(req$output, req$url, handle)
  4. curl::curl_fetch_memory(url, handle = handle)