capybarbecue 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a2678761d8bc81927ea82cb9bca880c1a8818043
4
- data.tar.gz: 6d41973f08aa3b7f8bd69cb0bae7fe88db3e77c8
3
+ metadata.gz: 27de67f89e44f79597616f0b196c84d0632e724f
4
+ data.tar.gz: bc371c0201a52e2cc887df403aa0bd3a9b8d9e39
5
5
  SHA512:
6
- metadata.gz: ef670b9982bc9a534a8b36b1f5edcf05c99e0a22d334bb8e88af8d6505ffee4dd0d169f156a7bf8ce29b214bcbff6771a74e1bc7c26f2518a1af50ead9f58b89
7
- data.tar.gz: 63a06f7afeffa2d0b9d66f15d62dd0767efc01842d15c73a8483c06ff912cad74af0e2f7aa9773a9aa138ebad0230b021d03ca615635e75471c5a0b944758718
6
+ metadata.gz: 290b2dff533e72f579b90a256ed111d167620da15a9a624df3c33bb5996699aea4b6a4ec85cfb0a59c96c4a32d5687523ad9b9fe20b5dc993cc59d4cc958a2a5
7
+ data.tar.gz: 328e5dc4f01996ff18c791b585a4cc3024c6ece748dc40b13fea459c250edd6acea0bb1c95f3fe9f8b98e0e8013333603e981797c5fc5abb9dab3bf4f7c9be4a
@@ -14,6 +14,7 @@ module Capybarbecue
14
14
  end
15
15
 
16
16
  def call(env)
17
+ env.update({"rack.multithread" => false, "rack.multiprocess" => false, "rack.run_once" => false})
17
18
  queue_and_wait(env)
18
19
  end
19
20
 
@@ -38,19 +39,27 @@ module Capybarbecue
38
39
  request = QueuedRequest.new(env)
39
40
  @requestmq.enq(request)
40
41
  return unless wait_for_response
42
+ wait_for request
43
+ check_exception_for request
44
+ request.response
45
+ end
46
+
47
+ def wait_for(request)
41
48
  started_at = Time.now
42
49
  while !request.ready? && Time.now - started_at < timeout.seconds
43
50
  # It feels dangerous not to sleep here... keep a pulse on this (sleep causes performance problems)
44
51
  Thread.pass
45
52
  end
46
53
  raise Timeout::Error.new('Timeout expired before response received') unless request.ready?
54
+ end
55
+
56
+ def check_exception_for(request)
47
57
  if request.exception.present?
48
58
  # Add the backtrace from this thread to make it useful
49
59
  backtrace = request.exception.backtrace + Kernel.caller
50
60
  request.exception.set_backtrace(backtrace)
51
61
  raise request.exception
52
62
  end
53
- request.response
54
63
  end
55
64
 
56
65
  class QueuedRequest
@@ -1,3 +1,3 @@
1
1
  module Capybarbecue
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
  end
@@ -11,8 +11,8 @@ describe Capybarbecue::Server do
11
11
  describe '#handle_requests' do
12
12
  before{ subject.wait_for_response = false }
13
13
  it 'responds to all queued requests' do
14
- request1 = Object.new
15
- request2 = Object.new
14
+ request1 = {}
15
+ request2 = {}
16
16
  mock(app).call(request1)
17
17
  mock(app).call(request2)
18
18
  subject.call(request1)
@@ -23,7 +23,7 @@ describe Capybarbecue::Server do
23
23
  let(:body){ Rack::BodyProxy.new('body') }
24
24
  before do
25
25
  stub(app).call { [200, {}, body] }
26
- subject.call(nil)
26
+ subject.call({})
27
27
  end
28
28
  it 'closes the BodyProxy' do
29
29
  mock(body).close
@@ -32,6 +32,15 @@ describe Capybarbecue::Server do
32
32
  end
33
33
  end
34
34
  describe '#call' do
35
+ it 'sets some env properties' do
36
+ stub(subject).queue_and_wait
37
+ env = {}
38
+ subject.call(env)
39
+ env.keys.should match_array %w{rack.multithread rack.multiprocess rack.run_once}
40
+ env['rack.multithread'].should be_false
41
+ env['rack.multiprocess'].should be_false
42
+ env['rack.run_once'].should be_false
43
+ end
35
44
  context 'when another thread handles the request' do
36
45
  before do
37
46
  stub(app).call.with_any_args { |arg| arg }
@@ -46,7 +55,8 @@ describe Capybarbecue::Server do
46
55
  end
47
56
  after { thread.kill }
48
57
  it 'gives the response' do
49
- expect(subject.call('avacado')).to eq 'avacado'
58
+ env = {}
59
+ expect(subject.call(env)).to be env
50
60
  end
51
61
  context 'when there is an exception' do
52
62
  before do
@@ -60,7 +70,7 @@ describe Capybarbecue::Server do
60
70
  context 'when the timeout expires' do
61
71
  before{ subject.timeout = 0.01 }
62
72
  it 'raises an exception' do
63
- expect{ subject.call(nil) }.to raise_error Timeout::Error
73
+ expect{ subject.call({}) }.to raise_error Timeout::Error
64
74
  end
65
75
  end
66
76
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capybarbecue
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew DiMichele
@@ -122,6 +122,20 @@ dependencies:
122
122
  - - '>='
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rake
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
125
139
  description: Makes fundamental changes to Capybara's threading architecture so you
126
140
  can write stable tests with a shared database connection.
127
141
  email: backflip@gmail.com