-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create integration_async_test for to be enable test with rainbows
- Loading branch information
Showing
7 changed files
with
83 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Rainbows! do | ||
use :EventMachine | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters