polyphony 0.94 → 0.95
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/.github/workflows/test.yml +2 -2
- data/.gitignore +3 -3
- data/CHANGELOG.md +14 -0
- data/docs/api-reference/fiber.md +2 -2
- data/docs/api-reference/object.md +3 -3
- data/docs/main-concepts/exception-handling.md +2 -2
- data/ext/polyphony/backend_common.c +3 -3
- data/ext/polyphony/backend_io_uring.c +18 -16
- data/ext/polyphony/event.c +1 -1
- data/ext/polyphony/extconf.rb +5 -3
- data/ext/polyphony/fiber.c +5 -13
- data/ext/polyphony/io_extensions.c +1 -1
- data/ext/polyphony/pipe.c +1 -1
- data/ext/polyphony/polyphony.c +1 -1
- data/ext/polyphony/polyphony_ext.c +1 -1
- data/ext/polyphony/queue.c +1 -1
- data/ext/polyphony/ring_buffer.c +1 -0
- data/ext/polyphony/socket_extensions.c +1 -1
- data/ext/polyphony/thread.c +1 -1
- data/lib/polyphony/extensions/enumerator.rb +16 -0
- data/lib/polyphony/extensions/socket.rb +2 -0
- data/lib/polyphony/extensions.rb +1 -0
- data/lib/polyphony/version.rb +1 -1
- data/polyphony.gemspec +2 -2
- data/test/test_backend.rb +5 -1
- data/test/test_enumerator.rb +46 -0
- data/test/test_io.rb +241 -216
- data/test/test_socket.rb +1 -1
- data/test/test_thread_pool.rb +3 -3
- data/vendor/liburing/.github/workflows/build.yml +51 -5
- data/vendor/liburing/.github/workflows/shellcheck.yml +1 -1
- data/vendor/liburing/.gitignore +6 -123
- data/vendor/liburing/CHANGELOG +35 -0
- data/vendor/liburing/CITATION.cff +11 -0
- data/vendor/liburing/LICENSE +16 -3
- data/vendor/liburing/Makefile +3 -1
- data/vendor/liburing/Makefile.common +1 -0
- data/vendor/liburing/README +14 -2
- data/vendor/liburing/SECURITY.md +6 -0
- data/vendor/liburing/configure +16 -15
- data/vendor/liburing/examples/Makefile +4 -1
- data/vendor/liburing/examples/io_uring-udp.c +395 -0
- data/vendor/liburing/examples/poll-bench.c +101 -0
- data/vendor/liburing/examples/send-zerocopy.c +339 -0
- data/vendor/liburing/liburing.spec +1 -1
- data/vendor/liburing/man/io_uring.7 +38 -11
- data/vendor/liburing/man/io_uring_buf_ring_add.3 +53 -0
- data/vendor/liburing/man/io_uring_buf_ring_advance.3 +31 -0
- data/vendor/liburing/man/io_uring_buf_ring_cq_advance.3 +41 -0
- data/vendor/liburing/man/io_uring_buf_ring_init.3 +30 -0
- data/vendor/liburing/man/io_uring_buf_ring_mask.3 +27 -0
- data/vendor/liburing/man/io_uring_cq_advance.3 +29 -15
- data/vendor/liburing/man/io_uring_cq_has_overflow.3 +25 -0
- data/vendor/liburing/man/io_uring_cq_ready.3 +9 -8
- data/vendor/liburing/man/io_uring_cqe_get_data.3 +32 -13
- data/vendor/liburing/man/io_uring_cqe_get_data64.3 +1 -0
- data/vendor/liburing/man/io_uring_cqe_seen.3 +22 -12
- data/vendor/liburing/man/io_uring_enter.2 +249 -32
- data/vendor/liburing/man/io_uring_enter2.2 +1 -0
- data/vendor/liburing/man/io_uring_free_probe.3 +11 -8
- data/vendor/liburing/man/io_uring_get_events.3 +33 -0
- data/vendor/liburing/man/io_uring_get_probe.3 +9 -8
- data/vendor/liburing/man/io_uring_get_sqe.3 +29 -10
- data/vendor/liburing/man/io_uring_opcode_supported.3 +11 -10
- data/vendor/liburing/man/io_uring_peek_cqe.3 +38 -0
- data/vendor/liburing/man/io_uring_prep_accept.3 +197 -0
- data/vendor/liburing/man/io_uring_prep_accept_direct.3 +1 -0
- data/vendor/liburing/man/io_uring_prep_cancel.3 +118 -0
- data/vendor/liburing/man/io_uring_prep_cancel64.3 +1 -0
- data/vendor/liburing/man/io_uring_prep_close.3 +59 -0
- data/vendor/liburing/man/io_uring_prep_close_direct.3 +1 -0
- data/vendor/liburing/man/io_uring_prep_connect.3 +66 -0
- data/vendor/liburing/man/io_uring_prep_fadvise.3 +59 -0
- data/vendor/liburing/man/io_uring_prep_fallocate.3 +59 -0
- data/vendor/liburing/man/io_uring_prep_files_update.3 +92 -0
- data/vendor/liburing/man/io_uring_prep_fsync.3 +70 -0
- data/vendor/liburing/man/io_uring_prep_link.3 +1 -0
- data/vendor/liburing/man/io_uring_prep_linkat.3 +91 -0
- data/vendor/liburing/man/io_uring_prep_madvise.3 +56 -0
- data/vendor/liburing/man/io_uring_prep_mkdir.3 +1 -0
- data/vendor/liburing/man/io_uring_prep_mkdirat.3 +83 -0
- data/vendor/liburing/man/io_uring_prep_msg_ring.3 +39 -25
- data/vendor/liburing/man/io_uring_prep_multishot_accept.3 +1 -0
- data/vendor/liburing/man/io_uring_prep_multishot_accept_direct.3 +1 -0
- data/vendor/liburing/man/io_uring_prep_nop.3 +28 -0
- data/vendor/liburing/man/io_uring_prep_openat.3 +117 -0
- data/vendor/liburing/man/io_uring_prep_openat2.3 +117 -0
- data/vendor/liburing/man/io_uring_prep_openat2_direct.3 +1 -0
- data/vendor/liburing/man/io_uring_prep_openat_direct.3 +1 -0
- data/vendor/liburing/man/io_uring_prep_poll_add.3 +72 -0
- data/vendor/liburing/man/io_uring_prep_poll_multishot.3 +1 -0
- data/vendor/liburing/man/io_uring_prep_poll_remove.3 +55 -0
- data/vendor/liburing/man/io_uring_prep_poll_update.3 +89 -0
- data/vendor/liburing/man/io_uring_prep_provide_buffers.3 +131 -0
- data/vendor/liburing/man/io_uring_prep_read.3 +33 -14
- data/vendor/liburing/man/io_uring_prep_read_fixed.3 +39 -21
- data/vendor/liburing/man/io_uring_prep_readv.3 +49 -15
- data/vendor/liburing/man/io_uring_prep_readv2.3 +49 -17
- data/vendor/liburing/man/io_uring_prep_recv.3 +105 -0
- data/vendor/liburing/man/io_uring_prep_recv_multishot.3 +1 -0
- data/vendor/liburing/man/io_uring_prep_recvmsg.3 +124 -0
- data/vendor/liburing/man/io_uring_prep_recvmsg_multishot.3 +1 -0
- data/vendor/liburing/man/io_uring_prep_remove_buffers.3 +52 -0
- data/vendor/liburing/man/io_uring_prep_rename.3 +1 -0
- data/vendor/liburing/man/io_uring_prep_renameat.3 +96 -0
- data/vendor/liburing/man/io_uring_prep_send.3 +57 -0
- data/vendor/liburing/man/io_uring_prep_send_zc.3 +64 -0
- data/vendor/liburing/man/io_uring_prep_sendmsg.3 +69 -0
- data/vendor/liburing/man/io_uring_prep_shutdown.3 +53 -0
- data/vendor/liburing/man/io_uring_prep_socket.3 +118 -0
- data/vendor/liburing/man/io_uring_prep_socket_direct.3 +1 -0
- data/vendor/liburing/man/io_uring_prep_socket_direct_alloc.3 +1 -0
- data/vendor/liburing/man/io_uring_prep_splice.3 +80 -0
- data/vendor/liburing/man/io_uring_prep_statx.3 +74 -0
- data/vendor/liburing/man/io_uring_prep_symlink.3 +1 -0
- data/vendor/liburing/man/io_uring_prep_symlinkat.3 +85 -0
- data/vendor/liburing/man/io_uring_prep_sync_file_range.3 +59 -0
- data/vendor/liburing/man/io_uring_prep_tee.3 +74 -0
- data/vendor/liburing/man/io_uring_prep_timeout.3 +95 -0
- data/vendor/liburing/man/io_uring_prep_timeout_remove.3 +1 -0
- data/vendor/liburing/man/io_uring_prep_timeout_update.3 +98 -0
- data/vendor/liburing/man/io_uring_prep_unlink.3 +1 -0
- data/vendor/liburing/man/io_uring_prep_unlinkat.3 +82 -0
- data/vendor/liburing/man/io_uring_prep_write.3 +32 -15
- data/vendor/liburing/man/io_uring_prep_write_fixed.3 +39 -21
- data/vendor/liburing/man/io_uring_prep_writev.3 +50 -16
- data/vendor/liburing/man/io_uring_prep_writev2.3 +50 -17
- data/vendor/liburing/man/io_uring_queue_exit.3 +3 -4
- data/vendor/liburing/man/io_uring_queue_init.3 +58 -13
- data/vendor/liburing/man/io_uring_queue_init_params.3 +1 -0
- data/vendor/liburing/man/io_uring_recvmsg_cmsg_firsthdr.3 +1 -0
- data/vendor/liburing/man/io_uring_recvmsg_cmsg_nexthdr.3 +1 -0
- data/vendor/liburing/man/io_uring_recvmsg_name.3 +1 -0
- data/vendor/liburing/man/io_uring_recvmsg_out.3 +78 -0
- data/vendor/liburing/man/io_uring_recvmsg_payload.3 +1 -0
- data/vendor/liburing/man/io_uring_recvmsg_payload_length.3 +1 -0
- data/vendor/liburing/man/io_uring_recvmsg_validate.3 +1 -0
- data/vendor/liburing/man/io_uring_register.2 +153 -13
- data/vendor/liburing/man/io_uring_register_buf_ring.3 +140 -0
- data/vendor/liburing/man/io_uring_register_buffers.3 +32 -12
- data/vendor/liburing/man/io_uring_register_eventfd.3 +51 -0
- data/vendor/liburing/man/io_uring_register_eventfd_async.3 +1 -0
- data/vendor/liburing/man/io_uring_register_file_alloc_range.3 +52 -0
- data/vendor/liburing/man/io_uring_register_files.3 +33 -11
- data/vendor/liburing/man/io_uring_register_files_sparse.3 +1 -0
- data/vendor/liburing/man/io_uring_register_iowq_aff.3 +61 -0
- data/vendor/liburing/man/io_uring_register_iowq_max_workers.3 +71 -0
- data/vendor/liburing/man/io_uring_register_ring_fd.3 +49 -0
- data/vendor/liburing/man/io_uring_register_sync_cancel.3 +71 -0
- data/vendor/liburing/man/io_uring_setup.2 +119 -13
- data/vendor/liburing/man/io_uring_sq_ready.3 +14 -8
- data/vendor/liburing/man/io_uring_sq_space_left.3 +9 -9
- data/vendor/liburing/man/io_uring_sqe_set_data.3 +29 -11
- data/vendor/liburing/man/io_uring_sqe_set_data64.3 +1 -0
- data/vendor/liburing/man/io_uring_sqe_set_flags.3 +38 -11
- data/vendor/liburing/man/io_uring_sqring_wait.3 +13 -9
- data/vendor/liburing/man/io_uring_submit.3 +29 -12
- data/vendor/liburing/man/io_uring_submit_and_get_events.3 +31 -0
- data/vendor/liburing/man/io_uring_submit_and_wait.3 +16 -12
- data/vendor/liburing/man/io_uring_submit_and_wait_timeout.3 +30 -23
- data/vendor/liburing/man/io_uring_unregister_buf_ring.3 +30 -0
- data/vendor/liburing/man/io_uring_unregister_buffers.3 +11 -10
- data/vendor/liburing/man/io_uring_unregister_eventfd.3 +1 -0
- data/vendor/liburing/man/io_uring_unregister_files.3 +11 -10
- data/vendor/liburing/man/io_uring_unregister_iowq_aff.3 +1 -0
- data/vendor/liburing/man/io_uring_unregister_ring_fd.3 +32 -0
- data/vendor/liburing/man/io_uring_wait_cqe.3 +19 -12
- data/vendor/liburing/man/io_uring_wait_cqe_nr.3 +21 -14
- data/vendor/liburing/man/io_uring_wait_cqe_timeout.3 +27 -13
- data/vendor/liburing/man/io_uring_wait_cqes.3 +24 -14
- data/vendor/liburing/src/Makefile +8 -7
- data/vendor/liburing/src/arch/aarch64/lib.h +48 -0
- data/vendor/liburing/src/arch/aarch64/syscall.h +0 -4
- data/vendor/liburing/src/arch/generic/lib.h +0 -4
- data/vendor/liburing/src/arch/generic/syscall.h +29 -16
- data/vendor/liburing/src/arch/syscall-defs.h +41 -14
- data/vendor/liburing/src/arch/x86/lib.h +0 -21
- data/vendor/liburing/src/arch/x86/syscall.h +146 -10
- data/vendor/liburing/src/include/liburing/io_uring.h +245 -5
- data/vendor/liburing/src/include/liburing.h +468 -35
- data/vendor/liburing/src/int_flags.h +1 -0
- data/vendor/liburing/src/lib.h +20 -16
- data/vendor/liburing/src/liburing.map +16 -0
- data/vendor/liburing/src/nolibc.c +1 -1
- data/vendor/liburing/src/queue.c +87 -55
- data/vendor/liburing/src/register.c +129 -53
- data/vendor/liburing/src/setup.c +65 -28
- data/vendor/liburing/src/syscall.c +14 -32
- data/vendor/liburing/src/syscall.h +12 -64
- data/vendor/liburing/test/{232c93d07b74-test.c → 232c93d07b74.c} +8 -9
- data/vendor/liburing/test/{35fa71a030ca-test.c → 35fa71a030ca.c} +4 -4
- data/vendor/liburing/test/{500f9fbadef8-test.c → 500f9fbadef8.c} +7 -7
- data/vendor/liburing/test/{7ad0e4b2f83c-test.c → 7ad0e4b2f83c.c} +8 -7
- data/vendor/liburing/test/{8a9973408177-test.c → 8a9973408177.c} +4 -3
- data/vendor/liburing/test/{917257daa0fe-test.c → 917257daa0fe.c} +3 -2
- data/vendor/liburing/test/Makefile +60 -62
- data/vendor/liburing/test/{a0908ae19763-test.c → a0908ae19763.c} +3 -2
- data/vendor/liburing/test/{a4c0b3decb33-test.c → a4c0b3decb33.c} +3 -2
- data/vendor/liburing/test/accept-link.c +5 -4
- data/vendor/liburing/test/accept-reuse.c +17 -16
- data/vendor/liburing/test/accept-test.c +14 -10
- data/vendor/liburing/test/accept.c +529 -107
- data/vendor/liburing/test/across-fork.c +7 -6
- data/vendor/liburing/test/{b19062a56726-test.c → b19062a56726.c} +3 -2
- data/vendor/liburing/test/{b5837bd5311d-test.c → b5837bd5311d.c} +10 -9
- data/vendor/liburing/test/buf-ring.c +420 -0
- data/vendor/liburing/test/{ce593a6c480a-test.c → ce593a6c480a.c} +15 -12
- data/vendor/liburing/test/connect.c +8 -7
- data/vendor/liburing/test/cq-full.c +5 -4
- data/vendor/liburing/test/cq-overflow.c +242 -12
- data/vendor/liburing/test/cq-peek-batch.c +5 -4
- data/vendor/liburing/test/cq-ready.c +5 -4
- data/vendor/liburing/test/cq-size.c +5 -4
- data/vendor/liburing/test/{d4ae271dfaae-test.c → d4ae271dfaae.c} +2 -2
- data/vendor/liburing/test/{d77a67ed5f27-test.c → d77a67ed5f27.c} +6 -6
- data/vendor/liburing/test/defer-taskrun.c +336 -0
- data/vendor/liburing/test/defer.c +26 -14
- data/vendor/liburing/test/double-poll-crash.c +15 -5
- data/vendor/liburing/test/drop-submit.c +5 -3
- data/vendor/liburing/test/{eeed8b54e0df-test.c → eeed8b54e0df.c} +7 -6
- data/vendor/liburing/test/empty-eownerdead.c +4 -4
- data/vendor/liburing/test/eventfd-disable.c +48 -20
- data/vendor/liburing/test/eventfd-reg.c +10 -9
- data/vendor/liburing/test/eventfd-ring.c +13 -12
- data/vendor/liburing/test/eventfd.c +13 -12
- data/vendor/liburing/test/exit-no-cleanup.c +1 -1
- data/vendor/liburing/test/fadvise.c +3 -3
- data/vendor/liburing/test/fallocate.c +16 -9
- data/vendor/liburing/test/{fc2a85cb02ef-test.c → fc2a85cb02ef.c} +4 -3
- data/vendor/liburing/test/fd-pass.c +187 -0
- data/vendor/liburing/test/file-register.c +302 -36
- data/vendor/liburing/test/file-update.c +62 -4
- data/vendor/liburing/test/file-verify.c +6 -2
- data/vendor/liburing/test/files-exit-hang-poll.c +11 -25
- data/vendor/liburing/test/files-exit-hang-timeout.c +13 -10
- data/vendor/liburing/test/fixed-buf-iter.c +115 -0
- data/vendor/liburing/test/fixed-link.c +10 -10
- data/vendor/liburing/test/fixed-reuse.c +160 -0
- data/vendor/liburing/test/fpos.c +6 -3
- data/vendor/liburing/test/fsync.c +3 -3
- data/vendor/liburing/test/hardlink.c +10 -6
- data/vendor/liburing/test/helpers.c +137 -4
- data/vendor/liburing/test/helpers.h +27 -0
- data/vendor/liburing/test/io-cancel.c +16 -11
- data/vendor/liburing/test/io_uring_enter.c +46 -81
- data/vendor/liburing/test/io_uring_passthrough.c +451 -0
- data/vendor/liburing/test/io_uring_register.c +59 -229
- data/vendor/liburing/test/io_uring_setup.c +24 -29
- data/vendor/liburing/test/iopoll-leak.c +85 -0
- data/vendor/liburing/test/iopoll.c +16 -9
- data/vendor/liburing/test/lfs-openat-write.c +3 -1
- data/vendor/liburing/test/link-timeout.c +4 -3
- data/vendor/liburing/test/link.c +8 -7
- data/vendor/liburing/test/madvise.c +2 -2
- data/vendor/liburing/test/mkdir.c +9 -5
- data/vendor/liburing/test/msg-ring.c +46 -20
- data/vendor/liburing/test/multicqes_drain.c +51 -12
- data/vendor/liburing/test/nolibc.c +60 -0
- data/vendor/liburing/test/nop.c +78 -16
- data/vendor/liburing/test/nvme.h +168 -0
- data/vendor/liburing/test/open-direct-link.c +188 -0
- data/vendor/liburing/test/open-direct-pick.c +180 -0
- data/vendor/liburing/test/openat2.c +3 -3
- data/vendor/liburing/test/poll-cancel-all.c +472 -0
- data/vendor/liburing/test/poll-link.c +9 -18
- data/vendor/liburing/test/poll-mshot-overflow.c +162 -0
- data/vendor/liburing/test/poll-mshot-update.c +83 -33
- data/vendor/liburing/test/pollfree.c +2 -2
- data/vendor/liburing/test/read-before-exit.c +112 -0
- data/vendor/liburing/test/read-write.c +83 -1
- data/vendor/liburing/test/recv-msgall-stream.c +398 -0
- data/vendor/liburing/test/recv-msgall.c +265 -0
- data/vendor/liburing/test/recv-multishot.c +505 -0
- data/vendor/liburing/test/rename.c +2 -5
- data/vendor/liburing/test/ring-leak.c +97 -0
- data/vendor/liburing/test/ringbuf-read.c +200 -0
- data/vendor/liburing/test/rsrc_tags.c +25 -13
- data/vendor/liburing/test/runtests-quiet.sh +11 -0
- data/vendor/liburing/test/runtests.sh +18 -20
- data/vendor/liburing/test/rw_merge_test.c +3 -2
- data/vendor/liburing/test/send-zerocopy.c +684 -0
- data/vendor/liburing/test/send_recv.c +49 -2
- data/vendor/liburing/test/send_recvmsg.c +165 -55
- data/vendor/liburing/test/shutdown.c +3 -4
- data/vendor/liburing/test/sigfd-deadlock.c +22 -8
- data/vendor/liburing/test/single-issuer.c +171 -0
- data/vendor/liburing/test/socket-rw-eagain.c +2 -12
- data/vendor/liburing/test/socket-rw-offset.c +2 -11
- data/vendor/liburing/test/socket-rw.c +2 -11
- data/vendor/liburing/test/socket.c +409 -0
- data/vendor/liburing/test/sq-poll-dup.c +1 -1
- data/vendor/liburing/test/sq-poll-share.c +1 -1
- data/vendor/liburing/test/statx.c +2 -2
- data/vendor/liburing/test/submit-and-wait.c +108 -0
- data/vendor/liburing/test/submit-link-fail.c +5 -3
- data/vendor/liburing/test/submit-reuse.c +0 -2
- data/vendor/liburing/test/sync-cancel.c +235 -0
- data/vendor/liburing/test/test.h +35 -0
- data/vendor/liburing/test/timeout-overflow.c +11 -11
- data/vendor/liburing/test/timeout.c +7 -7
- data/vendor/liburing/test/tty-write-dpoll.c +60 -0
- data/vendor/liburing/test/unlink.c +1 -1
- data/vendor/liburing/test/xattr.c +425 -0
- metadata +143 -22
- data/Gemfile.lock +0 -78
data/test/test_io.rb
CHANGED
|
@@ -8,7 +8,7 @@ class IOTest < MiniTest::Test
|
|
|
8
8
|
super
|
|
9
9
|
@i, @o = IO.pipe
|
|
10
10
|
end
|
|
11
|
-
|
|
11
|
+
|
|
12
12
|
def test_that_io_op_yields_to_other_fibers
|
|
13
13
|
count = 0
|
|
14
14
|
msg = nil
|
|
@@ -17,20 +17,20 @@ class IOTest < MiniTest::Test
|
|
|
17
17
|
@o.write('hello')
|
|
18
18
|
@o.close
|
|
19
19
|
end,
|
|
20
|
-
|
|
20
|
+
|
|
21
21
|
spin do
|
|
22
22
|
while count < 5
|
|
23
23
|
sleep 0.01
|
|
24
24
|
count += 1
|
|
25
25
|
end
|
|
26
26
|
end,
|
|
27
|
-
|
|
27
|
+
|
|
28
28
|
spin { msg = @i.read }
|
|
29
29
|
].each(&:await)
|
|
30
30
|
assert_equal 5, count
|
|
31
31
|
assert_equal 'hello', msg
|
|
32
32
|
end
|
|
33
|
-
|
|
33
|
+
|
|
34
34
|
def test_write_multiple_arguments
|
|
35
35
|
i, o = IO.pipe
|
|
36
36
|
count = o.write('a', 'b', "\n", 'c')
|
|
@@ -38,15 +38,15 @@ class IOTest < MiniTest::Test
|
|
|
38
38
|
o.close
|
|
39
39
|
assert_equal "ab\nc", i.read
|
|
40
40
|
end
|
|
41
|
-
|
|
41
|
+
|
|
42
42
|
def test_that_double_chevron_method_returns_io
|
|
43
43
|
assert_equal @o, @o << 'foo'
|
|
44
|
-
|
|
44
|
+
|
|
45
45
|
@o << 'bar' << 'baz'
|
|
46
46
|
@o.close
|
|
47
47
|
assert_equal 'foobarbaz', @i.read
|
|
48
48
|
end
|
|
49
|
-
|
|
49
|
+
|
|
50
50
|
def test_wait_io
|
|
51
51
|
results = []
|
|
52
52
|
i, o = IO.pipe
|
|
@@ -62,60 +62,60 @@ class IOTest < MiniTest::Test
|
|
|
62
62
|
end
|
|
63
63
|
end
|
|
64
64
|
end
|
|
65
|
-
|
|
65
|
+
|
|
66
66
|
snooze
|
|
67
67
|
o.write('foo')
|
|
68
68
|
o.close
|
|
69
|
-
|
|
69
|
+
|
|
70
70
|
result = f.await
|
|
71
|
-
|
|
71
|
+
|
|
72
72
|
assert_equal 'foo', f.await
|
|
73
73
|
assert_equal [:wait_readable, 'foo'], results
|
|
74
74
|
end
|
|
75
|
-
|
|
75
|
+
|
|
76
76
|
def test_read
|
|
77
77
|
i, o = IO.pipe
|
|
78
|
-
|
|
78
|
+
|
|
79
79
|
o << 'hi'
|
|
80
80
|
assert_equal 'hi', i.read(2)
|
|
81
|
-
|
|
81
|
+
|
|
82
82
|
o << 'foobarbaz'
|
|
83
83
|
assert_equal 'foo', i.read(3)
|
|
84
84
|
assert_equal 'bar', i.read(3)
|
|
85
|
-
|
|
85
|
+
|
|
86
86
|
buf = +'abc'
|
|
87
87
|
assert_equal 'baz', i.read(3, buf)
|
|
88
88
|
assert_equal 'baz', buf
|
|
89
|
-
|
|
89
|
+
|
|
90
90
|
buf = +'def'
|
|
91
91
|
o << 'foobar'
|
|
92
92
|
assert_equal 'deffoobar', i.read(6, buf, -1)
|
|
93
93
|
assert_equal 'deffoobar', buf
|
|
94
94
|
end
|
|
95
|
-
|
|
95
|
+
|
|
96
96
|
def test_readpartial
|
|
97
97
|
i, o = IO.pipe
|
|
98
|
-
|
|
98
|
+
|
|
99
99
|
o << 'hi'
|
|
100
100
|
assert_equal 'hi', i.readpartial(3)
|
|
101
|
-
|
|
101
|
+
|
|
102
102
|
o << 'hi'
|
|
103
103
|
assert_equal 'h', i.readpartial(1)
|
|
104
104
|
assert_equal 'i', i.readpartial(1)
|
|
105
|
-
|
|
105
|
+
|
|
106
106
|
spin {
|
|
107
107
|
sleep 0.01
|
|
108
108
|
o << 'hi'
|
|
109
109
|
}
|
|
110
110
|
assert_equal 'hi', i.readpartial(2)
|
|
111
111
|
o.close
|
|
112
|
-
|
|
112
|
+
|
|
113
113
|
assert_raises(EOFError) { i.readpartial(1) }
|
|
114
114
|
end
|
|
115
|
-
|
|
115
|
+
|
|
116
116
|
def test_gets
|
|
117
117
|
i, o = IO.pipe
|
|
118
|
-
|
|
118
|
+
|
|
119
119
|
buf = []
|
|
120
120
|
f = spin do
|
|
121
121
|
peer = receive
|
|
@@ -124,37 +124,37 @@ class IOTest < MiniTest::Test
|
|
|
124
124
|
peer << true
|
|
125
125
|
end
|
|
126
126
|
end
|
|
127
|
-
|
|
127
|
+
|
|
128
128
|
snooze
|
|
129
129
|
assert_equal [], buf
|
|
130
|
-
|
|
130
|
+
|
|
131
131
|
o << 'fab'
|
|
132
132
|
f << Fiber.current
|
|
133
133
|
sleep 0.05
|
|
134
134
|
assert_equal [], buf
|
|
135
|
-
|
|
135
|
+
|
|
136
136
|
o << "ulous\n"
|
|
137
137
|
receive
|
|
138
138
|
assert_equal ["fabulous\n"], buf
|
|
139
|
-
|
|
139
|
+
|
|
140
140
|
o.close
|
|
141
141
|
f.await
|
|
142
142
|
assert_equal ["fabulous\n"], buf
|
|
143
143
|
end
|
|
144
|
-
|
|
144
|
+
|
|
145
145
|
def test_getc
|
|
146
146
|
i, o = IO.pipe
|
|
147
|
-
|
|
147
|
+
|
|
148
148
|
buf = []
|
|
149
149
|
f = spin do
|
|
150
150
|
while (c = i.getc)
|
|
151
151
|
buf << c
|
|
152
152
|
end
|
|
153
153
|
end
|
|
154
|
-
|
|
154
|
+
|
|
155
155
|
snooze
|
|
156
156
|
assert_equal [], buf
|
|
157
|
-
|
|
157
|
+
|
|
158
158
|
o << 'f'
|
|
159
159
|
snooze
|
|
160
160
|
o << 'g'
|
|
@@ -162,20 +162,20 @@ class IOTest < MiniTest::Test
|
|
|
162
162
|
f.await
|
|
163
163
|
assert_equal ['f', 'g'], buf
|
|
164
164
|
end
|
|
165
|
-
|
|
165
|
+
|
|
166
166
|
def test_getbyte
|
|
167
167
|
i, o = IO.pipe
|
|
168
|
-
|
|
168
|
+
|
|
169
169
|
buf = []
|
|
170
170
|
f = spin do
|
|
171
171
|
while (b = i.getbyte)
|
|
172
172
|
buf << b
|
|
173
173
|
end
|
|
174
174
|
end
|
|
175
|
-
|
|
175
|
+
|
|
176
176
|
snooze
|
|
177
177
|
assert_equal [], buf
|
|
178
|
-
|
|
178
|
+
|
|
179
179
|
o << 'f'
|
|
180
180
|
snooze
|
|
181
181
|
o << 'g'
|
|
@@ -183,21 +183,21 @@ class IOTest < MiniTest::Test
|
|
|
183
183
|
f.await
|
|
184
184
|
assert_equal [102, 103], buf
|
|
185
185
|
end
|
|
186
|
-
|
|
186
|
+
|
|
187
187
|
# see https://github.com/digital-fabric/polyphony/issues/30
|
|
188
188
|
def test_reopened_tempfile
|
|
189
189
|
file = Tempfile.new
|
|
190
190
|
file << 'hello: world'
|
|
191
191
|
file.close
|
|
192
|
-
|
|
192
|
+
|
|
193
193
|
buf = nil
|
|
194
194
|
File.open(file, 'r:bom|utf-8') do |f|
|
|
195
195
|
buf = f.read(16384)
|
|
196
196
|
end
|
|
197
|
-
|
|
197
|
+
|
|
198
198
|
assert_equal 'hello: world', buf
|
|
199
199
|
end
|
|
200
|
-
|
|
200
|
+
|
|
201
201
|
def test_feed_loop_with_block
|
|
202
202
|
i, o = IO.pipe
|
|
203
203
|
unpacker = MessagePack::Unpacker.new
|
|
@@ -208,28 +208,28 @@ class IOTest < MiniTest::Test
|
|
|
208
208
|
o << 'foo'.to_msgpack
|
|
209
209
|
sleep 0.01
|
|
210
210
|
assert_equal ['foo'], buffer
|
|
211
|
-
|
|
211
|
+
|
|
212
212
|
o << 'bar'.to_msgpack
|
|
213
213
|
sleep 0.01
|
|
214
214
|
assert_equal ['foo', 'bar'], buffer
|
|
215
|
-
|
|
215
|
+
|
|
216
216
|
o << 'baz'.to_msgpack
|
|
217
217
|
sleep 0.01
|
|
218
218
|
assert_equal ['foo', 'bar', 'baz'], buffer
|
|
219
219
|
end
|
|
220
|
-
|
|
220
|
+
|
|
221
221
|
class Receiver1
|
|
222
222
|
attr_reader :buffer
|
|
223
|
-
|
|
223
|
+
|
|
224
224
|
def initialize
|
|
225
225
|
@buffer = []
|
|
226
226
|
end
|
|
227
|
-
|
|
227
|
+
|
|
228
228
|
def recv(obj)
|
|
229
229
|
@buffer << obj
|
|
230
230
|
end
|
|
231
231
|
end
|
|
232
|
-
|
|
232
|
+
|
|
233
233
|
def test_feed_loop_without_block
|
|
234
234
|
i, o = IO.pipe
|
|
235
235
|
receiver = Receiver1.new
|
|
@@ -239,28 +239,28 @@ class IOTest < MiniTest::Test
|
|
|
239
239
|
o << 'foo'
|
|
240
240
|
sleep 0.01
|
|
241
241
|
assert_equal ['foo'], receiver.buffer
|
|
242
|
-
|
|
242
|
+
|
|
243
243
|
o << 'bar'
|
|
244
244
|
sleep 0.01
|
|
245
245
|
assert_equal ['foo', 'bar'], receiver.buffer
|
|
246
|
-
|
|
246
|
+
|
|
247
247
|
o << 'baz'
|
|
248
248
|
sleep 0.01
|
|
249
249
|
assert_equal ['foo', 'bar', 'baz'], receiver.buffer
|
|
250
250
|
end
|
|
251
|
-
|
|
251
|
+
|
|
252
252
|
class Receiver2
|
|
253
253
|
attr_reader :buffer
|
|
254
|
-
|
|
254
|
+
|
|
255
255
|
def initialize
|
|
256
256
|
@buffer = []
|
|
257
257
|
end
|
|
258
|
-
|
|
258
|
+
|
|
259
259
|
def call(obj)
|
|
260
260
|
@buffer << obj
|
|
261
261
|
end
|
|
262
262
|
end
|
|
263
|
-
|
|
263
|
+
|
|
264
264
|
def test_feed_loop_without_method
|
|
265
265
|
i, o = IO.pipe
|
|
266
266
|
receiver = Receiver2.new
|
|
@@ -270,64 +270,64 @@ class IOTest < MiniTest::Test
|
|
|
270
270
|
o << 'foo'
|
|
271
271
|
sleep 0.01
|
|
272
272
|
assert_equal ['foo'], receiver.buffer
|
|
273
|
-
|
|
273
|
+
|
|
274
274
|
o << 'bar'
|
|
275
275
|
sleep 0.01
|
|
276
276
|
assert_equal ['foo', 'bar'], receiver.buffer
|
|
277
|
-
|
|
277
|
+
|
|
278
278
|
o << 'baz'
|
|
279
279
|
sleep 0.01
|
|
280
280
|
assert_equal ['foo', 'bar', 'baz'], receiver.buffer
|
|
281
281
|
end
|
|
282
|
-
|
|
282
|
+
|
|
283
283
|
def test_splice_from
|
|
284
284
|
i1, o1 = IO.pipe
|
|
285
285
|
i2, o2 = IO.pipe
|
|
286
286
|
len = nil
|
|
287
|
-
|
|
287
|
+
|
|
288
288
|
spin {
|
|
289
289
|
len = o2.splice_from(i1, 1000)
|
|
290
290
|
o2.close
|
|
291
291
|
}
|
|
292
|
-
|
|
292
|
+
|
|
293
293
|
o1.write('foobar')
|
|
294
294
|
result = i2.read
|
|
295
|
-
|
|
295
|
+
|
|
296
296
|
assert_equal 'foobar', result
|
|
297
297
|
assert_equal 6, len
|
|
298
298
|
end
|
|
299
|
-
|
|
299
|
+
|
|
300
300
|
def test_splice_class_method
|
|
301
301
|
i1, o1 = IO.pipe
|
|
302
302
|
i2, o2 = IO.pipe
|
|
303
303
|
len = nil
|
|
304
|
-
|
|
304
|
+
|
|
305
305
|
spin {
|
|
306
306
|
len = IO.splice(i1, o2, 1000)
|
|
307
307
|
o2.close
|
|
308
308
|
}
|
|
309
|
-
|
|
309
|
+
|
|
310
310
|
o1.write('foobar')
|
|
311
311
|
result = i2.read
|
|
312
|
-
|
|
312
|
+
|
|
313
313
|
assert_equal 'foobar', result
|
|
314
314
|
assert_equal 6, len
|
|
315
315
|
end
|
|
316
|
-
|
|
316
|
+
|
|
317
317
|
def test_splice_from_to_eof
|
|
318
318
|
i1, o1 = IO.pipe
|
|
319
319
|
i2, o2 = IO.pipe
|
|
320
320
|
len = nil
|
|
321
|
-
|
|
321
|
+
|
|
322
322
|
f = spin {
|
|
323
323
|
len = o2.splice_from(i1, -1000)
|
|
324
324
|
o2.close
|
|
325
325
|
}
|
|
326
|
-
|
|
326
|
+
|
|
327
327
|
o1.write('foo')
|
|
328
328
|
result = i2.readpartial(1000)
|
|
329
329
|
assert_equal 'foo', result
|
|
330
|
-
|
|
330
|
+
|
|
331
331
|
o1.write('bar')
|
|
332
332
|
result = i2.readpartial(1000)
|
|
333
333
|
assert_equal 'bar', result
|
|
@@ -340,21 +340,21 @@ class IOTest < MiniTest::Test
|
|
|
340
340
|
f.await
|
|
341
341
|
end
|
|
342
342
|
end
|
|
343
|
-
|
|
343
|
+
|
|
344
344
|
def test_splice_class_method_to_eof
|
|
345
345
|
i1, o1 = IO.pipe
|
|
346
346
|
i2, o2 = IO.pipe
|
|
347
347
|
len = nil
|
|
348
|
-
|
|
348
|
+
|
|
349
349
|
f = spin {
|
|
350
350
|
len = IO.splice(i1, o2, -1000)
|
|
351
351
|
o2.close
|
|
352
352
|
}
|
|
353
|
-
|
|
353
|
+
|
|
354
354
|
o1.write('foo')
|
|
355
355
|
result = i2.readpartial(1000)
|
|
356
356
|
assert_equal 'foo', result
|
|
357
|
-
|
|
357
|
+
|
|
358
358
|
o1.write('bar')
|
|
359
359
|
result = i2.readpartial(1000)
|
|
360
360
|
assert_equal 'bar', result
|
|
@@ -367,90 +367,90 @@ class IOTest < MiniTest::Test
|
|
|
367
367
|
f.await
|
|
368
368
|
end
|
|
369
369
|
end
|
|
370
|
-
|
|
370
|
+
|
|
371
371
|
def test_double_splice
|
|
372
372
|
if Thread.current.backend.kind != :io_uring
|
|
373
373
|
skip "IO.double_splice available only on io_uring backend"
|
|
374
374
|
end
|
|
375
|
-
|
|
375
|
+
|
|
376
376
|
src = Polyphony.pipe
|
|
377
377
|
dest = Polyphony.pipe
|
|
378
378
|
ret = nil
|
|
379
379
|
data = 'foobar' * 10
|
|
380
|
-
|
|
380
|
+
|
|
381
381
|
f1 = spin {
|
|
382
382
|
ret = IO.double_splice(src, dest)
|
|
383
383
|
dest.close
|
|
384
384
|
}
|
|
385
|
-
|
|
385
|
+
|
|
386
386
|
src << data
|
|
387
387
|
src.close
|
|
388
|
-
|
|
388
|
+
|
|
389
389
|
f1.await
|
|
390
|
-
|
|
390
|
+
|
|
391
391
|
spliced = dest.read
|
|
392
392
|
assert_equal data, spliced
|
|
393
393
|
assert_equal data.bytesize, ret
|
|
394
394
|
end
|
|
395
|
-
|
|
395
|
+
|
|
396
396
|
def test_tee_from
|
|
397
397
|
skip "tested only on Linux" unless RUBY_PLATFORM =~ /linux/
|
|
398
398
|
|
|
399
399
|
src = Polyphony.pipe
|
|
400
400
|
dest1 = Polyphony.pipe
|
|
401
401
|
dest2 = Polyphony.pipe
|
|
402
|
-
|
|
402
|
+
|
|
403
403
|
len1 = len2 = nil
|
|
404
|
-
|
|
404
|
+
|
|
405
405
|
spin {
|
|
406
406
|
len1 = dest1.tee_from(src, 1000)
|
|
407
407
|
dest1.close
|
|
408
408
|
len2 = IO.splice(src, dest2, 1000)
|
|
409
409
|
dest2.close
|
|
410
410
|
}
|
|
411
|
-
|
|
411
|
+
|
|
412
412
|
src << 'foobar'
|
|
413
413
|
src.close
|
|
414
414
|
result1 = dest1.read
|
|
415
415
|
result2 = dest2.read
|
|
416
|
-
|
|
416
|
+
|
|
417
417
|
assert_equal 'foobar', result1
|
|
418
418
|
assert_equal 6, len1
|
|
419
|
-
|
|
419
|
+
|
|
420
420
|
assert_equal 'foobar', result2
|
|
421
421
|
assert_equal 6, len2
|
|
422
422
|
end
|
|
423
|
-
|
|
423
|
+
|
|
424
424
|
def test_tee_class_method
|
|
425
425
|
skip "tested only on Linux" unless RUBY_PLATFORM =~ /linux/
|
|
426
426
|
|
|
427
427
|
src = Polyphony.pipe
|
|
428
428
|
dest1 = Polyphony.pipe
|
|
429
429
|
dest2 = Polyphony.pipe
|
|
430
|
-
|
|
430
|
+
|
|
431
431
|
len1 = len2 = nil
|
|
432
|
-
|
|
432
|
+
|
|
433
433
|
spin {
|
|
434
434
|
len1 = IO.tee(src, dest1, 1000)
|
|
435
435
|
dest1.close
|
|
436
436
|
len2 = IO.splice(src, dest2, 1000)
|
|
437
437
|
dest2.close
|
|
438
438
|
}
|
|
439
|
-
|
|
439
|
+
|
|
440
440
|
src << 'foobar'
|
|
441
441
|
src.close
|
|
442
442
|
result1 = dest1.read
|
|
443
443
|
result2 = dest2.read
|
|
444
|
-
|
|
444
|
+
|
|
445
445
|
assert_equal 'foobar', result1
|
|
446
446
|
assert_equal 6, len1
|
|
447
|
-
|
|
447
|
+
|
|
448
448
|
assert_equal 'foobar', result2
|
|
449
449
|
assert_equal 6, len2
|
|
450
450
|
end
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
451
|
+
|
|
452
|
+
|
|
453
|
+
|
|
454
454
|
end
|
|
455
455
|
|
|
456
456
|
class IOWithRawBufferTest < MiniTest::Test
|
|
@@ -458,18 +458,18 @@ class IOWithRawBufferTest < MiniTest::Test
|
|
|
458
458
|
super
|
|
459
459
|
@i, @o = IO.pipe
|
|
460
460
|
end
|
|
461
|
-
|
|
461
|
+
|
|
462
462
|
def test_write_with_raw_buffer
|
|
463
463
|
Polyphony.__with_raw_buffer__(64) do |b|
|
|
464
464
|
Polyphony.__raw_buffer_set__(b, 'foobar')
|
|
465
465
|
@o << b
|
|
466
466
|
@o.close
|
|
467
467
|
end
|
|
468
|
-
|
|
468
|
+
|
|
469
469
|
str = @i.read
|
|
470
470
|
assert_equal 'foobar', str
|
|
471
471
|
end
|
|
472
|
-
|
|
472
|
+
|
|
473
473
|
def test_read_with_raw_buffer
|
|
474
474
|
@o << '*' * 65
|
|
475
475
|
@o.close
|
|
@@ -478,7 +478,7 @@ class IOWithRawBufferTest < MiniTest::Test
|
|
|
478
478
|
res = @i.read(64, b)
|
|
479
479
|
assert_equal 64, res
|
|
480
480
|
chunks << Polyphony.__raw_buffer_get__(b, res)
|
|
481
|
-
|
|
481
|
+
|
|
482
482
|
res = @i.read(64, b)
|
|
483
483
|
assert_equal 1, res
|
|
484
484
|
assert_equal 64, Polyphony.__raw_buffer_size__(b)
|
|
@@ -494,28 +494,28 @@ class IOClassMethodsTest < MiniTest::Test
|
|
|
494
494
|
assert_kind_of String, s
|
|
495
495
|
assert !s.empty?
|
|
496
496
|
assert_equal IO.orig_binread(__FILE__), s
|
|
497
|
-
|
|
497
|
+
|
|
498
498
|
s = IO.binread(__FILE__, 100)
|
|
499
499
|
assert_equal 100, s.bytesize
|
|
500
500
|
assert_equal IO.orig_binread(__FILE__, 100), s
|
|
501
|
-
|
|
501
|
+
|
|
502
502
|
s = IO.binread(__FILE__, 100, 2)
|
|
503
503
|
assert_equal 100, s.bytesize
|
|
504
504
|
assert_equal 'frozen', s[0..5]
|
|
505
505
|
end
|
|
506
|
-
|
|
506
|
+
|
|
507
507
|
BIN_DATA = "\x00\x01\x02\x03"
|
|
508
|
-
|
|
508
|
+
|
|
509
509
|
def test_binwrite
|
|
510
510
|
fn = '/tmp/test_binwrite'
|
|
511
511
|
FileUtils.rm(fn) rescue nil
|
|
512
|
-
|
|
512
|
+
|
|
513
513
|
len = IO.binwrite(fn, BIN_DATA)
|
|
514
514
|
assert_equal 4, len
|
|
515
515
|
s = IO.binread(fn)
|
|
516
516
|
assert_equal BIN_DATA, s
|
|
517
517
|
end
|
|
518
|
-
|
|
518
|
+
|
|
519
519
|
# def test_foreach
|
|
520
520
|
# skip 'IO.foreach is not yet implemented'
|
|
521
521
|
# lines = []
|
|
@@ -523,60 +523,60 @@ class IOClassMethodsTest < MiniTest::Test
|
|
|
523
523
|
# assert_equal "# frozen_string_literal: true\n", lines[0]
|
|
524
524
|
# assert_equal "end\n", lines[-1]
|
|
525
525
|
# end
|
|
526
|
-
|
|
526
|
+
|
|
527
527
|
def test_read_class_method
|
|
528
528
|
s = IO.read(__FILE__)
|
|
529
529
|
assert_kind_of String, s
|
|
530
530
|
assert(!s.empty?)
|
|
531
531
|
assert_equal IO.orig_read(__FILE__), s
|
|
532
|
-
|
|
532
|
+
|
|
533
533
|
s = IO.read(__FILE__, 100)
|
|
534
534
|
assert_equal 100, s.bytesize
|
|
535
535
|
assert_equal IO.orig_read(__FILE__, 100), s
|
|
536
|
-
|
|
536
|
+
|
|
537
537
|
s = IO.read(__FILE__, 100, 2)
|
|
538
538
|
assert_equal 100, s.bytesize
|
|
539
539
|
assert_equal 'frozen', s[0..5]
|
|
540
540
|
end
|
|
541
|
-
|
|
541
|
+
|
|
542
542
|
def test_readlines
|
|
543
543
|
lines = IO.readlines(__FILE__)
|
|
544
544
|
assert_equal "# frozen_string_literal: true\n", lines[0]
|
|
545
545
|
assert_equal "end\n", lines[-1]
|
|
546
546
|
end
|
|
547
|
-
|
|
547
|
+
|
|
548
548
|
WRITE_DATA = "foo\nbar קוקו"
|
|
549
|
-
|
|
549
|
+
|
|
550
550
|
def test_write_class_method
|
|
551
551
|
fn = '/tmp/test_write'
|
|
552
552
|
FileUtils.rm(fn) rescue nil
|
|
553
|
-
|
|
553
|
+
|
|
554
554
|
len = IO.write(fn, WRITE_DATA)
|
|
555
555
|
assert_equal WRITE_DATA.bytesize, len
|
|
556
556
|
s = IO.read(fn)
|
|
557
557
|
assert_equal WRITE_DATA, s
|
|
558
558
|
end
|
|
559
|
-
|
|
559
|
+
|
|
560
560
|
def test_popen
|
|
561
561
|
skip unless IS_LINUX
|
|
562
|
-
|
|
562
|
+
|
|
563
563
|
counter = 0
|
|
564
564
|
timer = spin { throttled_loop(20) { counter += 1 } }
|
|
565
|
-
|
|
565
|
+
|
|
566
566
|
IO.popen('sleep 0.5') { |io| io.read(8192) }
|
|
567
567
|
assert(counter >= 5)
|
|
568
|
-
|
|
568
|
+
|
|
569
569
|
result = nil
|
|
570
570
|
IO.popen('echo "foo"') { |io| result = io.read(8192) }
|
|
571
571
|
assert_equal "foo\n", result
|
|
572
572
|
ensure
|
|
573
573
|
timer&.stop
|
|
574
574
|
end
|
|
575
|
-
|
|
575
|
+
|
|
576
576
|
def test_kernel_gets
|
|
577
577
|
counter = 0
|
|
578
578
|
timer = spin { throttled_loop(200) { counter += 1 } }
|
|
579
|
-
|
|
579
|
+
|
|
580
580
|
i, o = IO.pipe
|
|
581
581
|
orig_stdin = $stdin
|
|
582
582
|
$stdin = i
|
|
@@ -585,26 +585,26 @@ class IOClassMethodsTest < MiniTest::Test
|
|
|
585
585
|
o.puts 'foo'
|
|
586
586
|
o.close
|
|
587
587
|
end
|
|
588
|
-
|
|
588
|
+
|
|
589
589
|
assert(counter >= 0)
|
|
590
590
|
assert_equal "foo\n", gets
|
|
591
591
|
ensure
|
|
592
592
|
$stdin = orig_stdin
|
|
593
593
|
timer&.stop
|
|
594
594
|
end
|
|
595
|
-
|
|
595
|
+
|
|
596
596
|
def test_kernel_gets_with_argv
|
|
597
597
|
ARGV << __FILE__
|
|
598
|
-
|
|
598
|
+
|
|
599
599
|
s = StringIO.new(IO.orig_read(__FILE__))
|
|
600
|
-
|
|
600
|
+
|
|
601
601
|
while (l = s.gets)
|
|
602
602
|
assert_equal l, gets
|
|
603
603
|
end
|
|
604
604
|
ensure
|
|
605
605
|
ARGV.delete __FILE__
|
|
606
606
|
end
|
|
607
|
-
|
|
607
|
+
|
|
608
608
|
def test_kernel_puts
|
|
609
609
|
orig_stdout = $stdout
|
|
610
610
|
o = eg(
|
|
@@ -613,15 +613,15 @@ class IOClassMethodsTest < MiniTest::Test
|
|
|
613
613
|
flush: -> {},
|
|
614
614
|
buf: -> { @buf }
|
|
615
615
|
)
|
|
616
|
-
|
|
616
|
+
|
|
617
617
|
$stdout = o
|
|
618
|
-
|
|
618
|
+
|
|
619
619
|
puts 'foobar'
|
|
620
620
|
assert_equal "foobar\n", o.buf
|
|
621
621
|
ensure
|
|
622
622
|
$stdout = orig_stdout
|
|
623
623
|
end
|
|
624
|
-
|
|
624
|
+
|
|
625
625
|
def test_read_large_file
|
|
626
626
|
fn = '/tmp/test.txt'
|
|
627
627
|
File.open(fn, 'w') { |f| f << ('*' * 1e6) }
|
|
@@ -629,7 +629,7 @@ class IOClassMethodsTest < MiniTest::Test
|
|
|
629
629
|
assert_equal 1e6, s.bytesize
|
|
630
630
|
assert s == IO.orig_read(fn)
|
|
631
631
|
end
|
|
632
|
-
|
|
632
|
+
|
|
633
633
|
def pipe_read
|
|
634
634
|
i, o = IO.pipe
|
|
635
635
|
yield o
|
|
@@ -638,36 +638,36 @@ class IOClassMethodsTest < MiniTest::Test
|
|
|
638
638
|
ensure
|
|
639
639
|
i.close
|
|
640
640
|
end
|
|
641
|
-
|
|
641
|
+
|
|
642
642
|
def test_puts
|
|
643
643
|
assert_equal "foo\n", pipe_read { |f| f.puts 'foo' }
|
|
644
644
|
assert_equal "foo\n", pipe_read { |f| f.puts "foo\n" }
|
|
645
645
|
assert_equal "foo\nbar\n", pipe_read { |f| f.puts 'foo', 'bar' }
|
|
646
646
|
assert_equal "foo\nbar\n", pipe_read { |f| f.puts 'foo', "bar\n" }
|
|
647
647
|
end
|
|
648
|
-
|
|
648
|
+
|
|
649
649
|
def test_read_loop
|
|
650
650
|
i, o = IO.pipe
|
|
651
|
-
|
|
651
|
+
|
|
652
652
|
buf = []
|
|
653
653
|
f = spin do
|
|
654
654
|
buf << :ready
|
|
655
655
|
i.read_loop { |d| buf << d }
|
|
656
656
|
buf << :done
|
|
657
657
|
end
|
|
658
|
-
|
|
658
|
+
|
|
659
659
|
# writing always causes snoozing
|
|
660
660
|
o << 'foo'
|
|
661
661
|
o << 'bar'
|
|
662
662
|
o.close
|
|
663
|
-
|
|
663
|
+
|
|
664
664
|
f.await
|
|
665
665
|
assert_equal [:ready, 'foo', 'bar', :done], buf
|
|
666
666
|
end
|
|
667
|
-
|
|
667
|
+
|
|
668
668
|
def test_read_loop_with_max_len
|
|
669
669
|
r, w = IO.pipe
|
|
670
|
-
|
|
670
|
+
|
|
671
671
|
w << 'foobar'
|
|
672
672
|
w.close
|
|
673
673
|
buf = []
|
|
@@ -680,59 +680,59 @@ class IOExtensionsTest < MiniTest::Test
|
|
|
680
680
|
def test_deflate
|
|
681
681
|
i, o = IO.pipe
|
|
682
682
|
r, w = IO.pipe
|
|
683
|
-
|
|
683
|
+
|
|
684
684
|
ret = nil
|
|
685
685
|
f = spin {
|
|
686
686
|
ret = IO.deflate(i, w)
|
|
687
687
|
w.close
|
|
688
688
|
}
|
|
689
|
-
|
|
689
|
+
|
|
690
690
|
o << 'foobar' * 20
|
|
691
691
|
o.close
|
|
692
|
-
|
|
692
|
+
|
|
693
693
|
f.await
|
|
694
694
|
assert_equal 17, ret
|
|
695
|
-
|
|
695
|
+
|
|
696
696
|
data = r.read
|
|
697
697
|
msg = Zlib::Inflate.inflate(data)
|
|
698
698
|
assert_equal 'foobar' * 20, msg
|
|
699
699
|
end
|
|
700
|
-
|
|
700
|
+
|
|
701
701
|
def test_deflate_to_string
|
|
702
702
|
i, o = IO.pipe
|
|
703
703
|
r, w = IO.pipe
|
|
704
704
|
str = +''
|
|
705
|
-
|
|
705
|
+
|
|
706
706
|
ret = nil
|
|
707
707
|
f = spin {
|
|
708
708
|
ret = IO.deflate(i, str)
|
|
709
709
|
w << str
|
|
710
710
|
w.close
|
|
711
711
|
}
|
|
712
|
-
|
|
712
|
+
|
|
713
713
|
o << 'foobar' * 20
|
|
714
714
|
o.close
|
|
715
|
-
|
|
715
|
+
|
|
716
716
|
f.await
|
|
717
717
|
assert_equal 17, ret
|
|
718
|
-
|
|
718
|
+
|
|
719
719
|
data = r.read
|
|
720
720
|
msg = Zlib::Inflate.inflate(data)
|
|
721
721
|
assert_equal 'foobar' * 20, msg
|
|
722
722
|
end
|
|
723
|
-
|
|
723
|
+
|
|
724
724
|
def test_deflate_to_frozen_string
|
|
725
725
|
i, o = IO.pipe
|
|
726
726
|
str = '' # frozen
|
|
727
|
-
|
|
727
|
+
|
|
728
728
|
f = spin {
|
|
729
729
|
o << 'foobar' * 20
|
|
730
730
|
o.close
|
|
731
731
|
}
|
|
732
|
-
|
|
732
|
+
|
|
733
733
|
assert_raises(FrozenError) { IO.deflate(i, str) }
|
|
734
734
|
end
|
|
735
|
-
|
|
735
|
+
|
|
736
736
|
def test_deflate_from_string
|
|
737
737
|
r, w = IO.pipe
|
|
738
738
|
str = 'foobar' * 10000
|
|
@@ -744,71 +744,71 @@ class IOExtensionsTest < MiniTest::Test
|
|
|
744
744
|
}
|
|
745
745
|
f.await
|
|
746
746
|
assert_equal 118, ret
|
|
747
|
-
|
|
747
|
+
|
|
748
748
|
data = r.read
|
|
749
749
|
msg = Zlib::Inflate.inflate(data)
|
|
750
750
|
assert_equal str, msg
|
|
751
751
|
end
|
|
752
|
-
|
|
752
|
+
|
|
753
753
|
def test_inflate
|
|
754
754
|
i, o = IO.pipe
|
|
755
755
|
r, w = IO.pipe
|
|
756
|
-
|
|
756
|
+
|
|
757
757
|
spin {
|
|
758
758
|
data = Zlib::Deflate.deflate('foobar', 9)
|
|
759
759
|
o << data
|
|
760
760
|
o.close
|
|
761
761
|
}
|
|
762
|
-
|
|
762
|
+
|
|
763
763
|
ret = IO.inflate(i, w)
|
|
764
764
|
assert_equal 6, ret
|
|
765
765
|
w.close
|
|
766
766
|
msg = r.read
|
|
767
767
|
assert_equal 'foobar', msg
|
|
768
768
|
end
|
|
769
|
-
|
|
769
|
+
|
|
770
770
|
def test_inflate_to_string
|
|
771
771
|
i, o = IO.pipe
|
|
772
772
|
str = +''
|
|
773
|
-
|
|
773
|
+
|
|
774
774
|
spin {
|
|
775
775
|
data = Zlib::Deflate.deflate('foobar', 9)
|
|
776
776
|
o << data
|
|
777
777
|
o.close
|
|
778
778
|
}
|
|
779
|
-
|
|
779
|
+
|
|
780
780
|
ret = IO.inflate(i, str)
|
|
781
781
|
assert_equal 6, ret
|
|
782
782
|
assert_equal 6, str.bytesize
|
|
783
783
|
assert_equal 'foobar', str
|
|
784
784
|
end
|
|
785
|
-
|
|
785
|
+
|
|
786
786
|
def test_inflate_from_string
|
|
787
787
|
r, w = IO.pipe
|
|
788
788
|
str = Zlib::Deflate.deflate('foobar', 9)
|
|
789
|
-
|
|
789
|
+
|
|
790
790
|
ret = IO.inflate(str, w)
|
|
791
791
|
assert_equal 6, ret
|
|
792
792
|
w.close
|
|
793
793
|
msg = r.read
|
|
794
794
|
assert_equal 'foobar', msg
|
|
795
795
|
end
|
|
796
|
-
|
|
796
|
+
|
|
797
797
|
def test_gzip
|
|
798
798
|
src = Polyphony.pipe
|
|
799
799
|
dest = Polyphony.pipe
|
|
800
800
|
now = nil
|
|
801
|
-
|
|
801
|
+
|
|
802
802
|
f = spin {
|
|
803
803
|
now = Time.now
|
|
804
804
|
IO.gzip(src, dest)
|
|
805
805
|
dest.close
|
|
806
806
|
}
|
|
807
|
-
|
|
807
|
+
|
|
808
808
|
src << IO.read(__FILE__)
|
|
809
809
|
src.close
|
|
810
810
|
f.await
|
|
811
|
-
|
|
811
|
+
|
|
812
812
|
gz = Zlib::GzipReader.new(dest)
|
|
813
813
|
data = gz.read
|
|
814
814
|
assert_equal IO.read(__FILE__), data
|
|
@@ -816,24 +816,24 @@ class IOExtensionsTest < MiniTest::Test
|
|
|
816
816
|
assert_nil gz.orig_name
|
|
817
817
|
assert_nil gz.comment
|
|
818
818
|
end
|
|
819
|
-
|
|
819
|
+
|
|
820
820
|
def test_gzip_to_string
|
|
821
821
|
src = Polyphony.pipe
|
|
822
822
|
dest = Polyphony.pipe
|
|
823
823
|
str = +''
|
|
824
824
|
now = nil
|
|
825
|
-
|
|
825
|
+
|
|
826
826
|
f = spin {
|
|
827
827
|
now = Time.now
|
|
828
828
|
IO.gzip(src, str)
|
|
829
829
|
dest << str
|
|
830
830
|
dest.close
|
|
831
831
|
}
|
|
832
|
-
|
|
832
|
+
|
|
833
833
|
src << IO.read(__FILE__)
|
|
834
834
|
src.close
|
|
835
835
|
f.await
|
|
836
|
-
|
|
836
|
+
|
|
837
837
|
gz = Zlib::GzipReader.new(dest)
|
|
838
838
|
data = gz.read
|
|
839
839
|
assert_equal IO.read(__FILE__), data
|
|
@@ -841,276 +841,301 @@ class IOExtensionsTest < MiniTest::Test
|
|
|
841
841
|
assert_nil gz.orig_name
|
|
842
842
|
assert_nil gz.comment
|
|
843
843
|
end
|
|
844
|
-
|
|
844
|
+
|
|
845
845
|
def test_gzip_from_string
|
|
846
846
|
str = IO.read(__FILE__)
|
|
847
847
|
dest = Polyphony.pipe
|
|
848
848
|
now = nil
|
|
849
|
-
|
|
849
|
+
|
|
850
850
|
IO.gzip(str, dest)
|
|
851
851
|
dest.close
|
|
852
|
-
|
|
852
|
+
|
|
853
853
|
gz = Zlib::GzipReader.new(dest)
|
|
854
854
|
data = gz.read
|
|
855
855
|
assert_equal IO.read(__FILE__), data
|
|
856
856
|
end
|
|
857
|
-
|
|
857
|
+
|
|
858
858
|
def test_gzip_return_value
|
|
859
859
|
src = Polyphony.pipe
|
|
860
860
|
dest = Polyphony.pipe
|
|
861
861
|
now = nil
|
|
862
862
|
ret = nil
|
|
863
|
-
|
|
863
|
+
|
|
864
864
|
f = spin {
|
|
865
865
|
now = Time.now
|
|
866
866
|
ret = IO.gzip(src, dest)
|
|
867
867
|
dest.close
|
|
868
868
|
}
|
|
869
|
-
|
|
869
|
+
|
|
870
870
|
src << IO.read(__FILE__)
|
|
871
871
|
src.close
|
|
872
872
|
f.await
|
|
873
|
-
|
|
873
|
+
|
|
874
874
|
gzipped = dest.read
|
|
875
875
|
assert_equal gzipped.bytesize, ret
|
|
876
876
|
end
|
|
877
|
-
|
|
877
|
+
|
|
878
878
|
def test_gzip_with_mtime_int
|
|
879
879
|
src = Polyphony.pipe
|
|
880
880
|
dest = Polyphony.pipe
|
|
881
|
-
|
|
881
|
+
|
|
882
882
|
spin {
|
|
883
883
|
IO.gzip(src, dest, mtime: 42)
|
|
884
884
|
dest.close
|
|
885
885
|
}
|
|
886
|
-
|
|
886
|
+
|
|
887
887
|
src << IO.read(__FILE__)
|
|
888
888
|
src.close
|
|
889
|
-
|
|
889
|
+
|
|
890
890
|
gz = Zlib::GzipReader.new(dest)
|
|
891
891
|
data = gz.read
|
|
892
892
|
assert_equal IO.read(__FILE__), data
|
|
893
893
|
assert_equal Time.at(42), gz.mtime
|
|
894
894
|
end
|
|
895
|
-
|
|
895
|
+
|
|
896
896
|
def test_gzip_with_mtime_false
|
|
897
897
|
src = Polyphony.pipe
|
|
898
898
|
dest = Polyphony.pipe
|
|
899
|
-
|
|
899
|
+
|
|
900
900
|
spin {
|
|
901
901
|
IO.gzip(src, dest, mtime: false)
|
|
902
902
|
dest.close
|
|
903
903
|
}
|
|
904
|
-
|
|
904
|
+
|
|
905
905
|
src << IO.read(__FILE__)
|
|
906
906
|
src.close
|
|
907
|
-
|
|
907
|
+
|
|
908
908
|
gz = Zlib::GzipReader.new(dest)
|
|
909
909
|
data = gz.read
|
|
910
910
|
assert_equal IO.read(__FILE__), data
|
|
911
911
|
assert_equal Time.at(0), gz.mtime
|
|
912
912
|
end
|
|
913
|
-
|
|
913
|
+
|
|
914
914
|
def test_gzip_with_mtime_time
|
|
915
915
|
src = Polyphony.pipe
|
|
916
916
|
dest = Polyphony.pipe
|
|
917
917
|
t = Time.at(Time.now.to_i) - rand(300000)
|
|
918
|
-
|
|
918
|
+
|
|
919
919
|
spin {
|
|
920
920
|
IO.gzip(src, dest, mtime: t)
|
|
921
921
|
dest.close
|
|
922
922
|
}
|
|
923
|
-
|
|
923
|
+
|
|
924
924
|
src << IO.read(__FILE__)
|
|
925
925
|
src.close
|
|
926
|
-
|
|
926
|
+
|
|
927
927
|
gz = Zlib::GzipReader.new(dest)
|
|
928
928
|
data = gz.read
|
|
929
929
|
assert_equal IO.read(__FILE__), data
|
|
930
930
|
assert_equal t, gz.mtime
|
|
931
931
|
end
|
|
932
|
-
|
|
932
|
+
|
|
933
933
|
def test_gzip_with_orig_name
|
|
934
934
|
src = Polyphony.pipe
|
|
935
935
|
dest = Polyphony.pipe
|
|
936
|
-
|
|
936
|
+
|
|
937
937
|
spin {
|
|
938
938
|
IO.gzip(src, dest, orig_name: '/foo/bar')
|
|
939
939
|
dest.close
|
|
940
940
|
}
|
|
941
|
-
|
|
941
|
+
|
|
942
942
|
src << IO.read(__FILE__)
|
|
943
943
|
src.close
|
|
944
|
-
|
|
944
|
+
|
|
945
945
|
gz = Zlib::GzipReader.new(dest)
|
|
946
946
|
data = gz.read
|
|
947
947
|
assert_equal IO.read(__FILE__), data
|
|
948
948
|
assert_equal '/foo/bar', gz.orig_name
|
|
949
949
|
end
|
|
950
|
-
|
|
950
|
+
|
|
951
951
|
def test_gzip_with_comment
|
|
952
952
|
src = Polyphony.pipe
|
|
953
953
|
dest = Polyphony.pipe
|
|
954
|
-
|
|
954
|
+
|
|
955
955
|
spin {
|
|
956
956
|
IO.gzip(src, dest, comment: 'hello!')
|
|
957
957
|
dest.close
|
|
958
958
|
}
|
|
959
|
-
|
|
959
|
+
|
|
960
960
|
src << IO.read(__FILE__)
|
|
961
961
|
src.close
|
|
962
|
-
|
|
962
|
+
|
|
963
963
|
gz = Zlib::GzipReader.new(dest)
|
|
964
964
|
data = gz.read
|
|
965
965
|
assert_equal IO.read(__FILE__), data
|
|
966
966
|
assert_equal 'hello!', gz.comment
|
|
967
967
|
end
|
|
968
|
-
|
|
968
|
+
|
|
969
969
|
def test_gunzip
|
|
970
970
|
src = Polyphony.pipe
|
|
971
971
|
dest = Polyphony.pipe
|
|
972
972
|
ret = nil
|
|
973
|
-
|
|
973
|
+
|
|
974
974
|
f = spin {
|
|
975
975
|
ret = IO.gunzip(src, dest)
|
|
976
976
|
dest.close
|
|
977
977
|
}
|
|
978
|
-
|
|
978
|
+
|
|
979
979
|
gz = Zlib::GzipWriter.new(src, 9)
|
|
980
980
|
gz << IO.read(__FILE__)
|
|
981
981
|
gz.close
|
|
982
982
|
f.await
|
|
983
|
-
|
|
983
|
+
|
|
984
984
|
data = dest.read
|
|
985
985
|
assert_equal IO.read(__FILE__).bytesize, ret
|
|
986
986
|
assert_equal IO.read(__FILE__), data
|
|
987
987
|
end
|
|
988
|
-
|
|
988
|
+
|
|
989
989
|
def test_gunzip_to_string
|
|
990
990
|
src = Polyphony.pipe
|
|
991
991
|
str = +''
|
|
992
992
|
ret = nil
|
|
993
|
-
|
|
993
|
+
|
|
994
994
|
f = spin {
|
|
995
995
|
ret = IO.gunzip(src, str)
|
|
996
996
|
}
|
|
997
|
-
|
|
997
|
+
|
|
998
998
|
gz = Zlib::GzipWriter.new(src, 9)
|
|
999
999
|
gz << IO.read(__FILE__)
|
|
1000
1000
|
gz.close
|
|
1001
1001
|
f.await
|
|
1002
|
-
|
|
1002
|
+
|
|
1003
1003
|
assert_equal IO.read(__FILE__).bytesize, ret
|
|
1004
1004
|
assert_equal IO.read(__FILE__), str
|
|
1005
1005
|
end
|
|
1006
|
-
|
|
1006
|
+
|
|
1007
1007
|
def test_gunzip_from_string
|
|
1008
1008
|
src_data = 'foobar' * 1000
|
|
1009
1009
|
str = Zlib.gzip(src_data, level: 9)
|
|
1010
1010
|
dest = Polyphony.pipe
|
|
1011
1011
|
ret = IO.gunzip(str, dest)
|
|
1012
1012
|
dest.close
|
|
1013
|
-
|
|
1013
|
+
|
|
1014
1014
|
dest_data = dest.read
|
|
1015
1015
|
assert_equal src_data.bytesize, ret
|
|
1016
1016
|
assert_equal src_data, dest_data
|
|
1017
1017
|
end
|
|
1018
|
-
|
|
1018
|
+
|
|
1019
1019
|
def test_gunzip_multi
|
|
1020
1020
|
src1 = Polyphony.pipe
|
|
1021
1021
|
src2 = Polyphony.pipe
|
|
1022
1022
|
dest = Polyphony.pipe
|
|
1023
|
-
|
|
1023
|
+
|
|
1024
1024
|
spin {
|
|
1025
1025
|
IO.gunzip(src1, dest)
|
|
1026
1026
|
IO.gunzip(src2, dest)
|
|
1027
1027
|
dest.close
|
|
1028
1028
|
}
|
|
1029
|
-
|
|
1029
|
+
|
|
1030
1030
|
gz1 = Zlib::GzipWriter.new(src1)
|
|
1031
1031
|
gz1 << 'foobar'
|
|
1032
1032
|
gz1.close
|
|
1033
|
-
|
|
1033
|
+
|
|
1034
1034
|
gz1 = Zlib::GzipWriter.new(src2)
|
|
1035
1035
|
gz1 << 'raboof'
|
|
1036
1036
|
gz1.close
|
|
1037
|
-
|
|
1037
|
+
|
|
1038
1038
|
data = dest.read
|
|
1039
1039
|
assert_equal 'foobarraboof', data
|
|
1040
1040
|
end
|
|
1041
|
-
|
|
1041
|
+
|
|
1042
1042
|
def test_gzip_gunzip
|
|
1043
1043
|
gzipped = Polyphony.pipe
|
|
1044
1044
|
gunzipped = Polyphony.pipe
|
|
1045
|
-
|
|
1045
|
+
|
|
1046
1046
|
spin { File.open(__FILE__, 'r') { |f| IO.gzip(f, gzipped) }; gzipped.close }
|
|
1047
1047
|
spin { IO.gunzip(gzipped, gunzipped); gunzipped.close }
|
|
1048
|
-
|
|
1048
|
+
|
|
1049
1049
|
data = gunzipped.read
|
|
1050
1050
|
assert_equal IO.read(__FILE__), data
|
|
1051
1051
|
end
|
|
1052
|
-
|
|
1052
|
+
|
|
1053
1053
|
def test_gunzip_with_empty_info
|
|
1054
1054
|
gzipped = Polyphony.pipe
|
|
1055
1055
|
gunzipped = Polyphony.pipe
|
|
1056
1056
|
info = {}
|
|
1057
|
-
|
|
1057
|
+
|
|
1058
1058
|
spin {
|
|
1059
1059
|
File.open(__FILE__, 'r') { |f| IO.gzip(f, gzipped, mtime: false) }
|
|
1060
1060
|
gzipped.close
|
|
1061
1061
|
}
|
|
1062
1062
|
spin { IO.gunzip(gzipped, gunzipped, info); gunzipped.close }
|
|
1063
|
-
|
|
1063
|
+
|
|
1064
1064
|
data = gunzipped.read
|
|
1065
1065
|
assert_equal IO.read(__FILE__), data
|
|
1066
1066
|
assert_equal Time.at(0), info[:mtime]
|
|
1067
1067
|
assert_nil info[:orig_name]
|
|
1068
1068
|
assert_nil info[:comment]
|
|
1069
1069
|
end
|
|
1070
|
-
|
|
1070
|
+
|
|
1071
1071
|
def test_gunzip_with_info
|
|
1072
1072
|
src = Polyphony.pipe
|
|
1073
1073
|
gzipped = Polyphony.pipe
|
|
1074
1074
|
gunzipped = Polyphony.pipe
|
|
1075
|
-
|
|
1075
|
+
|
|
1076
1076
|
src_info = {
|
|
1077
1077
|
mtime: 42,
|
|
1078
1078
|
orig_name: 'foo.bar',
|
|
1079
1079
|
comment: 'hello!'
|
|
1080
1080
|
}
|
|
1081
|
-
|
|
1081
|
+
|
|
1082
1082
|
dest_info = {}
|
|
1083
|
-
|
|
1083
|
+
|
|
1084
1084
|
spin { IO.gzip(src, gzipped, src_info); gzipped.close }
|
|
1085
1085
|
spin { IO.gunzip(gzipped, gunzipped, dest_info); gunzipped.close }
|
|
1086
|
-
|
|
1086
|
+
|
|
1087
1087
|
src << 'foobar'
|
|
1088
1088
|
src.close
|
|
1089
|
-
|
|
1089
|
+
|
|
1090
1090
|
data = gunzipped.read
|
|
1091
1091
|
assert_equal 'foobar', data
|
|
1092
1092
|
assert_equal Time.at(42), dest_info[:mtime]
|
|
1093
1093
|
assert_equal 'foo.bar', dest_info[:orig_name]
|
|
1094
1094
|
assert_equal 'hello!', dest_info[:comment]
|
|
1095
1095
|
end
|
|
1096
|
-
|
|
1096
|
+
|
|
1097
1097
|
def test_deflate_inflate_strings
|
|
1098
1098
|
src_data = IO.read(__FILE__)
|
|
1099
1099
|
deflated = +''
|
|
1100
1100
|
IO.deflate(src_data, deflated)
|
|
1101
1101
|
inflated = +''
|
|
1102
1102
|
IO.inflate(deflated, inflated)
|
|
1103
|
-
|
|
1103
|
+
|
|
1104
1104
|
assert_equal src_data, inflated
|
|
1105
1105
|
end
|
|
1106
|
-
|
|
1106
|
+
|
|
1107
1107
|
def test_gzip_gunzip_strings
|
|
1108
1108
|
src_data = IO.read(__FILE__)
|
|
1109
1109
|
gzipped = +''
|
|
1110
1110
|
IO.gzip(src_data, gzipped)
|
|
1111
1111
|
gunzipped = +''
|
|
1112
1112
|
IO.gunzip(gzipped, gunzipped)
|
|
1113
|
-
|
|
1113
|
+
|
|
1114
1114
|
assert_equal src_data, gunzipped
|
|
1115
1115
|
end
|
|
1116
1116
|
end
|
|
1117
|
+
|
|
1118
|
+
class IOIssuesTest < MiniTest::Test
|
|
1119
|
+
def test_issue_93
|
|
1120
|
+
# Write a file with 100 lines of 100 000 characters each
|
|
1121
|
+
File.open('/tmp/test.gz', 'w+') do |file|
|
|
1122
|
+
gz = Zlib::GzipWriter.new(file)
|
|
1123
|
+
gz.write("#{'a' * 10_000}\n" * 1000)
|
|
1124
|
+
gz.close
|
|
1125
|
+
end
|
|
1126
|
+
|
|
1127
|
+
# Read the file
|
|
1128
|
+
gz = Zlib::GzipReader.open('/tmp/test.gz')
|
|
1129
|
+
count = 0
|
|
1130
|
+
it = gz.each_line
|
|
1131
|
+
|
|
1132
|
+
loop do
|
|
1133
|
+
it.next
|
|
1134
|
+
count += 1
|
|
1135
|
+
rescue StopIteration
|
|
1136
|
+
break
|
|
1137
|
+
end
|
|
1138
|
+
|
|
1139
|
+
assert_equal 1000, count
|
|
1140
|
+
end
|
|
1141
|
+
end
|