Skip to content

Commit

Permalink
Reorder tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NHDaly committed Sep 4, 2019
1 parent de1ba80 commit 3a7ad5a
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,26 +1,6 @@
using Select
using Test

@testset "self-references" begin
# Test multiple times because the deadlock was only triggered if Task 1 is run before
# Task 2 or Task 3. Running it multiple times will hopefully cover all the cases.
for _ in 1:10
# Test that the two clauses in `@select` can't trigger eachother (Here, the problem
# would be if Task 1 puts into ch, then Task 2 sees Task 1 waiting, and thinks ch is
# ready to take! and attempts to incorrectly proceed w/ the take!.) Instead, this should
# timeout, since no one else is putting or taking on `ch`.
ch = Channel()
@test @select(begin
ch <| "hi" => "put"
# This take!(ch) should not be triggered by the put
ch |> x => "take! |> $x"
# This wait(ch) should also not be triggered by the put
ch => "waiting on ch"
@async(sleep(0.3)) => "timeout"
end) == "timeout"
end
end

function select_block_test(t1, t2, t3, t4)
c1 = Channel{Symbol}(1)
c2 = Channel{Int}(1)
Expand Down Expand Up @@ -84,3 +64,23 @@ end
@test select_nonblock_test(:take) == "Got 1 from c"
@test select_nonblock_test(:put) == "Wrote to c2"
@test select_nonblock_test(:default) == "Default case"

@testset "self-references" begin
# Test multiple times because the deadlock was only triggered if Task 1 is run before
# Task 2 or Task 3. Running it multiple times will hopefully cover all the cases.
for _ in 1:10
# Test that the two clauses in `@select` can't trigger eachother (Here, the problem
# would be if Task 1 puts into ch, then Task 2 sees Task 1 waiting, and thinks ch is
# ready to take! and attempts to incorrectly proceed w/ the take!.) Instead, this should
# timeout, since no one else is putting or taking on `ch`.
ch = Channel()
@test @select(begin
ch <| "hi" => "put"
# This take!(ch) should not be triggered by the put
ch |> x => "take! |> $x"
# This wait(ch) should also not be triggered by the put
ch => "waiting on ch"
@async(sleep(0.3)) => "timeout"
end) == "timeout"
end
end

0 comments on commit 3a7ad5a

Please sign in to comment.