Skip to content

Commit

Permalink
throttle test more debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
fonsp committed Aug 10, 2024
1 parent 6d3aaea commit 3c55edf
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 24 deletions.
1 change: 0 additions & 1 deletion src/evaluation/Throttled.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ Given a throttled function, skip any pending run if hot (but let the cooldown pe
Argument should be the first function returned by `throttled`.
"""
function force_throttle_without_run(tf::ThrottledFunction)
# (we can access variables from the function closure hihi)
tf.run_later[] = false
if tf.iscoolnow[]
tf.iscoolnow[] = false
Expand Down
60 changes: 37 additions & 23 deletions test/Throttled.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ using Pluto.WorkspaceManager: poll
# f was not throttled
@test x[] == 1

dt = 4 / 100
ft = Throttled.throttled(f, dt)
dt = 8 / 100
tf = Throttled.throttled(f, dt)

for x in 1:10
ft()
tf()
end
# we have an initial cooldown period in which f should not fire...
# ...so x is still 1...
Expand All @@ -25,7 +25,7 @@ using Pluto.WorkspaceManager: poll
@test x[] == 2

# Let's wait for the cooldown period to end
sleep(dt)
sleep(2dt)
# nothing should have changed
@test x[] == 2

Expand All @@ -35,7 +35,7 @@ using Pluto.WorkspaceManager: poll
# and the cooldown period for the first throttled calls is over

for x in 1:10
ft()
tf()
end
# we want to send plots to the user as soon as they are available,
# so no leading timeout
Expand All @@ -46,7 +46,7 @@ using Pluto.WorkspaceManager: poll


for x in 1:5
ft()
tf()
sleep(1.5dt)
end
@test x[] == 9
Expand All @@ -57,14 +57,14 @@ using Pluto.WorkspaceManager: poll
###

# "call 1"
ft()
tf()
# no leading timeout, immediately set to 10
@test x[] == 10

sleep(.5dt)

# "call 2"
ft()
tf()
# throttled
@test x[] == 10

Expand All @@ -79,57 +79,71 @@ using Pluto.WorkspaceManager: poll

###

ft()
ft()
tf()
tf()
@test x[] == 12
flush(ft)
flush(tf)
@test x[] == 13
sleep(2dt)
@test x[] == 13

####

ft()
tf()
@test poll(2dt, dt/60) do
x[] == 14
end
# immediately fire again, right after the last fire
ft()
ft()
tf()
tf()
# this should not do anything, because we are still in the cooldown period
@test x[] == 14
# not even after a little while
sleep(0.1dt)
@test x[] == 14

# but eventually, our call should get queued
sleep(dt)
@test x[] == 15
sleep(2dt)
@test x[] == 15

####

x[] = 0
Throttled.force_throttle_without_run(ft)


@test tf.iscoolnow[]
@test !tf.run_later[]

Throttled.force_throttle_without_run(tf)

@test !tf.iscoolnow[]
@test !tf.run_later[]

@test x[] == 0
ft()
tf()

@test !tf.iscoolnow[]
@test tf.run_later[]

@test x[] == 0
sleep(.1dt)
@test x[] == 0
sleep(2dt)
@test x[] == 1


ft()
@test tf.iscoolnow[]
@test !tf.run_later[]
tf()
@test x[] == 2
sleep(.1dt)
ft()
Throttled.force_throttle_without_run(ft)
tf()
Throttled.force_throttle_without_run(tf)
@test x[] == 2
sleep(2dt)
@test x[] == 2


ft()
tf()
@test x[] == 3
sleep(2dt)

Expand Down

0 comments on commit 3c55edf

Please sign in to comment.