Skip to content

Commit

Permalink
Apply suggestions from code review - wait explicitly on tasks in tests
Browse files Browse the repository at this point in the history
Co-authored-by: Takafumi Arakaki <[email protected]>
  • Loading branch information
c42f and tkf committed Nov 6, 2021
1 parent 547f8f8 commit 89e19a9
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions test/channels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -586,32 +586,36 @@ end
let c = Channel(2)
@test n_avail(c) == 0; put!(c, 0)
@test n_avail(c) == 1; put!(c, 0)
@test n_avail(c) == 2; yield(@task put!(c, 0))
@test n_avail(c) == 3; yield(@task put!(c, 0))
@test n_avail(c) == 2; t1 = @task put!(c, 0); yield(t1)
@test n_avail(c) == 3; t2 = @task put!(c, 0); yield(t2)
@test n_avail(c) == 4
# Test n_avail(c) after interrupting a task waiting on the channel
t = @task put!(c, 0)
yield(t)
t3 = @task put!(c, 0)
yield(t3)
@test n_avail(c) == 5
@async Base.throwto(t, ErrorException("Exit put!"))
try wait(t) catch end
@async Base.throwto(t3, ErrorException("Exit put!"))
try wait(t3) catch end
@test n_avail(c) == 4
close(c); yield()
close(c)
try wait(t1) catch end
try wait(t2) catch end
@test n_avail(c) == 2 # Already-buffered items remain
end
# Unbuffered: n_avail() = number of waiting tasks
let c = Channel()
@test n_avail(c) == 0; yield(@task put!(c, 0))
@test n_avail(c) == 1; yield(@task put!(c, 0))
@test n_avail(c) == 0; t1 = @task put!(c, 0); yield(t1)
@test n_avail(c) == 1; t2 = @task put!(c, 0); yield(t2)
@test n_avail(c) == 2
# Test n_avail(c) after interrupting a task waiting on the channel
t = @task put!(c, 0)
yield(t)
t3 = @task put!(c, 0)
yield(t3)
@test n_avail(c) == 3
@async Base.throwto(t, ErrorException("Exit put!"))
try wait(t) catch end
@async Base.throwto(t3, ErrorException("Exit put!"))
try wait(t3) catch end
@test n_avail(c) == 2
close(c); yield()
close(c)
try wait(t1) catch end
try wait(t2) catch end
@test n_avail(c) == 0
end
end

0 comments on commit 89e19a9

Please sign in to comment.