1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
# frozen_string_literal: true
# Released under the MIT License.
# Copyright, 2020, by Bruno Sutic.
# Copyright, 2020-2026, by Samuel Williams.
require "async"
require "async/http/body/pipe"
require "async/http/body/writable"
require "sus/fixtures/async"
require "io/stream"
describe Async::HTTP::Body::Pipe do
let(:input) {Async::HTTP::Body::Writable.new}
let(:pipe) {subject.new(input)}
let(:data) {"Hello World!"}
with "#to_io" do
include Sus::Fixtures::Async::ReactorContext
let(:input_write_duration) {0}
let(:io) {pipe.to_io}
def before
super
# input writer task
Async do |task|
first, second = data.split(" ")
input.write("#{first} ")
sleep(input_write_duration) if input_write_duration > 0
input.write(second)
input.close_write
end
end
after do
io.close
end
it "returns an io socket" do
expect(io).to be_a(::Socket)
expect(io.read).to be == data
end
with "blocking reads" do
let(:input_write_duration) {0.01}
it "returns an io socket" do
expect(io.read).to be == data
end
end
end
with "reactor going out of scope" do
it "finishes" do
# ensures pipe background tasks are transient
Async {pipe}
end
with "closed pipe" do
it "finishes" do
Async {pipe.close}
end
end
end
end
|