action_subscriber 3.0.0.pre1-java → 3.0.0.pre2-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1d9345303246c9e2b28d3169a40a0245460dddad
4
- data.tar.gz: 1c11f93bac81ae81db2c99e4d317cf63eddd732b
3
+ metadata.gz: 65fce1739063a1cf33dba2d29452a76add18ea96
4
+ data.tar.gz: 75d402b7e378ae9cf3d1eae35e694ffc23f4373c
5
5
  SHA512:
6
- metadata.gz: fda6c938b37ef37526bb0a77b735ee65c312c9a586622b5784aa41b9c3b3fcca67b4ff80ae9bcaae9b25d12f85ac89299215cc01916f80f5cb5c6d5aec1289c1
7
- data.tar.gz: 442d7cd524e4f9f41f262e606b4d3ed5cfd719ea1a25f2f60fffb0b6c6cacaf69b82f49f4d45b1e6d99a230a967b9576d2adcaf051faec89972a3d0003c5924c
6
+ metadata.gz: 7a7fa9c4143d3eef353301118acda43ca49b9c6bc7a07a846bc75e100aa6eefb926e31b8934b146dddb49bac572b9a2c74c3dcb860cc1cb23ddaa6c5fadd7ec6
7
+ data.tar.gz: 5861f99195162aec8d18c4d436f65f0ffda7a3e9438175218568770eaf17f54a00f1202fef76d661661a237b4375d5055e8fcb24634c509b2189e0e58a867951
@@ -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: java
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
  requirement: !ruby/object:Gem::Requirement