polyphony 0.16 → 0.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/Gemfile.lock +1 -1
- data/README.md +11 -11
- data/TODO.md +14 -5
- data/examples/core/channel_echo.rb +3 -3
- data/examples/core/enumerator.rb +1 -1
- data/examples/core/fork.rb +1 -1
- data/examples/core/genserver.rb +1 -1
- data/examples/core/lock.rb +3 -3
- data/examples/core/multiple_spawn.rb +2 -2
- data/examples/core/nested_async.rb +1 -1
- data/examples/core/nested_multiple_spawn.rb +3 -3
- data/examples/core/resource.rb +1 -1
- data/examples/core/resource_cancel.rb +1 -1
- data/examples/core/resource_delegate.rb +1 -1
- data/examples/core/sleep_spawn.rb +2 -2
- data/examples/core/spawn.rb +1 -1
- data/examples/core/spawn_cancel.rb +1 -1
- data/examples/core/spawn_error.rb +5 -5
- data/examples/core/supervisor.rb +4 -4
- data/examples/core/supervisor_with_cancel_scope.rb +3 -3
- data/examples/core/supervisor_with_error.rb +4 -4
- data/examples/core/supervisor_with_manual_move_on.rb +4 -4
- data/examples/core/thread.rb +2 -2
- data/examples/core/thread_cancel.rb +2 -2
- data/examples/core/thread_pool.rb +2 -2
- data/examples/core/throttle.rb +3 -3
- data/examples/fs/read.rb +1 -1
- data/examples/http/happy_eyeballs.rb +1 -1
- data/examples/http/http_client.rb +1 -1
- data/examples/http/http_server.rb +1 -1
- data/examples/http/http_server_throttled.rb +1 -1
- data/examples/http/http_ws_server.rb +2 -2
- data/examples/http/https_wss_server.rb +1 -1
- data/examples/interfaces/pg_client.rb +1 -1
- data/examples/interfaces/pg_pool.rb +1 -1
- data/examples/interfaces/redis_channels.rb +5 -5
- data/examples/interfaces/redis_pubsub.rb +2 -2
- data/examples/interfaces/redis_pubsub_perf.rb +3 -3
- data/examples/io/cat.rb +13 -0
- data/examples/io/echo_client.rb +2 -2
- data/examples/io/echo_server.rb +1 -1
- data/examples/io/echo_server_with_timeout.rb +1 -1
- data/examples/io/echo_stdin.rb +1 -1
- data/examples/io/io_read.rb +9 -0
- data/examples/io/system.rb +11 -0
- data/examples/performance/perf_multi_snooze.rb +2 -2
- data/examples/performance/perf_snooze.rb +2 -2
- data/examples/performance/thread-vs-fiber/polyphony_server.rb +2 -2
- data/ext/ev/io.c +53 -4
- data/lib/polyphony/core/coprocess.rb +1 -0
- data/lib/polyphony/core/supervisor.rb +1 -1
- data/lib/polyphony/extensions/io.rb +97 -17
- data/lib/polyphony/extensions/kernel.rb +47 -27
- data/lib/polyphony/http/server.rb +1 -1
- data/lib/polyphony/postgres.rb +0 -4
- data/lib/polyphony/version.rb +1 -1
- data/test/test_coprocess.rb +13 -13
- data/test/test_core.rb +12 -12
- data/test/test_io.rb +95 -3
- data/test/test_kernel.rb +26 -0
- metadata +6 -2
data/test/test_io.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'minitest/autorun'
|
2
4
|
require 'bundler/setup'
|
3
5
|
require 'polyphony'
|
6
|
+
require 'fileutils'
|
4
7
|
|
5
8
|
class IOTest < MiniTest::Test
|
6
9
|
def setup
|
@@ -12,19 +15,19 @@ class IOTest < MiniTest::Test
|
|
12
15
|
count = 0
|
13
16
|
msg = nil
|
14
17
|
[
|
15
|
-
|
18
|
+
coproc {
|
16
19
|
@o.write("hello")
|
17
20
|
@o.close
|
18
21
|
},
|
19
22
|
|
20
|
-
|
23
|
+
coproc {
|
21
24
|
while count < 5
|
22
25
|
sleep 0.01
|
23
26
|
count += 1
|
24
27
|
end
|
25
28
|
},
|
26
29
|
|
27
|
-
|
30
|
+
coproc {
|
28
31
|
msg = @i.read
|
29
32
|
}
|
30
33
|
].each(&:await)
|
@@ -39,4 +42,93 @@ class IOTest < MiniTest::Test
|
|
39
42
|
@o.close
|
40
43
|
assert_equal('foobarbaz', @i.read)
|
41
44
|
end
|
45
|
+
end
|
46
|
+
|
47
|
+
class IOClassMethodsTest < MiniTest::Test
|
48
|
+
def setup
|
49
|
+
EV.rerun
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_binread
|
53
|
+
s = IO.binread(__FILE__)
|
54
|
+
assert_kind_of(String, s)
|
55
|
+
assert(!s.empty?)
|
56
|
+
assert_equal(IO.orig_binread(__FILE__), s)
|
57
|
+
|
58
|
+
s = IO.binread(__FILE__, 100)
|
59
|
+
assert_equal(100, s.bytesize)
|
60
|
+
assert_equal(IO.orig_binread(__FILE__, 100), s)
|
61
|
+
|
62
|
+
s = IO.binread(__FILE__, 100, 2)
|
63
|
+
assert_equal(100, s.bytesize)
|
64
|
+
assert_equal('frozen', s[0..5])
|
65
|
+
end
|
66
|
+
|
67
|
+
BIN_DATA = "\x00\x01\x02\x03"
|
68
|
+
|
69
|
+
def test_binwrite
|
70
|
+
fn = '/tmp/test_binwrite'
|
71
|
+
FileUtils.rm(fn) rescue nil
|
72
|
+
|
73
|
+
len = IO.binwrite(fn, BIN_DATA)
|
74
|
+
assert_equal(4, len)
|
75
|
+
s = IO.binread(fn)
|
76
|
+
assert_equal(BIN_DATA, s)
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_foreach
|
80
|
+
lines = []
|
81
|
+
IO.foreach(__FILE__) { |l| lines << l }
|
82
|
+
assert_equal("# frozen_string_literal: true\n", lines[0])
|
83
|
+
assert_equal("end", lines[-1])
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_read
|
87
|
+
s = IO.read(__FILE__)
|
88
|
+
assert_kind_of(String, s)
|
89
|
+
assert(!s.empty?)
|
90
|
+
assert_equal(IO.orig_read(__FILE__), s)
|
91
|
+
|
92
|
+
s = IO.read(__FILE__, 100)
|
93
|
+
assert_equal(100, s.bytesize)
|
94
|
+
assert_equal(IO.orig_read(__FILE__, 100), s)
|
95
|
+
|
96
|
+
s = IO.read(__FILE__, 100, 2)
|
97
|
+
assert_equal(100, s.bytesize)
|
98
|
+
assert_equal('frozen', s[0..5])
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_readlines
|
102
|
+
lines = IO.readlines(__FILE__)
|
103
|
+
assert_equal("# frozen_string_literal: true\n", lines[0])
|
104
|
+
assert_equal("end", lines[-1])
|
105
|
+
end
|
106
|
+
|
107
|
+
WRITE_DATA = "foo\nbar קוקו"
|
108
|
+
|
109
|
+
def test_write
|
110
|
+
fn = '/tmp/test_write'
|
111
|
+
FileUtils.rm(fn) rescue nil
|
112
|
+
|
113
|
+
len = IO.write(fn, WRITE_DATA)
|
114
|
+
assert_equal(WRITE_DATA.bytesize, len)
|
115
|
+
s = IO.read(fn)
|
116
|
+
assert_equal(WRITE_DATA, s)
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_popen
|
120
|
+
counter = 0
|
121
|
+
timer = coproc {
|
122
|
+
throttled_loop(200) { counter += 1 }
|
123
|
+
}
|
124
|
+
|
125
|
+
IO.popen('sleep 0.01') { |io| io.read }
|
126
|
+
assert(counter >= 2)
|
127
|
+
|
128
|
+
result = nil
|
129
|
+
IO.popen('echo "foo"') { |io| result = io.read }
|
130
|
+
assert_equal("foo\n", result)
|
131
|
+
ensure
|
132
|
+
timer&.stop
|
133
|
+
end
|
42
134
|
end
|
data/test/test_kernel.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'minitest/autorun'
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'polyphony'
|
6
|
+
|
7
|
+
class KernelTest < MiniTest::Test
|
8
|
+
def setup
|
9
|
+
EV.rerun
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_system_method
|
13
|
+
counter = 0
|
14
|
+
timer = coproc {
|
15
|
+
throttled_loop(200) { counter += 1 }
|
16
|
+
}
|
17
|
+
|
18
|
+
system('sleep 0.01')
|
19
|
+
assert(counter >= 2)
|
20
|
+
|
21
|
+
result = system('echo "hello"')
|
22
|
+
assert_equal("hello\n", result)
|
23
|
+
ensure
|
24
|
+
timer&.stop
|
25
|
+
end
|
26
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: polyphony
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.17'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sharon Rosner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-05-
|
11
|
+
date: 2019-05-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: modulation
|
@@ -229,10 +229,13 @@ files:
|
|
229
229
|
- examples/interfaces/redis_client.rb
|
230
230
|
- examples/interfaces/redis_pubsub.rb
|
231
231
|
- examples/interfaces/redis_pubsub_perf.rb
|
232
|
+
- examples/io/cat.rb
|
232
233
|
- examples/io/echo_client.rb
|
233
234
|
- examples/io/echo_server.rb
|
234
235
|
- examples/io/echo_server_with_timeout.rb
|
235
236
|
- examples/io/echo_stdin.rb
|
237
|
+
- examples/io/io_read.rb
|
238
|
+
- examples/io/system.rb
|
236
239
|
- examples/performance/perf_multi_snooze.rb
|
237
240
|
- examples/performance/perf_snooze.rb
|
238
241
|
- examples/performance/thread-vs-fiber/polyphony_server.rb
|
@@ -298,6 +301,7 @@ files:
|
|
298
301
|
- test/test_core.rb
|
299
302
|
- test/test_ev.rb
|
300
303
|
- test/test_io.rb
|
304
|
+
- test/test_kernel.rb
|
301
305
|
homepage: http://github.com/digital-fabric/polyphony
|
302
306
|
licenses:
|
303
307
|
- MIT
|