uringmachine 0.31.0 → 0.33.0
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/CHANGELOG.md +9 -0
- data/README.md +36 -37
- data/TODO.md +40 -59
- data/benchmark/bm_io_pipe.rb +2 -2
- data/benchmark/common.rb +16 -16
- data/benchmark/gets.rb +7 -7
- data/benchmark/gets_concurrent.rb +12 -12
- data/benchmark/http_parse.rb +11 -11
- data/benchmark/http_server_accept_queue.rb +7 -7
- data/benchmark/http_server_multi_accept.rb +7 -7
- data/benchmark/http_server_multi_ractor.rb +7 -7
- data/benchmark/http_server_single_thread.rb +8 -8
- data/benchmark/openssl.rb +4 -4
- data/docs/um_api.md +4 -9
- data/examples/fiber_concurrency_io.rb +1 -1
- data/examples/fiber_concurrency_um.rb +16 -0
- data/examples/io_uring_simple.c +13 -4
- data/examples/pg.rb +2 -2
- data/examples/um_cancellation.rb +20 -0
- data/examples/um_fiber_scheduler.rb +10 -0
- data/examples/um_io.rb +19 -0
- data/examples/um_mo.c +32 -0
- data/examples/um_multishot.rb +15 -0
- data/examples/um_ssl.rb +11 -0
- data/ext/um/um.c +21 -76
- data/ext/um/um.h +22 -41
- data/ext/um/um_class.c +11 -65
- data/ext/um/um_ext.c +2 -4
- data/ext/um/{um_connection.c → um_io.c} +209 -210
- data/ext/um/{um_connection_class.c → um_io_class.c} +102 -102
- data/ext/um/um_op.c +0 -1
- data/ext/um/um_utils.c +0 -86
- data/lib/uringmachine/version.rb +1 -1
- data/lib/uringmachine.rb +12 -12
- data/test/{test_connection.rb → test_io.rb} +63 -63
- data/test/test_um.rb +17 -95
- metadata +13 -6
|
@@ -5,13 +5,13 @@ require 'securerandom'
|
|
|
5
5
|
require 'openssl'
|
|
6
6
|
require 'localhost/authority'
|
|
7
7
|
|
|
8
|
-
class
|
|
8
|
+
class IOBaseTest < UMBaseTest
|
|
9
9
|
attr_reader :conn
|
|
10
10
|
|
|
11
11
|
def setup
|
|
12
12
|
super
|
|
13
13
|
@rfd, @wfd = UM.pipe
|
|
14
|
-
@conn = UM::
|
|
14
|
+
@conn = UM::IO.new(@machine, @rfd)
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
def teardown
|
|
@@ -22,7 +22,7 @@ class ConnectionBaseTest < UMBaseTest
|
|
|
22
22
|
end
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
-
class
|
|
25
|
+
class IOTest < IOBaseTest
|
|
26
26
|
def buffer_metrics
|
|
27
27
|
machine.metrics.fetch_values(
|
|
28
28
|
:buffers_allocated,
|
|
@@ -33,7 +33,7 @@ class ConnectionTest < ConnectionBaseTest
|
|
|
33
33
|
)
|
|
34
34
|
end
|
|
35
35
|
|
|
36
|
-
def
|
|
36
|
+
def test_io_basic_usage
|
|
37
37
|
assert_equal [0, 0, 0, 0, 0], buffer_metrics
|
|
38
38
|
machine.write(@wfd, "foobar")
|
|
39
39
|
machine.close(@wfd)
|
|
@@ -53,9 +53,9 @@ class ConnectionTest < ConnectionBaseTest
|
|
|
53
53
|
assert_equal 0, machine.metrics[:ops_pending]
|
|
54
54
|
end
|
|
55
55
|
|
|
56
|
-
def
|
|
56
|
+
def test_io_clear
|
|
57
57
|
rfd, wfd = UM.pipe
|
|
58
|
-
conn = UM::
|
|
58
|
+
conn = UM::IO.new(machine, rfd)
|
|
59
59
|
|
|
60
60
|
assert_equal [0, 0, 0, 0, 0], buffer_metrics
|
|
61
61
|
machine.write(wfd, "foobar")
|
|
@@ -77,9 +77,9 @@ class ConnectionTest < ConnectionBaseTest
|
|
|
77
77
|
machine.close(wfd) rescue nil
|
|
78
78
|
end
|
|
79
79
|
|
|
80
|
-
def
|
|
80
|
+
def test_io_big_read
|
|
81
81
|
s1, s2 = UM.socketpair(UM::AF_UNIX, UM::SOCK_STREAM, 0)
|
|
82
|
-
conn = UM::
|
|
82
|
+
conn = UM::IO.new(machine, s2)
|
|
83
83
|
|
|
84
84
|
msg = '1234567' * 20000
|
|
85
85
|
|
|
@@ -96,9 +96,9 @@ class ConnectionTest < ConnectionBaseTest
|
|
|
96
96
|
machine.join(f)
|
|
97
97
|
end
|
|
98
98
|
|
|
99
|
-
def
|
|
99
|
+
def test_io_buffer_reuse
|
|
100
100
|
s1, s2 = UM.socketpair(UM::AF_UNIX, UM::SOCK_STREAM, 0)
|
|
101
|
-
conn = UM::
|
|
101
|
+
conn = UM::IO.new(machine, s2)
|
|
102
102
|
|
|
103
103
|
msg = '1234567' * 20000
|
|
104
104
|
|
|
@@ -131,7 +131,7 @@ class ConnectionTest < ConnectionBaseTest
|
|
|
131
131
|
machine.join(f)
|
|
132
132
|
end
|
|
133
133
|
|
|
134
|
-
def
|
|
134
|
+
def test_io_read_line
|
|
135
135
|
machine.write(@wfd, "foo\nbar\r\nbaz")
|
|
136
136
|
machine.close(@wfd)
|
|
137
137
|
|
|
@@ -145,7 +145,7 @@ class ConnectionTest < ConnectionBaseTest
|
|
|
145
145
|
assert_equal "baz", conn.read(-6)
|
|
146
146
|
end
|
|
147
147
|
|
|
148
|
-
def
|
|
148
|
+
def test_io_read_line_segmented
|
|
149
149
|
machine.write(@wfd, "foo\n")
|
|
150
150
|
assert_equal 'foo', conn.read_line(0)
|
|
151
151
|
|
|
@@ -163,7 +163,7 @@ class ConnectionTest < ConnectionBaseTest
|
|
|
163
163
|
assert_nil conn.read_line(0)
|
|
164
164
|
end
|
|
165
165
|
|
|
166
|
-
def
|
|
166
|
+
def test_io_read_line_maxlen
|
|
167
167
|
machine.write(@wfd, "foobar\r\n")
|
|
168
168
|
|
|
169
169
|
assert_nil conn.read_line(3)
|
|
@@ -188,7 +188,7 @@ class ConnectionTest < ConnectionBaseTest
|
|
|
188
188
|
assert_equal [16, 0, 256, 16384 * 16, 16384 * 16 - 17], buffer_metrics
|
|
189
189
|
end
|
|
190
190
|
|
|
191
|
-
def
|
|
191
|
+
def test_io_read
|
|
192
192
|
machine.write(@wfd, "foobarbazblahzzz")
|
|
193
193
|
machine.close(@wfd)
|
|
194
194
|
|
|
@@ -198,7 +198,7 @@ class ConnectionTest < ConnectionBaseTest
|
|
|
198
198
|
assert_nil conn.read(4)
|
|
199
199
|
end
|
|
200
200
|
|
|
201
|
-
def
|
|
201
|
+
def test_io_read_zero_len
|
|
202
202
|
machine.write(@wfd, "foobar")
|
|
203
203
|
|
|
204
204
|
assert_equal 'foobar', conn.read(0)
|
|
@@ -209,7 +209,7 @@ class ConnectionTest < ConnectionBaseTest
|
|
|
209
209
|
assert_nil conn.read(0)
|
|
210
210
|
end
|
|
211
211
|
|
|
212
|
-
def
|
|
212
|
+
def test_io_read_negative_len
|
|
213
213
|
machine.write(@wfd, "foobar")
|
|
214
214
|
|
|
215
215
|
assert_equal 'foo', conn.read(-3)
|
|
@@ -221,7 +221,7 @@ class ConnectionTest < ConnectionBaseTest
|
|
|
221
221
|
assert_nil conn.read(-3)
|
|
222
222
|
end
|
|
223
223
|
|
|
224
|
-
def
|
|
224
|
+
def test_io_read_to_delim
|
|
225
225
|
machine.write(@wfd, "abc,def,ghi")
|
|
226
226
|
machine.close(@wfd)
|
|
227
227
|
|
|
@@ -233,7 +233,7 @@ class ConnectionTest < ConnectionBaseTest
|
|
|
233
233
|
assert_equal 'ghi', conn.read_to_delim(',', -3)
|
|
234
234
|
end
|
|
235
235
|
|
|
236
|
-
def
|
|
236
|
+
def test_io_read_to_delim_invalid_delim
|
|
237
237
|
machine.write(@wfd, "abc,def,ghi")
|
|
238
238
|
|
|
239
239
|
assert_raises(ArgumentError) { conn.read_to_delim(:foo, 0) }
|
|
@@ -242,7 +242,7 @@ class ConnectionTest < ConnectionBaseTest
|
|
|
242
242
|
assert_raises(UM::Error) { conn.read_to_delim('🙂', 0) }
|
|
243
243
|
end
|
|
244
244
|
|
|
245
|
-
def
|
|
245
|
+
def test_io_skip
|
|
246
246
|
machine.write(@wfd, "foobarbaz")
|
|
247
247
|
|
|
248
248
|
conn.skip(2)
|
|
@@ -252,7 +252,7 @@ class ConnectionTest < ConnectionBaseTest
|
|
|
252
252
|
assert_equal 'az', conn.read(0)
|
|
253
253
|
end
|
|
254
254
|
|
|
255
|
-
def
|
|
255
|
+
def test_io_big_data
|
|
256
256
|
data = SecureRandom.random_bytes(300_000)
|
|
257
257
|
fiber = machine.spin {
|
|
258
258
|
machine.writev(@wfd, data)
|
|
@@ -273,7 +273,7 @@ class ConnectionTest < ConnectionBaseTest
|
|
|
273
273
|
assert_equal data, received.join
|
|
274
274
|
end
|
|
275
275
|
|
|
276
|
-
def
|
|
276
|
+
def test_io_read_each
|
|
277
277
|
bufs = []
|
|
278
278
|
f = machine.spin do
|
|
279
279
|
bufs << :ready
|
|
@@ -307,13 +307,13 @@ class ConnectionTest < ConnectionBaseTest
|
|
|
307
307
|
end
|
|
308
308
|
end
|
|
309
309
|
|
|
310
|
-
class
|
|
310
|
+
class IOWriteTest < UMBaseTest
|
|
311
311
|
attr_reader :conn
|
|
312
312
|
|
|
313
313
|
def setup
|
|
314
314
|
super
|
|
315
315
|
@s1, @s2 = UM.socketpair(UM::AF_UNIX, UM::SOCK_STREAM, 0)
|
|
316
|
-
@conn = UM::
|
|
316
|
+
@conn = UM::IO.new(@machine, @s1)
|
|
317
317
|
end
|
|
318
318
|
|
|
319
319
|
def teardown
|
|
@@ -323,7 +323,7 @@ class ConnectionWriteTest < UMBaseTest
|
|
|
323
323
|
super
|
|
324
324
|
end
|
|
325
325
|
|
|
326
|
-
def
|
|
326
|
+
def test_io_write_single_buf
|
|
327
327
|
assert_equal 3, conn.write('foo')
|
|
328
328
|
|
|
329
329
|
buf = +''
|
|
@@ -331,7 +331,7 @@ class ConnectionWriteTest < UMBaseTest
|
|
|
331
331
|
assert_equal 'foo', buf
|
|
332
332
|
end
|
|
333
333
|
|
|
334
|
-
def
|
|
334
|
+
def test_io_write_multi_buf
|
|
335
335
|
assert_equal 6, conn.write('foo', 'bar')
|
|
336
336
|
|
|
337
337
|
buf = +''
|
|
@@ -339,8 +339,8 @@ class ConnectionWriteTest < UMBaseTest
|
|
|
339
339
|
assert_equal 'foobar', buf
|
|
340
340
|
end
|
|
341
341
|
|
|
342
|
-
def
|
|
343
|
-
conn = machine.
|
|
342
|
+
def test_io_write_socket_mode
|
|
343
|
+
conn = machine.io(@s2, :socket)
|
|
344
344
|
|
|
345
345
|
assert_equal 6, conn.write('foo', 'bar')
|
|
346
346
|
|
|
@@ -349,7 +349,7 @@ class ConnectionWriteTest < UMBaseTest
|
|
|
349
349
|
assert_equal 'foobar', buf
|
|
350
350
|
end
|
|
351
351
|
|
|
352
|
-
def
|
|
352
|
+
def test_io_write_ssl_mode
|
|
353
353
|
ssl1 = OpenSSL::SSL::SSLSocket.new(IO.for_fd(@s1), Localhost::Authority.fetch.server_context)
|
|
354
354
|
ssl1.sync_close = true
|
|
355
355
|
ssl2 = OpenSSL::SSL::SSLSocket.new(IO.for_fd(@s2), OpenSSL::SSL::SSLContext.new)
|
|
@@ -363,8 +363,8 @@ class ConnectionWriteTest < UMBaseTest
|
|
|
363
363
|
ssl2.connect
|
|
364
364
|
refute_equal 0, @machine.metrics[:total_ops]
|
|
365
365
|
|
|
366
|
-
conn1 = machine.
|
|
367
|
-
conn2 = machine.
|
|
366
|
+
conn1 = machine.io(ssl1)
|
|
367
|
+
conn2 = machine.io(ssl2)
|
|
368
368
|
|
|
369
369
|
assert_equal 10, conn1.write('foobar', "\n", 'baz')
|
|
370
370
|
|
|
@@ -379,8 +379,8 @@ class ConnectionWriteTest < UMBaseTest
|
|
|
379
379
|
end
|
|
380
380
|
end
|
|
381
381
|
|
|
382
|
-
class
|
|
383
|
-
def
|
|
382
|
+
class IORespTest < IOBaseTest
|
|
383
|
+
def test_io_resp_read
|
|
384
384
|
machine.write(@wfd, "+foo bar\r\n")
|
|
385
385
|
assert_equal "foo bar", conn.resp_read
|
|
386
386
|
|
|
@@ -389,12 +389,12 @@ class ConnectionRespTest < ConnectionBaseTest
|
|
|
389
389
|
|
|
390
390
|
machine.write(@wfd, "-foobar\r\n")
|
|
391
391
|
o = conn.resp_read
|
|
392
|
-
assert_kind_of UM::
|
|
392
|
+
assert_kind_of UM::IO::RESPError, o
|
|
393
393
|
assert_equal "foobar", o.message
|
|
394
394
|
|
|
395
395
|
machine.write(@wfd, "!3\r\nbaz\r\n")
|
|
396
396
|
o = conn.resp_read
|
|
397
|
-
assert_kind_of UM::
|
|
397
|
+
assert_kind_of UM::IO::RESPError, o
|
|
398
398
|
assert_equal "baz", o.message
|
|
399
399
|
|
|
400
400
|
machine.write(@wfd, ":123\r\n")
|
|
@@ -443,7 +443,7 @@ class ConnectionRespTest < ConnectionBaseTest
|
|
|
443
443
|
assert_equal({ 'a' => 42, 'b' => ['foo', 'bar', 'baz'] }, conn.resp_read)
|
|
444
444
|
end
|
|
445
445
|
|
|
446
|
-
def
|
|
446
|
+
def test_io_resp_read_segmented
|
|
447
447
|
machine.write(@wfd, "\n")
|
|
448
448
|
assert_equal "", conn.read_line(0)
|
|
449
449
|
|
|
@@ -458,8 +458,8 @@ class ConnectionRespTest < ConnectionBaseTest
|
|
|
458
458
|
assert_equal "bazbug", conn.resp_read
|
|
459
459
|
end
|
|
460
460
|
|
|
461
|
-
def
|
|
462
|
-
writer = machine.
|
|
461
|
+
def test_io_resp_write
|
|
462
|
+
writer = machine.io(@wfd)
|
|
463
463
|
|
|
464
464
|
writer.resp_write(nil);
|
|
465
465
|
assert_equal "_\r\n", conn.read(-100)
|
|
@@ -489,8 +489,8 @@ class ConnectionRespTest < ConnectionBaseTest
|
|
|
489
489
|
assert_equal "%2\r\n$3\r\nfoo\r\n$3\r\nbar\r\n$3\r\nbaz\r\n:42\r\n", conn.read(-100)
|
|
490
490
|
end
|
|
491
491
|
|
|
492
|
-
def
|
|
493
|
-
s = UM::
|
|
492
|
+
def test_io_resp_encode
|
|
493
|
+
s = UM::IO
|
|
494
494
|
assert_equal "_\r\n", s.resp_encode(+'', nil)
|
|
495
495
|
assert_equal "#t\r\n", s.resp_encode(+'', true)
|
|
496
496
|
assert_equal "#f\r\n", s.resp_encode(+'', false)
|
|
@@ -507,7 +507,7 @@ class ConnectionRespTest < ConnectionBaseTest
|
|
|
507
507
|
end
|
|
508
508
|
end
|
|
509
509
|
|
|
510
|
-
class
|
|
510
|
+
class IOStressTest < UMBaseTest
|
|
511
511
|
def setup
|
|
512
512
|
super
|
|
513
513
|
|
|
@@ -525,7 +525,7 @@ class ConnectionStressTest < UMBaseTest
|
|
|
525
525
|
|
|
526
526
|
def start_connection_fiber(fd)
|
|
527
527
|
machine.spin do
|
|
528
|
-
conn = UM::
|
|
528
|
+
conn = UM::IO.new(machine, fd)
|
|
529
529
|
while (msg = conn.read_line(0))
|
|
530
530
|
@received << msg
|
|
531
531
|
end
|
|
@@ -537,7 +537,7 @@ class ConnectionStressTest < UMBaseTest
|
|
|
537
537
|
end
|
|
538
538
|
end
|
|
539
539
|
|
|
540
|
-
def
|
|
540
|
+
def test_io_server_big_lines
|
|
541
541
|
server_fibers = []
|
|
542
542
|
server_fibers << machine.spin do
|
|
543
543
|
machine.accept_each(@listen_fd) { |fd|
|
|
@@ -580,7 +580,7 @@ class ConnectionStressTest < UMBaseTest
|
|
|
580
580
|
assert_equal msg * client_count, @received.map { it + "\n" }.join
|
|
581
581
|
end
|
|
582
582
|
|
|
583
|
-
def
|
|
583
|
+
def test_io_server_http
|
|
584
584
|
server_fibers = []
|
|
585
585
|
server_fibers << machine.spin do
|
|
586
586
|
machine.accept_each(@listen_fd) { |fd|
|
|
@@ -620,10 +620,10 @@ class ConnectionStressTest < UMBaseTest
|
|
|
620
620
|
end
|
|
621
621
|
end
|
|
622
622
|
|
|
623
|
-
class
|
|
624
|
-
def
|
|
623
|
+
class IODevRandomTest < UMBaseTest
|
|
624
|
+
def test_io_dev_random_read_line
|
|
625
625
|
fd = machine.open('/dev/random', UM::O_RDONLY)
|
|
626
|
-
conn = UM::
|
|
626
|
+
conn = UM::IO.new(machine, fd)
|
|
627
627
|
|
|
628
628
|
n = 100000
|
|
629
629
|
lines = []
|
|
@@ -639,11 +639,11 @@ class ConnectionDevRandomTest < UMBaseTest
|
|
|
639
639
|
|
|
640
640
|
def read_line_do(n, acc)
|
|
641
641
|
fd = @machine.open('/dev/random', UM::O_RDONLY)
|
|
642
|
-
conn = UM::
|
|
642
|
+
conn = UM::IO.new(@machine, fd)
|
|
643
643
|
n.times { acc << conn.read_line(0) }
|
|
644
644
|
end
|
|
645
645
|
|
|
646
|
-
def
|
|
646
|
+
def test_io_dev_random_read_line_concurrent
|
|
647
647
|
acc = []
|
|
648
648
|
c = 1
|
|
649
649
|
n = 100000
|
|
@@ -654,9 +654,9 @@ class ConnectionDevRandomTest < UMBaseTest
|
|
|
654
654
|
assert_equal c * n, acc.size
|
|
655
655
|
end
|
|
656
656
|
|
|
657
|
-
def
|
|
657
|
+
def test_io_dev_random_read
|
|
658
658
|
fd = machine.open('/dev/random', UM::O_RDONLY)
|
|
659
|
-
conn = UM::
|
|
659
|
+
conn = UM::IO.new(machine, fd)
|
|
660
660
|
|
|
661
661
|
n = 256
|
|
662
662
|
size = 65536 * 8
|
|
@@ -676,35 +676,35 @@ class ConnectionDevRandomTest < UMBaseTest
|
|
|
676
676
|
end
|
|
677
677
|
end
|
|
678
678
|
|
|
679
|
-
class
|
|
680
|
-
def
|
|
679
|
+
class IOModeTest < UMBaseTest
|
|
680
|
+
def test_io_default_mode
|
|
681
681
|
r, w = UM.pipe
|
|
682
|
-
conn = UM::
|
|
682
|
+
conn = UM::IO.new(machine, r)
|
|
683
683
|
assert_equal :fd, conn.mode
|
|
684
684
|
ensure
|
|
685
685
|
machine.close(r) rescue nil
|
|
686
686
|
machine.close(w) rescue nil
|
|
687
687
|
end
|
|
688
688
|
|
|
689
|
-
def
|
|
689
|
+
def test_io_default_mode_ssl
|
|
690
690
|
authority = Localhost::Authority.fetch
|
|
691
691
|
@server_ctx = authority.server_context
|
|
692
692
|
sock1, sock2 = UNIXSocket.pair
|
|
693
693
|
|
|
694
694
|
s1 = OpenSSL::SSL::SSLSocket.new(sock1, @server_ctx)
|
|
695
|
-
conn = UM::
|
|
695
|
+
conn = UM::IO.new(machine, s1)
|
|
696
696
|
assert_equal :ssl, conn.mode
|
|
697
697
|
ensure
|
|
698
698
|
sock1&.close rescue nil
|
|
699
699
|
sock2&.close rescue nil
|
|
700
700
|
end
|
|
701
701
|
|
|
702
|
-
def
|
|
702
|
+
def test_io_socket_mode_non_socket
|
|
703
703
|
r, w = UM.pipe
|
|
704
704
|
machine.write(w, 'foobar')
|
|
705
705
|
machine.close(w)
|
|
706
706
|
|
|
707
|
-
conn = UM::
|
|
707
|
+
conn = UM::IO.new(machine, r, :socket)
|
|
708
708
|
assert_equal :socket, conn.mode
|
|
709
709
|
# assert :socket, conn.mode
|
|
710
710
|
assert_raises(Errno::ENOTSOCK) { conn.read(0) }
|
|
@@ -713,12 +713,12 @@ class ConnectionModeTest < UMBaseTest
|
|
|
713
713
|
machine.close(w) rescue nil
|
|
714
714
|
end
|
|
715
715
|
|
|
716
|
-
def
|
|
716
|
+
def test_io_socket_mode_socket
|
|
717
717
|
r, w = UM.socketpair(UM::AF_UNIX, UM::SOCK_STREAM, 0)
|
|
718
718
|
machine.write(w, 'foobar')
|
|
719
719
|
machine.close(w)
|
|
720
720
|
|
|
721
|
-
conn = UM::
|
|
721
|
+
conn = UM::IO.new(machine, r, :socket)
|
|
722
722
|
assert_equal :socket, conn.mode
|
|
723
723
|
buf = conn.read(0)
|
|
724
724
|
assert_equal 'foobar', buf
|
|
@@ -727,7 +727,7 @@ class ConnectionModeTest < UMBaseTest
|
|
|
727
727
|
machine.close(w) rescue nil
|
|
728
728
|
end
|
|
729
729
|
|
|
730
|
-
def
|
|
730
|
+
def test_io_ssl_mode
|
|
731
731
|
authority = Localhost::Authority.fetch
|
|
732
732
|
@server_ctx = authority.server_context
|
|
733
733
|
sock1, sock2 = UNIXSocket.pair
|
|
@@ -751,7 +751,7 @@ class ConnectionModeTest < UMBaseTest
|
|
|
751
751
|
assert_equal 10, @machine.ssl_write(s1, buf, buf.bytesize)
|
|
752
752
|
buf = +''
|
|
753
753
|
|
|
754
|
-
conn = UM::
|
|
754
|
+
conn = UM::IO.new(machine, s2, :ssl)
|
|
755
755
|
assert_equal "foobar", conn.read_line(0)
|
|
756
756
|
|
|
757
757
|
buf = "buh"
|
|
@@ -774,8 +774,8 @@ class ConnectionModeTest < UMBaseTest
|
|
|
774
774
|
end
|
|
775
775
|
end
|
|
776
776
|
|
|
777
|
-
class
|
|
778
|
-
def
|
|
777
|
+
class IOByteCountsTest < IOBaseTest
|
|
778
|
+
def test_io_byte_counts
|
|
779
779
|
machine.write(@wfd, "foobar")
|
|
780
780
|
|
|
781
781
|
assert_equal 0, conn.consumed
|
data/test/test_um.rb
CHANGED
|
@@ -653,8 +653,6 @@ class ReadEachTest < UMBaseTest
|
|
|
653
653
|
def test_read_each
|
|
654
654
|
r, w = IO.pipe
|
|
655
655
|
bufs = []
|
|
656
|
-
bgid = machine.setup_buffer_ring(4096, 1024)
|
|
657
|
-
assert_equal 0, bgid
|
|
658
656
|
|
|
659
657
|
f = Fiber.new do
|
|
660
658
|
w << 'foo'
|
|
@@ -669,7 +667,7 @@ class ReadEachTest < UMBaseTest
|
|
|
669
667
|
|
|
670
668
|
machine.schedule(f, nil)
|
|
671
669
|
|
|
672
|
-
machine.read_each(r.fileno
|
|
670
|
+
machine.read_each(r.fileno) do |buf|
|
|
673
671
|
bufs << buf
|
|
674
672
|
end
|
|
675
673
|
|
|
@@ -681,15 +679,13 @@ class ReadEachTest < UMBaseTest
|
|
|
681
679
|
# send once and close write fd
|
|
682
680
|
def test_read_each_raising_1
|
|
683
681
|
r, w = IO.pipe
|
|
684
|
-
bgid = machine.setup_buffer_ring(4096, 1024)
|
|
685
|
-
assert_equal 0, bgid
|
|
686
682
|
|
|
687
683
|
w << 'foo'
|
|
688
684
|
w.close
|
|
689
685
|
|
|
690
686
|
e = nil
|
|
691
687
|
begin
|
|
692
|
-
machine.read_each(r.fileno
|
|
688
|
+
machine.read_each(r.fileno) do |buf|
|
|
693
689
|
raise 'hi'
|
|
694
690
|
end
|
|
695
691
|
rescue => e
|
|
@@ -704,14 +700,12 @@ class ReadEachTest < UMBaseTest
|
|
|
704
700
|
# send once and leave write fd open
|
|
705
701
|
def test_read_each_raising_2
|
|
706
702
|
r, w = IO.pipe
|
|
707
|
-
bgid = machine.setup_buffer_ring(4096, 1024)
|
|
708
|
-
assert_equal 0, bgid
|
|
709
703
|
|
|
710
704
|
w << 'foo'
|
|
711
705
|
|
|
712
706
|
e = nil
|
|
713
707
|
begin
|
|
714
|
-
machine.read_each(r.fileno
|
|
708
|
+
machine.read_each(r.fileno) do |buf|
|
|
715
709
|
raise 'hi'
|
|
716
710
|
end
|
|
717
711
|
rescue => e
|
|
@@ -728,15 +722,13 @@ class ReadEachTest < UMBaseTest
|
|
|
728
722
|
# send twice
|
|
729
723
|
def test_read_each_raising_3
|
|
730
724
|
r, w = IO.pipe
|
|
731
|
-
bgid = machine.setup_buffer_ring(4096, 1024)
|
|
732
|
-
assert_equal 0, bgid
|
|
733
725
|
|
|
734
726
|
w << 'foo'
|
|
735
727
|
w << 'bar'
|
|
736
728
|
|
|
737
729
|
e = nil
|
|
738
730
|
begin
|
|
739
|
-
machine.read_each(r.fileno
|
|
731
|
+
machine.read_each(r.fileno) do |buf|
|
|
740
732
|
raise 'hi'
|
|
741
733
|
end
|
|
742
734
|
rescue => e
|
|
@@ -752,7 +744,6 @@ class ReadEachTest < UMBaseTest
|
|
|
752
744
|
|
|
753
745
|
def test_read_each_break
|
|
754
746
|
r, w = IO.pipe
|
|
755
|
-
bgid = machine.setup_buffer_ring(4096, 1024)
|
|
756
747
|
|
|
757
748
|
t = Thread.new do
|
|
758
749
|
sleep 0.1
|
|
@@ -762,7 +753,7 @@ class ReadEachTest < UMBaseTest
|
|
|
762
753
|
end
|
|
763
754
|
|
|
764
755
|
bufs = []
|
|
765
|
-
machine.read_each(r.fileno
|
|
756
|
+
machine.read_each(r.fileno) do |b|
|
|
766
757
|
bufs << b
|
|
767
758
|
break
|
|
768
759
|
end
|
|
@@ -779,13 +770,12 @@ class ReadEachTest < UMBaseTest
|
|
|
779
770
|
|
|
780
771
|
def test_read_each_timeout
|
|
781
772
|
r, _w = IO.pipe
|
|
782
|
-
bgid = machine.setup_buffer_ring(4096, 1024)
|
|
783
773
|
|
|
784
774
|
bufs = []
|
|
785
775
|
e = nil
|
|
786
776
|
begin
|
|
787
777
|
machine.timeout(0.01, TOError) do
|
|
788
|
-
machine.read_each(r.fileno
|
|
778
|
+
machine.read_each(r.fileno) do |b|
|
|
789
779
|
bufs << b
|
|
790
780
|
end
|
|
791
781
|
end
|
|
@@ -804,10 +794,9 @@ class ReadEachTest < UMBaseTest
|
|
|
804
794
|
|
|
805
795
|
def test_read_each_bad_file
|
|
806
796
|
_r, w = IO.pipe
|
|
807
|
-
bgid = machine.setup_buffer_ring(4096, 1024)
|
|
808
797
|
|
|
809
798
|
assert_raises(Errno::EBADF) do
|
|
810
|
-
machine.read_each(w.fileno
|
|
799
|
+
machine.read_each(w.fileno)
|
|
811
800
|
end
|
|
812
801
|
assert_equal 0, machine.metrics[:ops_pending]
|
|
813
802
|
assert_equal 256, machine.metrics[:ops_free]
|
|
@@ -1892,15 +1881,9 @@ class RecvEachTest < UMBaseTest
|
|
|
1892
1881
|
res = machine.connect(fd, '127.0.0.1', @port)
|
|
1893
1882
|
assert_equal 0, res
|
|
1894
1883
|
|
|
1895
|
-
bgid = machine.setup_buffer_ring(4096, 1024)
|
|
1896
|
-
assert_equal 0, bgid
|
|
1897
|
-
|
|
1898
|
-
bgid2 = machine.setup_buffer_ring(4096, 1024)
|
|
1899
|
-
assert_equal 1, bgid2
|
|
1900
|
-
|
|
1901
1884
|
bufs = []
|
|
1902
1885
|
|
|
1903
|
-
machine.recv_each(fd,
|
|
1886
|
+
machine.recv_each(fd, 0) do |buf|
|
|
1904
1887
|
bufs << buf
|
|
1905
1888
|
end
|
|
1906
1889
|
assert_equal ['abc', 'def', 'ghi'], bufs
|
|
@@ -1922,14 +1905,11 @@ class RecvEachTest < UMBaseTest
|
|
|
1922
1905
|
res = machine.connect(fd, '127.0.0.1', @port)
|
|
1923
1906
|
assert_equal 0, res
|
|
1924
1907
|
|
|
1925
|
-
bgid = machine.setup_buffer_ring(4096, 1024)
|
|
1926
|
-
assert_equal 0, bgid
|
|
1927
|
-
|
|
1928
1908
|
bufs = []
|
|
1929
1909
|
e = nil
|
|
1930
1910
|
begin
|
|
1931
1911
|
machine.timeout(0.01, TOError) do
|
|
1932
|
-
machine.recv_each(fd,
|
|
1912
|
+
machine.recv_each(fd, 0) do |buf|
|
|
1933
1913
|
bufs << buf
|
|
1934
1914
|
end
|
|
1935
1915
|
end
|
|
@@ -1953,9 +1933,6 @@ class RecvEachTest < UMBaseTest
|
|
|
1953
1933
|
res = machine.connect(fd, '127.0.0.1', @port)
|
|
1954
1934
|
assert_equal 0, res
|
|
1955
1935
|
|
|
1956
|
-
bgid = machine.setup_buffer_ring(4096, 1024)
|
|
1957
|
-
assert_equal 0, bgid
|
|
1958
|
-
|
|
1959
1936
|
bufs = []
|
|
1960
1937
|
e = nil
|
|
1961
1938
|
|
|
@@ -1965,7 +1942,7 @@ class RecvEachTest < UMBaseTest
|
|
|
1965
1942
|
}
|
|
1966
1943
|
|
|
1967
1944
|
begin
|
|
1968
|
-
machine.recv_each(fd,
|
|
1945
|
+
machine.recv_each(fd, 0) do |buf|
|
|
1969
1946
|
bufs << buf
|
|
1970
1947
|
end
|
|
1971
1948
|
rescue => e
|
|
@@ -3097,61 +3074,6 @@ class ForkTest < UMBaseTest
|
|
|
3097
3074
|
end
|
|
3098
3075
|
end
|
|
3099
3076
|
|
|
3100
|
-
class SendBundleTest < UMBaseTest
|
|
3101
|
-
def setup
|
|
3102
|
-
super
|
|
3103
|
-
@client_fd, @server_fd = UM.socketpair(UM::AF_UNIX, UM::SOCK_STREAM, 0)
|
|
3104
|
-
end
|
|
3105
|
-
|
|
3106
|
-
def test_send_bundle_splat
|
|
3107
|
-
bgid = machine.setup_buffer_ring(0, 8)
|
|
3108
|
-
assert_equal 0, bgid
|
|
3109
|
-
|
|
3110
|
-
strs = ['foo', 'bar', 'bazzzzz']
|
|
3111
|
-
len = strs.inject(0) { |len, s| len + s.bytesize }
|
|
3112
|
-
|
|
3113
|
-
ret = machine.send_bundle(@client_fd, bgid, *strs)
|
|
3114
|
-
assert_equal len, ret
|
|
3115
|
-
|
|
3116
|
-
buf = +''
|
|
3117
|
-
ret = machine.recv(@server_fd, buf, 8192, 0)
|
|
3118
|
-
assert_equal len, ret
|
|
3119
|
-
assert_equal strs.join, buf
|
|
3120
|
-
end
|
|
3121
|
-
|
|
3122
|
-
def test_send_bundle_array
|
|
3123
|
-
bgid = machine.setup_buffer_ring(0, 8)
|
|
3124
|
-
assert_equal 0, bgid
|
|
3125
|
-
|
|
3126
|
-
strs = ['foo', 'bar', 'bazzzzz']
|
|
3127
|
-
len = strs.inject(0) { |len, s| len + s.bytesize }
|
|
3128
|
-
|
|
3129
|
-
ret = machine.send_bundle(@client_fd, bgid, strs)
|
|
3130
|
-
assert_equal len, ret
|
|
3131
|
-
|
|
3132
|
-
buf = +''
|
|
3133
|
-
ret = machine.recv(@server_fd, buf, 8192, 0)
|
|
3134
|
-
assert_equal len, ret
|
|
3135
|
-
assert_equal strs.join, buf
|
|
3136
|
-
end
|
|
3137
|
-
|
|
3138
|
-
def test_send_bundle_non_strings
|
|
3139
|
-
bgid = machine.setup_buffer_ring(0, 8)
|
|
3140
|
-
assert_equal 0, bgid
|
|
3141
|
-
|
|
3142
|
-
strs = [42, 'bar', false]
|
|
3143
|
-
len = strs.inject(0) { |len, s| len + s.to_s.bytesize }
|
|
3144
|
-
|
|
3145
|
-
ret = machine.send_bundle(@client_fd, bgid, strs)
|
|
3146
|
-
assert_equal len, ret
|
|
3147
|
-
|
|
3148
|
-
buf = +''
|
|
3149
|
-
ret = machine.recv(@server_fd, buf, 8192, 0)
|
|
3150
|
-
assert_equal len, ret
|
|
3151
|
-
assert_equal strs.map(&:to_s).join, buf
|
|
3152
|
-
end
|
|
3153
|
-
end
|
|
3154
|
-
|
|
3155
3077
|
class MetricsTest < UMBaseTest
|
|
3156
3078
|
def test_metrics_empty
|
|
3157
3079
|
assert_equal({
|
|
@@ -3506,7 +3428,7 @@ class SetChildSubreaperTest < Minitest::Test
|
|
|
3506
3428
|
end
|
|
3507
3429
|
end
|
|
3508
3430
|
|
|
3509
|
-
class
|
|
3431
|
+
class IOMethodTest < UMBaseTest
|
|
3510
3432
|
def setup
|
|
3511
3433
|
super
|
|
3512
3434
|
@rfd, @wfd = UM.pipe
|
|
@@ -3519,12 +3441,12 @@ class ConnectionMethodTest < UMBaseTest
|
|
|
3519
3441
|
super
|
|
3520
3442
|
end
|
|
3521
3443
|
|
|
3522
|
-
def
|
|
3444
|
+
def test_io_method
|
|
3523
3445
|
machine.write(@wfd, "foobar")
|
|
3524
3446
|
machine.close(@wfd)
|
|
3525
3447
|
|
|
3526
|
-
conn = machine.
|
|
3527
|
-
assert_kind_of UM::
|
|
3448
|
+
conn = machine.io(@rfd)
|
|
3449
|
+
assert_kind_of UM::IO, conn
|
|
3528
3450
|
|
|
3529
3451
|
buf = conn.read(3)
|
|
3530
3452
|
assert_equal 'foo', buf
|
|
@@ -3536,13 +3458,13 @@ class ConnectionMethodTest < UMBaseTest
|
|
|
3536
3458
|
conn.clear
|
|
3537
3459
|
end
|
|
3538
3460
|
|
|
3539
|
-
def
|
|
3461
|
+
def test_io_method_with_block
|
|
3540
3462
|
machine.write(@wfd, "foobar")
|
|
3541
3463
|
machine.close(@wfd)
|
|
3542
3464
|
|
|
3543
3465
|
bufs = []
|
|
3544
3466
|
conn_obj = nil
|
|
3545
|
-
res = machine.
|
|
3467
|
+
res = machine.io(@rfd) do |s|
|
|
3546
3468
|
conn_obj = s
|
|
3547
3469
|
|
|
3548
3470
|
bufs << s.read(3)
|
|
@@ -3551,7 +3473,7 @@ class ConnectionMethodTest < UMBaseTest
|
|
|
3551
3473
|
:foo
|
|
3552
3474
|
end
|
|
3553
3475
|
|
|
3554
|
-
assert_kind_of UM::
|
|
3476
|
+
assert_kind_of UM::IO, conn_obj
|
|
3555
3477
|
assert conn_obj.eof?
|
|
3556
3478
|
assert_equal ['foo', 'bar'], bufs
|
|
3557
3479
|
assert_equal :foo, res
|