action_subscriber 3.0.0.pre1 → 3.0.0.pre2

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: b0a848297f91f557f43e6240545866aaad495d17
4
- data.tar.gz: 0fd512e453740a0ad0e34f1f42ddef7ab5ac240f
3
+ metadata.gz: f453f7e59eee1009c949b5e395359dc59b637c5f
4
+ data.tar.gz: 426ef40b324f3770306f790b3f03673905670a23
5
5
  SHA512:
6
- metadata.gz: 6d30b59daffa7e89a4c48eb3044a65af90804d91b3c0991e3dd0899b9a20944532878bc6327684577d05c11b9017edfb233bbd251daa42dff9a50d614f4701da
7
- data.tar.gz: df4cf38fe9cbfed26adcc53e43823348726176cc387ccaa46d22274099182198aa1c2d1fcd1c7e341d87dd6e4f1a88e24702788a41c9955e8a2161a880459d56
6
+ metadata.gz: b644cb531eacde80a9f7878fcfeb3c50925b70dc5bafdf3d753462a505883645e7bf81220e727aac99b399a82e9951df276676e9a12d20e903a22dd72132df65
7
+ data.tar.gz: 410c264a22022b14a2fe4a7a44674c184b982dcd9562b5e2966def02b12043ee3fe6f27387b139820f32e5cdd1e53edcc3d4af42b954d3e8a139c9ce5cad6af2
@@ -8,17 +8,26 @@ module ActionSubscriber
8
8
  end
9
9
 
10
10
  def call(env)
11
- # This insulates the connection thread from errors that are raised by the error_handle or
12
- # exceptions that don't fall under StandardError (which are not caught by `rescue => error`)
13
- new_thread = ::Thread.new do
14
- begin
15
- @app.call(env)
16
- rescue => error
17
- logger.error "FAILED #{env.message_id}"
18
- ::ActionSubscriber.configuration.error_handler.call(error, env.to_h)
11
+ job_mutex = ::Mutex.new
12
+ job_complete = ::ConditionVariable.new
13
+
14
+ job_mutex.synchronize do
15
+ ::Thread.new do
16
+ job_mutex.synchronize do
17
+ begin
18
+ @app.call(env)
19
+ rescue => error
20
+ logger.error "FAILED #{env.message_id}"
21
+ ::ActionSubscriber.configuration.error_handler.call(error, env.to_h)
22
+ ensure
23
+ job_complete.signal
24
+ end
25
+ end
19
26
  end
27
+
28
+ # TODO we might want to pass a timeout to this wait so we can handle jobs that get frozen
29
+ job_complete.wait(job_mutex)
20
30
  end
21
- ::Thread.pass while new_thread.alive?
22
31
  end
23
32
  end
24
33
  end
@@ -13,13 +13,15 @@ module ActionSubscriber
13
13
  end
14
14
 
15
15
  def self.subscriber_connected?
16
- subscriber_connections.all?{|_name, connection| connection.connected?}
16
+ SUBSCRIBER_CONNECTION_MUTEX.synchronize do
17
+ subscriber_connections.all?{|_name, connection| connection.connected?}
18
+ end
17
19
  end
18
20
 
19
21
  def self.subscriber_disconnect!
20
22
  SUBSCRIBER_CONNECTION_MUTEX.synchronize do
21
23
  subscriber_connections.each{|_name, connection| connection.close}
22
- @subscriber_connections = []
24
+ @subscriber_connections = {}
23
25
  end
24
26
  end
25
27
 
@@ -40,8 +40,9 @@ module ActionSubscriber
40
40
  ].compact.join(".")
41
41
  end
42
42
 
43
- def default_routes_for(subscriber)
44
- subscriber.routes({:connection_name => @current_connection_name}).each do |route|
43
+ def default_routes_for(subscriber, options = {})
44
+ options = options.merge({:connection_name => @current_connection_name})
45
+ subscriber.routes(options).each do |route|
45
46
  routes << route
46
47
  end
47
48
  end
@@ -1,3 +1,3 @@
1
1
  module ActionSubscriber
2
- VERSION = "3.0.0.pre1"
2
+ VERSION = "3.0.0.pre2"
3
3
  end
@@ -19,4 +19,19 @@ describe ActionSubscriber::Middleware::ErrorHandler do
19
19
  subject.call(env)
20
20
  end
21
21
  end
22
+
23
+ context "many concurrent threads" do
24
+ it "handles the race conditions without raising exceptions" do
25
+ no_op = lambda{ nil }
26
+ threads = 1.upto(100).map do
27
+ ::Thread.new do
28
+ ::Thread.current.abort_on_exception = true
29
+ 100.times do
30
+ described_class.new(no_op).call(env)
31
+ end
32
+ end
33
+ end
34
+ threads.each(&:join)
35
+ end
36
+ end
22
37
  end
data/spec/spec_helper.rb CHANGED
@@ -33,6 +33,7 @@ RSpec.configure do |config|
33
33
  ::ActionSubscriber.instance_variable_set("@route_set_block", nil)
34
34
  end
35
35
  config.after(:suite) do
36
+ ::ActionSubscriber.stop_subscribers!
36
37
  ::ActionSubscriber::RabbitConnection.subscriber_disconnect!
37
38
  end
38
39
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: action_subscriber
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0.pre1
4
+ version: 3.0.0.pre2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Stien
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2016-09-15 00:00:00.000000000 Z
15
+ date: 2016-09-20 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: activesupport