Skip to content

Build tidiness #233

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

Merged
merged 8 commits into from
Apr 24, 2016
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
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ rvm:
- 1.9.3
- 2.0.0
- 2.1.2
- 2.2.0
- 2.3.0
- ruby-head
- jruby
- rbx-2
Expand All @@ -10,6 +12,11 @@ matrix:
allow_failures:
- rvm: ruby-head
- rvm: jruby
- rvm: rbx-2

before_install:
- gem update --system
- gem update bundler

bundler_args: --without guard docs

Expand Down
1 change: 1 addition & 0 deletions lib/webmachine/adapters/reel.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'webmachine/adapter'
require 'webmachine/constants'
require 'set'
require 'celluloid/current'
require 'reel'
require 'webmachine/headers'
require 'webmachine/request'
Expand Down
62 changes: 39 additions & 23 deletions lib/webmachine/spec/adapter_lint.rb
Original file line number Diff line number Diff line change
@@ -1,56 +1,72 @@
require "webmachine/spec/test_resource"
require "net/http"

ADDRESS = "127.0.0.1"

shared_examples_for :adapter_lint do
attr_accessor :client
attr_reader :client

class TestApplicationNotResponsive < Timeout::Error; end

let(:address) { "127.0.0.1" }
let(:port) { s = TCPServer.new(address, 0); p = s.addr[1]; s.close; p }
def find_free_port
temp_server = TCPServer.new(ADDRESS, 0)
port = temp_server.addr[1]
temp_server.close # only frees Ruby resource, socket is in TIME_WAIT at OS level
# so we can't have our adapter use it too quickly

let(:application) do
application = Webmachine::Application.new
application.dispatcher.add_route ["test"], Test::Resource
sleep(0.1) # 'Wait' for temp_server to *really* close, not just TIME_WAIT
port
end

application.configure do |c|
c.ip = address
c.port = port
def create_test_application(port)
Webmachine::Application.new.tap do |application|
application.dispatcher.add_route ["test"], Test::Resource

application.configure do |c|
c.ip = ADDRESS
c.port = port
end
end
end

application
def run_application(adapter_class, application)
adapter = adapter_class.new(application)
Thread.abort_on_exception = true
Thread.new { adapter.run }
end

let(:client) do
client = Net::HTTP.new(application.configuration.ip, port)
# Wait until the server is responsive
timeout(5) do
def wait_until_server_responds_to(client)
Timeout.timeout(5, TestApplicationNotResponsive) do
begin
client.start
rescue Errno::ECONNREFUSED
sleep(0.01)
retry
end
end
client
end

before do
@adapter = described_class.new(application)
before(:all) do
@port = find_free_port
application = create_test_application(@port)

Thread.abort_on_exception = true
@server_thread = Thread.new { @adapter.run }
sleep(0.01)
adapter_class = described_class
@server_thread = run_application(adapter_class, application)

@client = Net::HTTP.new(application.configuration.ip, @port)
wait_until_server_responds_to(client)
end

after do
client.finish
after(:all) do
@client.finish
@server_thread.kill
end

it "provides the request URI" do
request = Net::HTTP::Get.new("/test")
request["Accept"] = "test/response.request_uri"
response = client.request(request)
expect(response.body).to eq("http://#{address}:#{port}/test")
expect(response.body).to eq("http://#{ADDRESS}:#{@port}/test")
end

# context do
Expand Down
2 changes: 1 addition & 1 deletion spec/webmachine/adapters/reel_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
def reel_server(adptr = adapter)
thread = Thread.new { adptr.run }
begin
timeout(5) do
Timeout.timeout(5) do
begin
sock = TCPSocket.new(adptr.application.configuration.ip, adptr.application.configuration.port)
begin
Expand Down