From f65f3861df8bc21aef3503ee19234bdf6921fb31 Mon Sep 17 00:00:00 2001 From: Chris Foster Date: Sat, 6 Nov 2021 13:07:07 +1000 Subject: [PATCH] Apply suggestions from code review - wait explicitly on tasks in tests Co-authored-by: Takafumi Arakaki --- test/channels.jl | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/test/channels.jl b/test/channels.jl index 2256cd22984b92..1a989747c38635 100644 --- a/test/channels.jl +++ b/test/channels.jl @@ -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