/
queue_runner.jl
86 lines (81 loc) · 2.71 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
facts("Queue runner") do
context("Queue restarts during push!") do
@fact 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)
wait(Reactive.runner_task)
@fact queue_size() --> 0
@fact orig_runner --> not(Reactive.runner_task) # we should have a new queue runner
@fact bcount --> expected_bcount
end
@fact bcount --> 0
test_queue(1, Reactive.runner_task)
test_queue(2, Reactive.runner_task)
end
context("Multiple queue restarts during a single action") do
@fact 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)
wait(Reactive.runner_task)
@fact queue_size() --> 0
@fact orig_runner --> not(Reactive.runner_task) # we should have a new queue runner
@fact bcount --> expected_bcount
end
@fact bcount --> 0
test_queue(1, Reactive.runner_task)
test_queue(2, Reactive.runner_task)
end
context("Queue restarts after more than one push!") do
@fact 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)
wait(Reactive.runner_task)
@fact queue_size() --> 0
@fact orig_runner --> not(Reactive.runner_task) # we should have a new queue runner
@fact bcount --> expected_bcount*2
end
@fact bcount --> 0
test_queue(1, Reactive.runner_task)
test_queue(2, Reactive.runner_task)
end
end
if !istaskdone(Reactive.runner_task)
Reactive.stop()
wait(Reactive.runner_task)
end