/
queue_runner.jl
86 lines (81 loc) · 2.78 KB
/
queue_runner.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
Reactive.__init__()
import Reactive: runner_task
@testset "Queue runner" begin
@testset "Queue restarts during push!" begin
@test (queue_size()) == (0)
bcount = 0
a = Signal(1)
foreach(a; init=nothing) do _
b = Signal(1)
bcount += 1
foreach(b; init=nothing) do _
bcount += 1 #won't get run because of the init=nothing
end
nothing
end
function test_queue(expected_bcount, orig_runner)
push!(a, 3)
fetch(Reactive.runner_task[])
@test (queue_size()) == (0)
@test (orig_runner) != (Reactive.runner_task[]) # we should have a new queue runner)
@test (bcount) == (expected_bcount)
end
@test (bcount) == (0)
test_queue(1, Reactive.runner_task[])
test_queue(2, Reactive.runner_task[])
end
@testset "Multiple queue restarts during a single action" begin
@test (queue_size()) == (0)
bcount = 0
a = Signal(1)
foreach(a; init=nothing) do _
b = Signal(1)
bcount += 1
foreach(b; init=nothing) do _
bcount += 1 #won't get run because of the init=nothing
end
foreach(b; init=nothing) do _
bcount += 1 #won't get run because of the init=nothing
end
nothing
end
function test_queue(expected_bcount, orig_runner)
push!(a, 3)
fetch(Reactive.runner_task[])
@test (queue_size()) == (0)
@test (orig_runner) != Reactive.runner_task[] # we should have a new queue runner)
@test (bcount) == (expected_bcount)
end
@test (bcount) == (0)
test_queue(1, Reactive.runner_task[])
test_queue(2, Reactive.runner_task[])
end
@testset "Queue restarts after more than one push!" begin
@test (queue_size()) == (0)
bcount = 0
a = Signal(1)
foreach(a; init=nothing) do _
b = Signal(1)
bcount += 1
foreach(b; init=nothing) do _
bcount += 1 #won't get run because of the init=nothing
end
nothing
end
function test_queue(expected_bcount, orig_runner)
push!(a, 3)
push!(a, 4)
fetch(Reactive.runner_task[])
@test (queue_size()) == (0)
@test (orig_runner) != (Reactive.runner_task[]) # we should have a new queue runner)
@test (bcount) == (expected_bcount*2)
end
@test (bcount) == (0)
test_queue(1, Reactive.runner_task[])
test_queue(2, Reactive.runner_task[])
end
end
if !istaskdone(Reactive.runner_task[])
Reactive.stop()
fetch(Reactive.runner_task[])
end