exceptional_synchrony 1.3.0.pre.1 → 1.4.0.pre.3
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 +4 -4
- data/CHANGELOG.md +7 -2
- data/Gemfile +0 -1
- data/Gemfile.lock +3 -7
- data/Rakefile +1 -1
- data/lib/exceptional_synchrony/event_machine_proxy.rb +5 -0
- data/lib/exceptional_synchrony/faraday_monkey_patch.rb +52 -0
- data/lib/exceptional_synchrony/version.rb +1 -1
- data/test/unit/event_machine_proxy_test.rb +21 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f2d07494229878e6b59b249b36914d1a6487393ebd636ac239c0f865abbd1bf1
|
4
|
+
data.tar.gz: af0fba3287a3c9dad53c46cb3f6290c2ba478cd9ef41a1811f8ac4d008837564
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ccbed6964c6408c17d178d48641c0f96941ee997f55b5656d59c1d3f0a31c97a2c5de2fd2f752297ee99cbd1d0e35e86746adf2cf44a0d29b8cb9df120f53dc4
|
7
|
+
data.tar.gz: b04f34c08e1a9da226a9bf679985017cd6e86b18f173152169e7be9cf7e143c46fbe85cee265ce6112e4fc03a369abb39cbf14cf9070684375a31c4f4c941c3d
|
data/CHANGELOG.md
CHANGED
@@ -6,7 +6,11 @@ Note: This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0
|
|
6
6
|
|
7
7
|
All notable changes to this project will be documented in this file.
|
8
8
|
|
9
|
-
## [1.
|
9
|
+
## [1.4.0] - UNRELEASED
|
10
|
+
### Added
|
11
|
+
- Added use of Thread local variable to indicate when Eventmachine is running using EM::Synchrony
|
12
|
+
|
13
|
+
## [1.3.0] - 2021-02-04
|
10
14
|
### Added
|
11
15
|
- Extend `EMP.defer` to have a new keyword argument, `wait_for_result` for the callers to control whether they should should block until the background thread returns. To preserve existing behavior, this option defaults to `true`, so `EMP.defer` will block in order to return the value (or raise an exception) from the deferred block. Callers can pass `wait_for_result: false` if they do not want to block.
|
12
16
|
|
@@ -24,6 +28,7 @@ All notable changes to this project will be documented in this file.
|
|
24
28
|
## [1.1.1] - 2020-05-03
|
25
29
|
- Replace hobo_support with invoca_utils
|
26
30
|
|
31
|
+
[1.4.0]: https://github.com/Invoca/exceptional_synchrony/compare/v1.3.0...v1.4.0
|
27
32
|
[1.3.0]: https://github.com/Invoca/exceptional_synchrony/compare/v1.2.0...v1.3.0
|
28
33
|
[1.2.0]: https://github.com/Invoca/exceptional_synchrony/compare/v1.1.1...v1.2.0
|
29
|
-
[1.1.1]: https://github.com/Invoca/exceptional_synchrony/compare/v1.1.0...v1.1.1
|
34
|
+
[1.1.1]: https://github.com/Invoca/exceptional_synchrony/compare/v1.1.0...v1.1.1
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
exceptional_synchrony (1.
|
4
|
+
exceptional_synchrony (1.4.0.pre.3)
|
5
5
|
em-http-request
|
6
6
|
em-synchrony
|
7
7
|
eventmachine
|
@@ -76,7 +76,7 @@ GEM
|
|
76
76
|
activesupport (>= 4.2.0)
|
77
77
|
hashdiff (1.0.1)
|
78
78
|
http_parser.rb (0.6.0)
|
79
|
-
i18n (1.8.
|
79
|
+
i18n (1.8.8)
|
80
80
|
concurrent-ruby (~> 1.0)
|
81
81
|
invoca-utils (0.4.1)
|
82
82
|
json (2.5.1)
|
@@ -87,15 +87,13 @@ GEM
|
|
87
87
|
mini_mime (>= 0.1.1)
|
88
88
|
method_source (1.0.0)
|
89
89
|
mini_mime (1.0.2)
|
90
|
-
mini_portile2 (2.5.0)
|
91
90
|
minitest (5.14.0)
|
92
91
|
minitest-reporters (1.4.2)
|
93
92
|
ansi
|
94
93
|
builder
|
95
94
|
minitest (>= 5.0)
|
96
95
|
ruby-progressbar
|
97
|
-
nokogiri (1.11.1)
|
98
|
-
mini_portile2 (~> 2.5.0)
|
96
|
+
nokogiri (1.11.1-x86_64-darwin)
|
99
97
|
racc (~> 1.4)
|
100
98
|
pry (0.13.1)
|
101
99
|
coderay (~> 1.1)
|
@@ -114,7 +112,6 @@ GEM
|
|
114
112
|
rr (1.2.1)
|
115
113
|
ruby-progressbar (1.10.1)
|
116
114
|
safe_yaml (1.0.5)
|
117
|
-
test_overrides (1.0.0)
|
118
115
|
thor (1.0.1)
|
119
116
|
tzinfo (2.0.4)
|
120
117
|
concurrent-ruby (~> 1.0)
|
@@ -134,7 +131,6 @@ DEPENDENCIES
|
|
134
131
|
pry
|
135
132
|
rake
|
136
133
|
rr (~> 1.2)
|
137
|
-
test_overrides
|
138
134
|
thor
|
139
135
|
webmock (~> 1.24)
|
140
136
|
|
data/Rakefile
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
require 'eventmachine'
|
4
4
|
require 'em-http'
|
5
5
|
require 'em-synchrony/em-http'
|
6
|
+
require_relative 'faraday_monkey_patch'
|
6
7
|
|
7
8
|
module ExceptionalSynchrony
|
8
9
|
# It is important for this exception to be inherited from Exception so that
|
@@ -62,6 +63,7 @@ module ExceptionalSynchrony
|
|
62
63
|
def stop
|
63
64
|
@proxy_class.stop
|
64
65
|
@proxy_class.next_tick { } #Fake out EventMachine's epoll mechanism so we don't block until timers fire
|
66
|
+
Thread.current.thread_variable_set(:em_synchrony_reactor_thread, false)
|
65
67
|
end
|
66
68
|
|
67
69
|
def defers_finished?
|
@@ -72,6 +74,7 @@ module ExceptionalSynchrony
|
|
72
74
|
@proxy_class.connect(server, port, handler, *args, &block)
|
73
75
|
end
|
74
76
|
|
77
|
+
# This method starts the EventMachine reactor.
|
75
78
|
# The on_error option has these possible values:
|
76
79
|
# :log - log any rescued StandardError exceptions and continue
|
77
80
|
# :raise - raise FatalRunError for any rescued StandardError exceptions
|
@@ -136,6 +139,7 @@ module ExceptionalSynchrony
|
|
136
139
|
def run_with_error_logging(&block)
|
137
140
|
ensure_completely_safe("run_with_error_logging") do
|
138
141
|
if @proxy_class.respond_to?(:synchrony)
|
142
|
+
Thread.current.thread_variable_set(:em_synchrony_reactor_thread, true)
|
139
143
|
@proxy_class.synchrony(&block)
|
140
144
|
else
|
141
145
|
@proxy_class.run(&block)
|
@@ -148,6 +152,7 @@ module ExceptionalSynchrony
|
|
148
152
|
|
149
153
|
rescue_exceptions_and_ensure_exit("run_with_error_raising") do
|
150
154
|
if @proxy_class.respond_to?(:synchrony)
|
155
|
+
Thread.current.thread_variable_set(:em_synchrony_reactor_thread, true)
|
151
156
|
@proxy_class.synchrony(&run_block)
|
152
157
|
else
|
153
158
|
@proxy_class.run(&run_block)
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Monkey patch for the Faraday method that creates the adapter used for a connection.
|
4
|
+
# If the thread local variable :em_synchrony_reactor_thread is true, it overrides this method
|
5
|
+
# in order to force use of the :em_synchrony adapter rather than the :net_http adapter.
|
6
|
+
# This ensures that the Eventmachine reactor does not get blocked by connection i/o.
|
7
|
+
begin
|
8
|
+
require 'faraday'
|
9
|
+
|
10
|
+
module ExceptionalSynchrony
|
11
|
+
# Patch built relative to faraday v0.17.3
|
12
|
+
module FaradayAdapterPatch_v0
|
13
|
+
def adapter(key, *args, &block)
|
14
|
+
|
15
|
+
# BEGIN PATCH
|
16
|
+
if key == :net_http && Thread.current.thread_variable_get(:em_synchrony_reactor_thread)
|
17
|
+
key = :em_synchrony
|
18
|
+
end
|
19
|
+
# END PATCH
|
20
|
+
|
21
|
+
use_symbol(Faraday::Adapter, key, *args, &block)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# Patch built relative to faraday v1.3.0 although the ruby2_keywords prefix
|
26
|
+
# was dropped from the adapter method definition to simplify this code
|
27
|
+
module FaradayPatch_v1
|
28
|
+
def adapter(klass = NO_ARGUMENT, *args, &block)
|
29
|
+
return @adapter if klass == NO_ARGUMENT
|
30
|
+
|
31
|
+
klass = Faraday::Adapter.lookup_middleware(klass) if klass.is_a?(Symbol)
|
32
|
+
|
33
|
+
# BEGIN PATCH
|
34
|
+
if klass == Faraday::Adapter::NetHttp && Thread.current.thread_variable_get(:em_synchrony_reactor_thread)
|
35
|
+
klass = Faraday::Adapter::EMSynchrony
|
36
|
+
end
|
37
|
+
# END PATCH
|
38
|
+
|
39
|
+
@adapter = self.class::Handler.new(klass, *args, &block)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
if Faraday::VERSION.start_with?("0")
|
45
|
+
Faraday::RackBuilder.prepend ExceptionalSynchrony::FaradayAdapterPatch_v0
|
46
|
+
else
|
47
|
+
Faraday::RackBuilder.prepend ExceptionalSynchrony::FaradayAdapterPatch_v1
|
48
|
+
end
|
49
|
+
|
50
|
+
rescue LoadError
|
51
|
+
# Monkey patch is not needed if faraday is not available
|
52
|
+
end
|
@@ -64,6 +64,14 @@ describe ExceptionalSynchrony::EventMachineProxy do
|
|
64
64
|
@em.stop
|
65
65
|
end
|
66
66
|
|
67
|
+
it "should set thread variable :em_synchrony_reactor_thread running to false when stop" do
|
68
|
+
@em.run do
|
69
|
+
assert_equal true, Thread.current.thread_variable_get(:em_synchrony_reactor_thread)
|
70
|
+
@em.stop
|
71
|
+
assert_equal false, Thread.current.thread_variable_get(:em_synchrony_reactor_thread)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
67
75
|
it "should proxy connect" do
|
68
76
|
ServerClass = Class.new
|
69
77
|
mock(EventMachine).connect(ServerClass, 8080, :handler, :extra_arg).yields(:called)
|
@@ -171,6 +179,10 @@ describe ExceptionalSynchrony::EventMachineProxy do
|
|
171
179
|
end
|
172
180
|
|
173
181
|
describe "without error" do
|
182
|
+
before do
|
183
|
+
Thread.current.thread_variable_set(:em_synchrony_reactor_thread, nil)
|
184
|
+
end
|
185
|
+
|
174
186
|
[:log, :raise].each do |on_error|
|
175
187
|
describe "when using #{method} and on_error = #{on_error}" do
|
176
188
|
it "should dispatch to the proxy's synchrony method instead of run iff synchrony" do
|
@@ -178,6 +190,15 @@ describe ExceptionalSynchrony::EventMachineProxy do
|
|
178
190
|
assert_equal method, (@proxy.run(on_error: on_error) { dispatched = true })
|
179
191
|
assert_equal true, dispatched
|
180
192
|
end
|
193
|
+
|
194
|
+
if method == :synchrony
|
195
|
+
it "should set thread variable :em_synchrony_reactor_thread running to true" do
|
196
|
+
assert_nil Thread.current.thread_variable_get(:em_synchrony_reactor_thread)
|
197
|
+
@proxy.run(on_error: on_error) do
|
198
|
+
assert_equal true, Thread.current.thread_variable_get(:em_synchrony_reactor_thread)
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
181
202
|
end
|
182
203
|
end
|
183
204
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: exceptional_synchrony
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0.pre.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Invoca
|
@@ -101,6 +101,7 @@ files:
|
|
101
101
|
- lib/exceptional_synchrony.rb
|
102
102
|
- lib/exceptional_synchrony/callback_exceptions.rb
|
103
103
|
- lib/exceptional_synchrony/event_machine_proxy.rb
|
104
|
+
- lib/exceptional_synchrony/faraday_monkey_patch.rb
|
104
105
|
- lib/exceptional_synchrony/limited_work_queue.rb
|
105
106
|
- lib/exceptional_synchrony/parallel_sync.rb
|
106
107
|
- lib/exceptional_synchrony/version.rb
|