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: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "SweepRunner"
uuid = "be946ad2-3cb3-4b6e-8f7e-4a5ecc3c255b"
version = "0.6.6"
version = "0.6.7"
authors = ["sota shimozono <shimozono-sota631@g.ecc.u-tokyo.ac.jp>"]

[deps]
Expand Down
19 changes: 15 additions & 4 deletions test/run/test_run_adversarial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,30 @@ allk_a(v) = ParamIO.expand(v.spec)
@test length(keys) >= 4

stop = joinpath(outdir, "STOP_NOW")
# Delay the stop flag by 50 ms so a few keys finish first
t = Timer(_ -> touch(stop), 0.05)
# The concurrent task raises the flag once the first key has finished — not after a fixed
# delay, which assumed `run!` starts within it. It does not always: a run-start
# observation that keeps the packages the process loaded takes most of a second, and a
# 50 ms timer then fired before any key ran.
first_done = Channel{Nothing}(1)
raiser = @async try
take!(first_done)
touch(stop)
catch e
e isa InvalidStateException || rethrow() # closed: the run ended first
end

# work_fn sleeps so we're sure the stop is seen after some work
# work_fn sleeps so the raiser gets to run while keys remain
counter = Ref(0)
work_fn = k -> begin
counter[] += 1
sleep(0.02)
counter[] == 1 && put!(first_done, nothing)
Dict{String,Any}("x" => 1)
end

result = run!(work_fn, v, keys; opts=RunOpts(stop_flag=stop))
close(t)
close(first_done)
wait(raiser)

# At least one key ran before stop kicked in, at least one was skipped
@test result.done >= 1
Expand Down
Loading