Skip to content

Commit

Permalink
Make throttle/debounce tests robust to CPU scheduling
Browse files Browse the repository at this point in the history
  • Loading branch information
dvg-p4 committed Sep 24, 2024
1 parent d84aa94 commit 1cdd8cc
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions tests/testthat/test-reactivity.r
Original file line number Diff line number Diff line change
Expand Up @@ -1243,7 +1243,10 @@ test_that("debounce/throttle work properly (with priming)", {

# This observer will be what changes rv$a.
src <- observe({
invalidateLater(100)
if (isolate(rv$a) == 0)
invalidateLater(120) # delay 20ms extra once to avoid threshold errors
else
invalidateLater(100)
rv$a <- isolate(rv$a) + 1
})
on.exit(src$destroy(), add = TRUE)
Expand Down Expand Up @@ -1322,7 +1325,10 @@ test_that("debounce/throttle work properly (without priming)", {

# This observer will be what changes rv$a.
src <- observe({
invalidateLater(100)
if (isolate(rv$a) == 0)
invalidateLater(120) # delay 20ms extra once to avoid threshold errors
else
invalidateLater(100)
rv$a <- isolate(rv$a) + 1
})
on.exit(src$destroy(), add = TRUE)
Expand Down

0 comments on commit 1cdd8cc

Please sign in to comment.