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

Drop thin support #1627

Merged
merged 7 commits into from
Aug 8, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Create integration_async_test for to be enable test with rainbows
  • Loading branch information
rkmathi committed Aug 8, 2020
commit 965c8b9c39da2163592415f0056a196f31049b95
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ if RUBY_ENGINE == "ruby"
gem 'puma'
gem 'yajl-ruby'
gem 'nokogiri'
gem 'puma'
gem 'rainbows'
gem 'eventmachine'
gem 'slim', '~> 2.0'
gem 'coffee-script', '>= 2.0'
gem 'rdoc'
Expand Down
2 changes: 2 additions & 0 deletions test/integration/app.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
$stderr.puts "loading"
require 'sinatra'

require_relative 'rainbows' if RUBY_ENGINE == 'ruby'

configure do
set :foo, :bar
end
Expand Down
3 changes: 3 additions & 0 deletions test/integration/rainbows.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Rainbows! do
use :EventMachine
end
20 changes: 20 additions & 0 deletions test/integration/rainbows.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require 'rainbows'

module Rack
module Handler
class Rainbows
def self.run(app, **options)
rainbows_options = {
listeners: ["#{options[:Host]}:#{options[:Port]}"],
worker_processes: 1,
timeout: 30,
config_file: ::File.expand_path('../rainbows.conf', __FILE__),
}

::Rainbows::HttpServer.new(app, rainbows_options).start.join
end
end

register "rainbows", "Rack::Handler::Rainbows"
end
end
14 changes: 14 additions & 0 deletions test/integration_async_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require File.expand_path('../integration_helper', __FILE__)

module IntegrationAsyncHelper
def it(message, &block)
base_port = 5100 + Process.pid % 100

%w(rainbows).each_with_index do |server_name, index|
server = IntegrationHelper::BaseServer.new(server_name, base_port + index)
next unless server.installed?

super("with #{server.name}: #{message}") { server.run_test(self, &block) }
end
end
end
40 changes: 40 additions & 0 deletions test/integration_async_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
require File.expand_path('../helper', __FILE__)
require File.expand_path('../integration_async_helper', __FILE__)

# These tests are like integration_test, but they test asynchronous streaming.
class IntegrationAsyncTest < Minitest::Test
extend IntegrationAsyncHelper
attr_accessor :server

it 'streams async' do
Timeout.timeout(3) do
chunks = []
server.get_stream '/async' do |chunk|
next if chunk.empty?
chunks << chunk
case chunk
when "hi!" then server.get "/send?msg=hello"
when "hello" then server.get "/send?close=1"
end
end

assert_equal ['hi!', 'hello'], chunks
end
end

it 'streams async from subclass' do
Timeout.timeout(3) do
chunks = []
server.get_stream '/subclass/async' do |chunk|
next if chunk.empty?
chunks << chunk
case chunk
when "hi!" then server.get "/subclass/send?msg=hello"
when "hello" then server.get "/subclass/send?close=1"
end
end

assert_equal ['hi!', 'hello'], chunks
end
end
end
40 changes: 2 additions & 38 deletions test/integration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class IntegrationTest < Minitest::Test
it('only extends main') { assert_equal "true", server.get("/mainonly") }

it 'logs once in development mode' do
next if server.puma? or RUBY_ENGINE == 'jruby'
next if server.puma? or server.rainbows? or RUBY_ENGINE == 'jruby'
random = "%064x" % Kernel.rand(2**256-1)
server.get "/ping?x=#{random}"
count = server.log.scan("GET /ping?x=#{random}").count
Expand All @@ -39,42 +39,6 @@ class IntegrationTest < Minitest::Test
assert times[2] - times[1] > 1
end

it 'streams async' do
next unless server.rainbows?

Timeout.timeout(3) do
chunks = []
server.get_stream '/async' do |chunk|
next if chunk.empty?
chunks << chunk
case chunk
when "hi!" then server.get "/send?msg=hello"
when "hello" then server.get "/send?close=1"
end
end

assert_equal ['hi!', 'hello'], chunks
end
end

it 'streams async from subclass' do
next unless server.rainbows?

Timeout.timeout(3) do
chunks = []
server.get_stream '/subclass/async' do |chunk|
next if chunk.empty?
chunks << chunk
case chunk
when "hi!" then server.get "/subclass/send?msg=hello"
when "hello" then server.get "/subclass/send?close=1"
end
end

assert_equal ['hi!', 'hello'], chunks
end
end

namusyaka marked this conversation as resolved.
Show resolved Hide resolved
it 'starts the correct server' do
exp = %r{
==\sSinatra\s\(v#{Sinatra::VERSION}\)\s
Expand All @@ -83,7 +47,7 @@ class IntegrationTest < Minitest::Test
}ix

# because Net HTTP Server logs to $stderr by default
assert_match exp, server.log unless server.net_http_server? || server.reel?
assert_match exp, server.log unless server.net_http_server? || server.reel? || server.rainbows?
end

it 'does not generate warnings' do
Expand Down