Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
keller-mark committed Jun 21, 2024
1 parent ac03900 commit 269ee0d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
4 changes: 2 additions & 2 deletions R/options.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ parse_parallel_option <- function(val) {
if(val == "future") {
return("future")
}
logical_val <- as.logical(val)
integer_val <- as.integer(val)
logical_val <- suppressWarnings(as.logical(val))
integer_val <- suppressWarnings(as.integer(val))

if(is.na(integer_val)) {
return(logical_val)
Expand Down
1 change: 1 addition & 0 deletions R/stores.R
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ HttpStore <- R6::R6Class("HttpStore",
path <- paste(private$base_path, key, sep="/")

parallel_option <- getOption("pizzarr.parallel_read_enabled")
parallel_option <- parse_parallel_option(parallel_option)
is_parallel <- is_truthy_parallel_option(parallel_option)

if(is_parallel) {
Expand Down
5 changes: 3 additions & 2 deletions tests/testthat/setup-utils.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
setup({

pbapply::pboptions(type = "none")
do.call(options, pizzarr_option_defaults)
})
teardown({

do.call(options, pizzarr_option_defaults)
})

zarr_volcano <- function() {
Expand Down
31 changes: 24 additions & 7 deletions tests/testthat/test-parallel.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
library(pizzarr)

pbapply::pboptions(type = "none")

SlowGettingDirectoryStore <- R6::R6Class("SlowGettingDirectoryStore",
inherit = DirectoryStore,
public = list(
Expand Down Expand Up @@ -68,7 +66,6 @@ run_parallel_set <- function(num_workers) {
}

test_that("can run get_item() in parallel", {

bench_df <- bench::mark(
run_parallel_get(1),
run_parallel_get(2),
Expand All @@ -81,11 +78,9 @@ test_that("can run get_item() in parallel", {
expect_equal(unlist(bench_df$result), rep(134538481, 3))
expect_equal(bench_df$total_time[[1]] > bench_df$total_time[[2]], TRUE)
expect_equal(bench_df$total_time[[2]] > bench_df$total_time[[3]], TRUE)

})

test_that("can run set_item() in parallel", {

bench_df <- bench::mark(
run_parallel_set(1),
run_parallel_set(2),
Expand All @@ -98,5 +93,27 @@ test_that("can run set_item() in parallel", {
expect_equal(unlist(bench_df$result), rep(134538481*2.0, 3))
expect_equal(bench_df$total_time[[1]] > bench_df$total_time[[2]], TRUE)
expect_equal(bench_df$total_time[[2]] > bench_df$total_time[[3]], TRUE)

})
})

test_that("parse_parallel_option works as expected", {
expect_equal(parse_parallel_option("future"), "future")
expect_equal(parse_parallel_option("0"), FALSE)
expect_equal(parse_parallel_option(0), FALSE)
expect_equal(parse_parallel_option("FALSE"), FALSE)
expect_equal(parse_parallel_option(FALSE), FALSE)
expect_equal(parse_parallel_option("1"), TRUE)
expect_equal(parse_parallel_option(1), TRUE)
expect_equal(parse_parallel_option("TRUE"), TRUE)
expect_equal(parse_parallel_option(TRUE), TRUE)
expect_equal(parse_parallel_option("2"), 2)
expect_equal(parse_parallel_option(2), 2)
})

test_that("is_truthy_parallel_option works as expected", {
expect_equal(is_truthy_parallel_option("future"), TRUE)
expect_equal(is_truthy_parallel_option(FALSE), FALSE)
expect_equal(is_truthy_parallel_option(0), FALSE)
expect_equal(is_truthy_parallel_option(TRUE), TRUE)
expect_equal(is_truthy_parallel_option(1), TRUE)
expect_equal(is_truthy_parallel_option(2), TRUE)
})

0 comments on commit 269ee0d

Please sign in to comment.