Skip to content

Commit

Permalink
Migrate tests from rspec -> sus.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Sep 11, 2023
1 parent 7f9a1c3 commit c7dea0b
Show file tree
Hide file tree
Showing 15 changed files with 936 additions and 982 deletions.
565 changes: 565 additions & 0 deletions fixtures/async/http/a_protocol.rb

Large diffs are not rendered by default.

110 changes: 110 additions & 0 deletions fixtures/async/http/body/a_writable_body.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# frozen_string_literal: true

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

require 'protocol/http/body/deflate'

module Async
module HTTP
module Body
AWritableBody = Sus::Shared("a writable body") do
it "can write and read data" do
3.times do |i|
body.write("Hello World #{i}")
expect(body.read).to be == "Hello World #{i}"
end
end

it "can buffer data in order" do
3.times do |i|
body.write("Hello World #{i}")
end

3.times do |i|
expect(body.read).to be == "Hello World #{i}"
end
end

with '#join' do
it "can join chunks" do
3.times do |i|
body.write("#{i}")
end

body.close

expect(body.join).to be == "012"
end
end

with '#each' do
it "can read all data in order" do
3.times do |i|
body.write("Hello World #{i}")
end

body.close

3.times do |i|
chunk = body.read
expect(chunk).to be == "Hello World #{i}"
end
end

it "can propagate failures" do
reactor.async do
expect do
body.each do |chunk|
raise RuntimeError.new("It was too big!")
end
end.to raise_exception(RuntimeError, message: be =~ /big/)
end

expect{
body.write("Beep boop") # This will cause a failure.
::Async::Task.current.yield
body.write("Beep boop") # This will fail.
}.to raise_exception(RuntimeError, message: be =~ /big/)
end

it "can propagate failures in nested bodies" do
nested = ::Protocol::HTTP::Body::Deflate.for(body)

reactor.async do
expect do
nested.each do |chunk|
raise RuntimeError.new("It was too big!")
end
end.to raise_exception(RuntimeError, message: be =~ /big/)
end

expect{
body.write("Beep boop") # This will cause a failure.
::Async::Task.current.yield
body.write("Beep boop") # This will fail.
}.to raise_exception(RuntimeError, message: be =~ /big/)
end

it "will stop after finishing" do
output_task = reactor.async do
body.each do |chunk|
expect(chunk).to be == "Hello World!"
end
end

body.write("Hello World!")
body.close

expect(body).not.to be(:empty?)

::Async::Task.current.yield

expect(output_task).to be(:finished?)
expect(body).to be(:empty?)
end
end
end
end
end
end
113 changes: 0 additions & 113 deletions fixtures/sus/fixtures/async/http/body/a_writable_body.rb

This file was deleted.

2 changes: 1 addition & 1 deletion gems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
gem "covered"
gem "sus"
gem "sus-fixtures-async"
gem "sus-fixtures-async-http", "~> 0.5"
gem "sus-fixtures-async-http", "~> 0.7"
gem "sus-fixtures-openssl"

gem "bake"
Expand Down
4 changes: 2 additions & 2 deletions test/async/http/body/slowloris.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
require 'async/http/body/slowloris'

require 'sus/fixtures/async'
require 'sus/fixtures/async/http/body/a_writable_body'
require 'async/http/body/a_writable_body'

describe Async::HTTP::Body::Slowloris do
include Sus::Fixtures::Async::ReactorContext

let(:body) {subject.new}

it_behaves_like Sus::Fixtures::Async::HTTP::Body::AWritableBody
it_behaves_like Async::HTTP::Body::AWritableBody

it "closes body with error if throughput is not maintained" do
body.write("Hello World")
Expand Down
4 changes: 2 additions & 2 deletions test/async/http/body/writable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
require 'async/http/body/slowloris'

require 'sus/fixtures/async'
require 'sus/fixtures/async/http/body/a_writable_body'
require 'async/http/body/a_writable_body'

describe Async::HTTP::Body::Writable do
include Sus::Fixtures::Async::ReactorContext

let(:body) {subject.new}

it_behaves_like Sus::Fixtures::Async::HTTP::Body::AWritableBody
it_behaves_like Async::HTTP::Body::AWritableBody
end
Loading

0 comments on commit c7dea0b

Please sign in to comment.