polyphony 0.29 → 0.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +14 -0
- data/Gemfile.lock +1 -1
- data/TODO.md +15 -10
- data/docs/getting-started/tutorial.md +3 -3
- data/docs/index.md +2 -3
- data/docs/{technical-overview → main-concepts}/concurrency.md +62 -15
- data/docs/{technical-overview → main-concepts}/design-principles.md +21 -8
- data/docs/{technical-overview → main-concepts}/exception-handling.md +80 -38
- data/docs/{technical-overview → main-concepts}/extending.md +4 -3
- data/docs/{technical-overview → main-concepts}/fiber-scheduling.md +3 -3
- data/docs/{technical-overview.md → main-concepts.md} +2 -2
- data/examples/core/xx-at_exit.rb +29 -0
- data/examples/core/xx-fork-terminate.rb +27 -0
- data/examples/core/xx-pingpong.rb +18 -0
- data/examples/core/xx-stop.rb +20 -0
- data/ext/gyro/async.c +1 -1
- data/ext/gyro/extconf.rb +0 -3
- data/ext/gyro/gyro.c +7 -8
- data/ext/gyro/gyro.h +2 -0
- data/ext/gyro/queue.c +6 -6
- data/ext/gyro/selector.c +32 -1
- data/ext/gyro/thread.c +55 -9
- data/ext/gyro/timer.c +1 -0
- data/lib/polyphony/core/exceptions.rb +4 -1
- data/lib/polyphony/core/global_api.rb +1 -6
- data/lib/polyphony/core/thread_pool.rb +3 -3
- data/lib/polyphony/extensions/core.rb +7 -1
- data/lib/polyphony/extensions/fiber.rb +159 -72
- data/lib/polyphony/extensions/io.rb +2 -4
- data/lib/polyphony/extensions/openssl.rb +0 -17
- data/lib/polyphony/extensions/thread.rb +46 -22
- data/lib/polyphony/version.rb +1 -1
- data/lib/polyphony.rb +20 -18
- data/test/coverage.rb +1 -1
- data/test/helper.rb +7 -3
- data/test/test_fiber.rb +285 -72
- data/test/test_global_api.rb +7 -52
- data/test/test_io.rb +8 -0
- data/test/test_signal.rb +1 -0
- data/test/test_thread.rb +76 -56
- data/test/test_thread_pool.rb +27 -5
- data/test/test_throttler.rb +1 -0
- metadata +12 -12
- data/lib/polyphony/core/supervisor.rb +0 -114
- data/lib/polyphony/line_reader.rb +0 -82
- data/test/test_gyro.rb +0 -25
- data/test/test_supervisor.rb +0 -180
data/test/test_supervisor.rb
DELETED
@@ -1,180 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'helper'
|
4
|
-
|
5
|
-
class SupervisorTest < MiniTest::Test
|
6
|
-
def test_await
|
7
|
-
result = Polyphony::Supervisor.new.await { |s|
|
8
|
-
s.spin {
|
9
|
-
snooze
|
10
|
-
:foo
|
11
|
-
}
|
12
|
-
}
|
13
|
-
assert_equal [:foo], result
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_await_multiple_fibers
|
17
|
-
result = Polyphony::Supervisor.new.await { |s|
|
18
|
-
(1..3).each { |i|
|
19
|
-
s.spin {
|
20
|
-
snooze
|
21
|
-
i * 10
|
22
|
-
}
|
23
|
-
}
|
24
|
-
}
|
25
|
-
assert_equal [10, 20, 30], result
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_new_with_block
|
29
|
-
supervisor = Polyphony::Supervisor.new { |s|
|
30
|
-
(1..3).each { |i|
|
31
|
-
s.spin {
|
32
|
-
snooze
|
33
|
-
i * 10
|
34
|
-
}
|
35
|
-
}
|
36
|
-
}
|
37
|
-
assert_equal [10, 20, 30], supervisor.await
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_join_multiple_fibers
|
41
|
-
result = Polyphony::Supervisor.new.join { |s|
|
42
|
-
(1..3).each { |i|
|
43
|
-
s.spin {
|
44
|
-
snooze
|
45
|
-
i * 10
|
46
|
-
}
|
47
|
-
}
|
48
|
-
}
|
49
|
-
assert_equal [10, 20, 30], result
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_spin_method
|
53
|
-
buffer = []
|
54
|
-
Polyphony::Supervisor.new.join { |s|
|
55
|
-
(1..3).each { |i|
|
56
|
-
buffer << s.spin {
|
57
|
-
snooze
|
58
|
-
i * 10
|
59
|
-
}
|
60
|
-
}
|
61
|
-
}
|
62
|
-
|
63
|
-
assert_equal [Fiber], buffer.map { |v| v.class }.uniq
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_supervisor_select
|
67
|
-
buffer = []
|
68
|
-
foo_f = bar_f = baz_f = nil
|
69
|
-
result, f = Polyphony::Supervisor.new.select { |s|
|
70
|
-
foo_f = s.spin { sleep 0.1; buffer << :foo; :foo }
|
71
|
-
bar_f = s.spin { sleep 0.3; buffer << :bar; :bar }
|
72
|
-
baz_f = s.spin { sleep 0.5; buffer << :baz; :baz }
|
73
|
-
}
|
74
|
-
|
75
|
-
assert_equal :foo, result
|
76
|
-
assert_equal foo_f, f
|
77
|
-
|
78
|
-
sleep 0.05
|
79
|
-
assert !bar_f.running?
|
80
|
-
assert !baz_f.running?
|
81
|
-
assert_equal [:foo], buffer
|
82
|
-
end
|
83
|
-
|
84
|
-
def test_await_with_exception
|
85
|
-
buffer = []
|
86
|
-
result = capture_exception do
|
87
|
-
Polyphony::Supervisor.new.await { |s|
|
88
|
-
(1..3).each { |i|
|
89
|
-
s.spin {
|
90
|
-
raise 'foo' if i == 1
|
91
|
-
snooze
|
92
|
-
buffer << i * 10
|
93
|
-
i * 10
|
94
|
-
}
|
95
|
-
}
|
96
|
-
}
|
97
|
-
end
|
98
|
-
|
99
|
-
assert_kind_of RuntimeError, result
|
100
|
-
assert_equal 'foo', result.message
|
101
|
-
snooze
|
102
|
-
assert_equal [], buffer
|
103
|
-
end
|
104
|
-
|
105
|
-
def test_await_interruption
|
106
|
-
buffer = []
|
107
|
-
supervisor = nil
|
108
|
-
supervisor = Polyphony::Supervisor.new
|
109
|
-
spin { supervisor.interrupt(42) }
|
110
|
-
buffer << supervisor.await { |s|
|
111
|
-
(1..3).each { |i|
|
112
|
-
s.spin {
|
113
|
-
buffer << i
|
114
|
-
sleep i
|
115
|
-
buffer << i * 10
|
116
|
-
}
|
117
|
-
}
|
118
|
-
}
|
119
|
-
|
120
|
-
snooze
|
121
|
-
assert_equal [1, 2, 3, 42], buffer
|
122
|
-
end
|
123
|
-
|
124
|
-
def test_select_interruption
|
125
|
-
buffer = []
|
126
|
-
supervisor = nil
|
127
|
-
supervisor = Polyphony::Supervisor.new
|
128
|
-
spin { supervisor.interrupt(42) }
|
129
|
-
buffer << supervisor.select { |s|
|
130
|
-
(1..3).each { |i|
|
131
|
-
s.spin {
|
132
|
-
buffer << i
|
133
|
-
sleep i
|
134
|
-
buffer << i * 10
|
135
|
-
}
|
136
|
-
}
|
137
|
-
}
|
138
|
-
|
139
|
-
snooze
|
140
|
-
assert_equal [1, 2, 3, 42], buffer
|
141
|
-
end
|
142
|
-
|
143
|
-
def test_add
|
144
|
-
supervisor = Polyphony::Supervisor.new
|
145
|
-
supervisor << spin { :foo }
|
146
|
-
supervisor << spin { :bar }
|
147
|
-
|
148
|
-
assert_equal [:foo, :bar], supervisor.await
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
class FiberExtensionsTest < MiniTest::Test
|
153
|
-
def test_join
|
154
|
-
f1 = spin { :foo }
|
155
|
-
f2 = spin { :bar }
|
156
|
-
assert_equal [:foo, :bar], Fiber.join(f1, f2)
|
157
|
-
|
158
|
-
f1 = spin { :foo }
|
159
|
-
f2 = spin { raise 'bar' }
|
160
|
-
result = capture_exception { Fiber.join(f1, f2) }
|
161
|
-
assert_kind_of RuntimeError, result
|
162
|
-
assert_equal 'bar', result.message
|
163
|
-
end
|
164
|
-
|
165
|
-
def test_select
|
166
|
-
f1 = spin { sleep 1; :foo }
|
167
|
-
f2 = spin { :bar }
|
168
|
-
assert_equal [:bar, f2], Fiber.select(f1, f2)
|
169
|
-
|
170
|
-
f1 = spin { :foo }
|
171
|
-
f2 = spin { sleep 0.01; raise 'bar' }
|
172
|
-
assert_equal [:foo, f1], Fiber.select(f1, f2)
|
173
|
-
|
174
|
-
f1 = spin { sleep 1; :foo }
|
175
|
-
f2 = spin { raise 'bar' }
|
176
|
-
result = capture_exception { Fiber.select(f1, f2) }
|
177
|
-
assert_kind_of RuntimeError, result
|
178
|
-
assert_equal 'bar', result.message
|
179
|
-
end
|
180
|
-
end
|