Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fifo tests. #90

Merged
merged 2 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/io/event/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@

class IO
module Event
VERSION = "1.4.0"
VERSION = "1.4.1"
end
end
70 changes: 70 additions & 0 deletions test/io/event/selector/fifo_io.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2021-2023, by Samuel Williams.

require 'io/event'
require 'io/event/selector'
require 'fileutils'
require 'tmpdir'

FifoIO = Sus::Shared("fifo io") do
with 'a fifo' do
def around
@root = Dir.mktmpdir
super
ensure
FileUtils.rm_rf(@root) if @root
end

let(:path) {File.join(@root, "fifo")}

it 'can read and write' do
File.mkfifo(path)
input = File.open(path, "r+")
output = File.open(path, "w+")

buffer = IO::Buffer.new(128)

reader = Fiber.new do
@selector.io_wait(Fiber.current, input, IO::READABLE)
result = buffer.read(input, buffer.size)
buffer.resize(result)
end

writer = Fiber.new do
output.puts("Hello World\n")
output.close
end

reader.transfer
writer.transfer

2.times do
@selector.select(0)
end

expect(buffer.get_string).to be == "Hello World\n"
end
end
end

IO::Event::Selector.constants.each do |name|
klass = IO::Event::Selector.const_get(name)

describe(klass, unique: name) do
def before
@loop = Fiber.current
@selector = subject.new(@loop)
end

def after
@selector&.close
end

attr :loop
attr :selector

it_behaves_like FifoIO
end
end
Loading