Skip to content

Commit 9d6307e

Browse files
committed
Merge pull request #233 from webmachine/build-tidiness
Build tidiness
2 parents bc7b147 + d300057 commit 9d6307e

File tree

4 files changed

+48
-24
lines changed

4 files changed

+48
-24
lines changed

.travis.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ rvm:
22
- 1.9.3
33
- 2.0.0
44
- 2.1.2
5+
- 2.2.0
6+
- 2.3.0
57
- ruby-head
68
- jruby
79
- rbx-2
@@ -10,6 +12,11 @@ matrix:
1012
allow_failures:
1113
- rvm: ruby-head
1214
- rvm: jruby
15+
- rvm: rbx-2
16+
17+
before_install:
18+
- gem update --system
19+
- gem update bundler
1320

1421
bundler_args: --without guard docs
1522

lib/webmachine/adapters/reel.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require 'webmachine/adapter'
22
require 'webmachine/constants'
33
require 'set'
4+
require 'celluloid/current'
45
require 'reel'
56
require 'webmachine/headers'
67
require 'webmachine/request'

lib/webmachine/spec/adapter_lint.rb

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,72 @@
11
require "webmachine/spec/test_resource"
22
require "net/http"
33

4+
ADDRESS = "127.0.0.1"
5+
46
shared_examples_for :adapter_lint do
5-
attr_accessor :client
7+
attr_reader :client
8+
9+
class TestApplicationNotResponsive < Timeout::Error; end
610

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

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

14-
application.configure do |c|
15-
c.ip = address
16-
c.port = port
21+
def create_test_application(port)
22+
Webmachine::Application.new.tap do |application|
23+
application.dispatcher.add_route ["test"], Test::Resource
24+
25+
application.configure do |c|
26+
c.ip = ADDRESS
27+
c.port = port
28+
end
1729
end
30+
end
1831

19-
application
32+
def run_application(adapter_class, application)
33+
adapter = adapter_class.new(application)
34+
Thread.abort_on_exception = true
35+
Thread.new { adapter.run }
2036
end
2137

22-
let(:client) do
23-
client = Net::HTTP.new(application.configuration.ip, port)
24-
# Wait until the server is responsive
25-
timeout(5) do
38+
def wait_until_server_responds_to(client)
39+
Timeout.timeout(5, TestApplicationNotResponsive) do
2640
begin
2741
client.start
2842
rescue Errno::ECONNREFUSED
2943
sleep(0.01)
3044
retry
3145
end
3246
end
33-
client
3447
end
3548

36-
before do
37-
@adapter = described_class.new(application)
49+
before(:all) do
50+
@port = find_free_port
51+
application = create_test_application(@port)
3852

39-
Thread.abort_on_exception = true
40-
@server_thread = Thread.new { @adapter.run }
41-
sleep(0.01)
53+
adapter_class = described_class
54+
@server_thread = run_application(adapter_class, application)
55+
56+
@client = Net::HTTP.new(application.configuration.ip, @port)
57+
wait_until_server_responds_to(client)
4258
end
4359

44-
after do
45-
client.finish
60+
after(:all) do
61+
@client.finish
4662
@server_thread.kill
4763
end
4864

4965
it "provides the request URI" do
5066
request = Net::HTTP::Get.new("/test")
5167
request["Accept"] = "test/response.request_uri"
5268
response = client.request(request)
53-
expect(response.body).to eq("http://#{address}:#{port}/test")
69+
expect(response.body).to eq("http://#{ADDRESS}:#{@port}/test")
5470
end
5571

5672
# context do

spec/webmachine/adapters/reel_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
def reel_server(adptr = adapter)
5757
thread = Thread.new { adptr.run }
5858
begin
59-
timeout(5) do
59+
Timeout.timeout(5) do
6060
begin
6161
sock = TCPSocket.new(adptr.application.configuration.ip, adptr.application.configuration.port)
6262
begin

0 commit comments

Comments
 (0)