Skip to content
Closed
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
20 changes: 19 additions & 1 deletion R/mock-session.R
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,25 @@ MockShinySession <- R6Class(
withReactiveDomain(self, {
private$endedCBs$invoke(onError = printError, ..stacktraceon = TRUE)
})
private$invokeDestroyCallbacks(allowRoot = TRUE)
# TEMPORARILY DISABLED for the 1.14.0 release. #4372 made a closing
# session destroy the reactives bound to it; because testServer() closes
# its mock session on exit, reactives created inside a module under test
# are now torn down as soon as testServer() returns. Several CRAN
# packages (blockr.core, blockr.dock, teal.slice) read such reactives
# *after* the testServer() block and broke with "its module session has
# been destroyed". The real ShinySession (ShinySession$wsClosed()) still
# destroys on close, so app behavior is unchanged; only the test harness
# is reverted to the pre-#4372 behavior of leaving reactives intact.
#
# TO RE-ENABLE (target: a future release): once the affected maintainers
# have been notified to update their tests — either create session-
# independent reactives with `withReactiveDomain(NULL, ...)`, or read
# reactive state inside the testServer() block / snapshot it with
# `isolate(reactiveValuesToList(...))` — uncomment the line below and the
# paired tests in tests/testthat/test-destroy.R (search for this same
# marker) and tests/testthat/test-test-server.R.
Comment on lines +371 to +372
#
# private$invokeDestroyCallbacks(allowRoot = TRUE)
private$was_closed <- TRUE
},

Expand Down
71 changes: 39 additions & 32 deletions tests/testthat/test-destroy.R
Original file line number Diff line number Diff line change
Expand Up @@ -540,27 +540,32 @@ test_that("session$destroy(id) does not leak bookmark-exclude callbacks", {
expect_equal(session$getBookmarkExclude(), before)
})

test_that("MockShinySession$close() invokes destroy callbacks", {
session <- MockShinySession$new()
called <- FALSE
session$onDestroy(function() called <<- TRUE)
session$close()
expect_true(called)
})

test_that("MockShinySession$close() fires destroy callbacks deepest-first", {
session <- MockShinySession$new()
parent <- session$makeScope("parent")
child <- parent$makeScope("child")

order <- character(0)
session$onDestroy(function() order <<- c(order, "root"))
parent$onDestroy(function() order <<- c(order, "parent"))
child$onDestroy(function() order <<- c(order, "child"))

session$close()
expect_equal(order, c("child", "parent", "root"))
})
# RE-ENABLE alongside MockShinySession$close()'s invokeDestroyCallbacks("") call
# (see the note in R/mock-session.R). These tests assert that closing the mock
# session destroys its reactives; that behavior is temporarily disabled for the
# 1.14.0 release, so they are commented out and should be restored together with
# that line.
Comment on lines +543 to +547
# test_that("MockShinySession$close() invokes destroy callbacks", {
# session <- MockShinySession$new()
# called <- FALSE
# session$onDestroy(function() called <<- TRUE)
# session$close()
# expect_true(called)
# })
#
# test_that("MockShinySession$close() fires destroy callbacks deepest-first", {
# session <- MockShinySession$new()
# parent <- session$makeScope("parent")
# child <- parent$makeScope("child")
#
# order <- character(0)
# session$onDestroy(function() order <<- c(order, "root"))
# parent$onDestroy(function() order <<- c(order, "parent"))
# child$onDestroy(function() order <<- c(order, "child"))
#
# session$close()
# expect_equal(order, c("child", "parent", "root"))
# })

test_that("MockShinySession destroy cleans up namespaced inputs", {
session <- MockShinySession$new()
Expand All @@ -577,17 +582,19 @@ test_that("MockShinySession destroy cleans up namespaced inputs", {
expect_null(isolate(session$input$`mymod-y`))
})

test_that("root onDestroy callbacks fire after module callbacks during close", {
session <- MockShinySession$new()
scope <- session$makeScope("mod1")

order <- character(0)
session$onDestroy(function() order <<- c(order, "root"))
scope$onDestroy(function() order <<- c(order, "mod1"))

session$close()
expect_equal(order, c("mod1", "root"))
})
# RE-ENABLE alongside MockShinySession$close()'s invokeDestroyCallbacks("") call
# (see the note in R/mock-session.R); disabled for the 1.14.0 release.
Comment on lines +585 to +586
# test_that("root onDestroy callbacks fire after module callbacks during close", {
# session <- MockShinySession$new()
# scope <- session$makeScope("mod1")
#
# order <- character(0)
# session$onDestroy(function() order <<- c(order, "root"))
# scope$onDestroy(function() order <<- c(order, "mod1"))
#
# session$close()
# expect_equal(order, c("mod1", "root"))
# })

test_that("session proxy onDestroy registers and fires on destroy", {
session <- MockShinySession$new()
Expand Down
Loading