Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# pool (development version)

* `Pool$release()` now forwards `error_call` correctly when reporting invalid objects.

# pool 1.0.5

* Added compatibility for dbplyr's upcoming dialect-based dispatch.
Expand Down
2 changes: 1 addition & 1 deletion R/pool.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Pool <- R6::R6Class(
## (sets up task to destroy the object if the number of
## total objects exceeds the minimum)
release = function(object, error_call = caller_env()) {
pool_metadata <- pool_metadata(object, error_call = error_call())
pool_metadata <- pool_metadata(object, error_call = error_call)
if (pool_metadata$state == "free") {
abort(
"This object was already returned to the pool.",
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/_snaps/pool.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@
Error in `poolClose()`:
! The pool has been closed.

# releasing a non-pooled object gives an informative error

Code
release(1)
Condition
Error in `release()`:
! `object` is not an pooled object.

# max size is enforced

Code
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/test-pool.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ test_that("can fetch and release", {
checkCounts(pool, free = 1, taken = 0)
})

test_that("releasing a non-pooled object gives an informative error", {
pool <- poolCreate(function() 1)
defer(poolClose(pool))

release <- function(object) pool$release(object)
expect_snapshot(release(1), error = TRUE)
})

test_that("max size is enforced", {
pool <- poolCreate(MockPooledObj$new, maxSize = 2)
defer(poolClose(pool))
Expand Down
Loading