mirror of
https://github.com/rstudio/shiny.git
synced 2026-01-13 08:57:57 -05:00
Compare commits
1 Commits
main
...
private-se
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bd7e1a5203 |
@@ -52,6 +52,11 @@ repeatable <- function(rngfunc, seed = stats::runif(1, 0, .Machine$integer.max))
|
||||
# Evaluate an expression using Shiny's own private stream of
|
||||
# randomness (not affected by set.seed).
|
||||
withPrivateSeed <- function(expr) {
|
||||
# Don't use the private seed in testmode for deterministic tests
|
||||
if (isTRUE(getOption("shiny.testmode", getShinyOption("testmode")))) {
|
||||
return(expr)
|
||||
}
|
||||
|
||||
# Save the old seed if present.
|
||||
if (exists(".Random.seed", envir = .GlobalEnv, inherits = FALSE)) {
|
||||
hasOrigSeed <- TRUE
|
||||
|
||||
@@ -50,6 +50,18 @@ test_that("Setting the private seed explicitly results in identical values", {
|
||||
expect_identical(id7, id8)
|
||||
})
|
||||
|
||||
test_that("Private seed is disabled in testmode", {
|
||||
oldopts <- options(shiny.testmode = TRUE)
|
||||
on.exit(options(oldopts), add = TRUE)
|
||||
|
||||
set.seed(0)
|
||||
id1 <- createUniqueId(4)
|
||||
set.seed(0)
|
||||
id2 <- createUniqueId(4)
|
||||
|
||||
expect_identical(id1, id2)
|
||||
})
|
||||
|
||||
test_that("Private and 'public' random streams are independent and work the same", {
|
||||
set.seed(0)
|
||||
public <- c(runif(1), runif(1), runif(1))
|
||||
|
||||
Reference in New Issue
Block a user