Skip to content
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

handle cases when httr/crul writes to disk #81

Closed
sckott opened this issue Dec 1, 2018 · 5 comments
Closed

handle cases when httr/crul writes to disk #81

sckott opened this issue Dec 1, 2018 · 5 comments
Milestone

Comments

@sckott
Copy link
Collaborator

sckott commented Dec 1, 2018

investigate if same problem occurs with httr or not.

use case right now is rnoaa, where many functions write to disk - vcr is throwing erors like: with this block https://github.com/ropensci/rnoaa/blob/master/tests/testthat/test-buoy.R#L26-L41

test-buoy.R:33: error: buoy works
argument 'x' must be a raw vector
1: vcr::use_cassette("buoys_parameters", {
       one <- buoy(dataset = "cwind", buoyid = 41001, year = 1997, datatype = "c") at tests/testthat/test-buoy.R:33
2: cassette$call_block(...)
3: lazyeval::lazy_eval(tmp)
4: lapply(x, lazy_eval, data = data)
5: FUN(X[[i]], ...)
6: eval(x$expr, x$env, emptyenv())
7: eval(x$expr, x$env, emptyenv())
8: buoy(dataset = "cwind", buoyid = 41001, year = 1997, datatype = "c") at tests/testthat/test-buoy.R:34
9: get_ncdf_file(path = toget, buoyid, file = files[[1]], output, ...) at /Users/sckott/github/ropensci/rnoaa/R/buoy.R:89
10: crul::HttpClient$new(path, opts = list(...))$get(disk = outpath) at /Users/sckott/github/ropensci/rnoaa/R/buoy.R:146
11: private$make_request(rr)
12: adap$handle_request(opts)
13: vcr::RequestHandlerCrul$new(req)$handle()
14: eval(parse(text = req_type_fun))(self$request)
15: cas$record_http_interaction(response)
16: self$make_http_interaction(x)
17: VcrResponse$new(if (inherits(x, "response")) httr::http_status(x) else unclass(x$status_http()),
       if (inherits(x, "response")) x$headers else x$response_headers, rawToChar(x$content),
18: .subset2(public_bind_env, "initialize")(...)
19: inherits(body, "list")
20: rawToChar(x$content)
@sckott
Copy link
Collaborator Author

sckott commented Dec 2, 2018

possible plan:

  • check class inherits(x$content, "character"), and then
  • check if the file exists file.exists(x$content)
  • if file exists
    • create hashed file name (for now: fff) from ???
    • copy file to fff
    • make sure file path in cassette is fff
  • if file doesn't exist
    • fail out (e.g., "you attempted to write to disk but the file does not exist")
  • On reuse of a cassette with a file on disk, make sure to read the file on disk first, and place bytes in $content slot before returning to the calling function

location o f cached files (e.g., fff) should be in a folder at the root of the user given directory, so if they give the dir as fixtures, then we do

fixtures
└── file_cache
    └── fff

this is def. going to be slow, but overall speeds up test suite, so fine

should also tell users that they can alternatively just read into memory then write to disk after and vcr will work already as is

@sckott sckott closed this as completed Dec 8, 2018
@sckott sckott reopened this Dec 8, 2018
@sckott
Copy link
Collaborator Author

sckott commented Dec 8, 2018

applies to both:

  • crul
  • httr

and

  • curl if we integrate it here (and in webmockr)

@sckott
Copy link
Collaborator Author

sckott commented Jul 24, 2019

  • crul: needs to have the file path in content slot in HttpResponse object
  • httr: same but path has to have s3 "path" class attached

@sckott
Copy link
Collaborator Author

sckott commented Jul 25, 2019

related fix in crul ropensci/crul#115

@sckott
Copy link
Collaborator Author

sckott commented Jul 26, 2019

here's a tough case: where the fxn caches a file from the HTTP request somewhere on disk - how do we deal with this in a vcr testing context?

an example is rnoaa::cpc_prcp - see experiments on branch vcr-write-disk

sckott added a commit that referenced this issue Jul 26, 2019
@sckott sckott changed the title handle cases when crul writes to disk handle cases when httr/crul writes to disk Jul 26, 2019
@sckott sckott modified the milestones: v0.3, v0.4 Aug 9, 2019
sckott added a commit that referenced this issue Dec 4, 2019
this commit fixing remaining holes in httr handling
bump pkg version
@sckott sckott modified the milestones: v0.4, v0.3.4 Dec 4, 2019
@sckott sckott closed this as completed Dec 4, 2019
sckott added a commit that referenced this issue Dec 7, 2019
sckott added a commit to ropensci/rnoaa that referenced this issue Mar 23, 2020
* #290 - working on integrating vcr handling writing to disk, not done yet
related: ropensci/vcr#81 ropensci/webmockr#57

* playing with buoy tests, check back in #FIXME

* cpc_prcp test tweaks

* man file updates

* arc2 fixes, use new write to disk setup

* #290 writing to disk work, not done yet

* fixes for lcd and isd tests that also cache files

* fixed some tests #290

* fix storms test

* use relative paths with new vcr version

* move write to disk files to inst/ - test check on travis | ropensci/vcr#164

* try commenting out deleting  user cached files for ersst tests

* comment out one ersst test, does it work now?

* try ersst tests each with different file on disk - was previously using the same file
perhaps that was leading to failure if e.g. file was opened but not closed before next test ran amybe

* remove .Rinstignore, and try inst/test_files in .Rbuildignore if it works on travis

* remove inst/test_files from rbuildignore

* move test files back to tests/files/

* add .Rinstignore for ignoring test on disk files

* woops, needed to fix write_disk_path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant