exceptional_synchrony 1.4.0.pre.1 → 1.4.0.pre.2
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 +2 -2
- data/Gemfile.lock +1 -1
- data/lib/exceptional_synchrony/event_machine_proxy.rb +10 -4
- data/lib/exceptional_synchrony/version.rb +1 -1
- data/test/unit/event_machine_proxy_test.rb +17 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7337c98f6e124b7e27327707ad7996bea893fe5c005ae57627e855ec35c77ff4
|
4
|
+
data.tar.gz: 2603dc05990ab4c3f257409382f8fc6453f8e22446a82a1ad9841564b509994e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd0b2894a70161f7162c465aacf315cada6748267d88590bb943d3c68ad382f0ed1b910224738f54b1a1ada219f894b9fd64bcb2f06c7f3b95f0c9b3efb1d218
|
7
|
+
data.tar.gz: b9b7c5fde46b71d32651108b855f4396517e32a73915b1e3bc09e258a5bcee678d3946ca3fc6c768eef1deebc0edaa66e4e41898b3a08a6d95e993c0bc12339e
|
data/CHANGELOG.md
CHANGED
@@ -8,8 +8,8 @@ All notable changes to this project will be documented in this file.
|
|
8
8
|
|
9
9
|
## [1.4.0] - UNRELEASED
|
10
10
|
### Added
|
11
|
-
-
|
12
|
-
|
11
|
+
- Added `:faraday_adapter` option to `EventMachineProxy#run` with a default of `:em_synchrony`
|
12
|
+
so that the reactor does not get blocked when using `Faraday` connections
|
13
13
|
|
14
14
|
## [1.3.0] - 2021-02-04
|
15
15
|
### Added
|
data/Gemfile.lock
CHANGED
@@ -72,11 +72,16 @@ module ExceptionalSynchrony
|
|
72
72
|
@proxy_class.connect(server, port, handler, *args, &block)
|
73
73
|
end
|
74
74
|
|
75
|
+
# This method starts the EventMachine reactor.
|
75
76
|
# The on_error option has these possible values:
|
76
77
|
# :log - log any rescued StandardError exceptions and continue
|
77
78
|
# :raise - raise FatalRunError for any rescued StandardError exceptions
|
78
|
-
|
79
|
-
|
79
|
+
# The faraday_adapter option has these possible values that only apply if Faraday connections are in use:
|
80
|
+
# :em_synchrony - for use when EM::Synchrony is being used in all threads of the given process
|
81
|
+
# :net_http - for use when EM::Synchrony is being used in only some threads of the given process;
|
82
|
+
# in this case requests made over the Faraday connection will block the reactor
|
83
|
+
def run(on_error: :log, faraday_adapter: :em_synchrony, &block)
|
84
|
+
configure_faraday(faraday_adapter)
|
80
85
|
case on_error
|
81
86
|
when :log then run_with_error_logging(&block)
|
82
87
|
when :raise then run_with_error_raising(&block)
|
@@ -134,9 +139,10 @@ module ExceptionalSynchrony
|
|
134
139
|
|
135
140
|
private
|
136
141
|
|
137
|
-
def configure_faraday
|
142
|
+
def configure_faraday(adapter)
|
138
143
|
if defined?(Faraday)
|
139
|
-
|
144
|
+
adapter.in?([:em_synchrony, :net_http]) or raise ArgumentError, "Invalid faraday_adapter: #{adapter.inspect}"
|
145
|
+
Faraday.default_adapter = adapter
|
140
146
|
end
|
141
147
|
end
|
142
148
|
|
@@ -159,7 +159,7 @@ describe ExceptionalSynchrony::EventMachineProxy do
|
|
159
159
|
end
|
160
160
|
|
161
161
|
describe "run with faraday" do
|
162
|
-
|
162
|
+
before do
|
163
163
|
class Faraday
|
164
164
|
class << self
|
165
165
|
attr_reader :default_adapter
|
@@ -172,11 +172,26 @@ describe ExceptionalSynchrony::EventMachineProxy do
|
|
172
172
|
self.default_adapter = :net_http
|
173
173
|
end
|
174
174
|
|
175
|
-
mock(@em).run_with_error_logging
|
176
175
|
assert_equal :net_http, Faraday.default_adapter
|
176
|
+
end
|
177
|
+
|
178
|
+
it "sets Faraday default_adapter to :em_synchrony by default if Faraday is defined" do
|
179
|
+
mock(@em).run_with_error_logging
|
177
180
|
@em.run
|
178
181
|
assert_equal :em_synchrony, Faraday.default_adapter
|
179
182
|
end
|
183
|
+
|
184
|
+
it "sets Faraday default_adapter to :net_http if Faraday is defined" do
|
185
|
+
mock(@em).run_with_error_logging
|
186
|
+
@em.run(faraday_adapter: :net_http)
|
187
|
+
assert_equal :net_http, Faraday.default_adapter
|
188
|
+
end
|
189
|
+
|
190
|
+
it "raise ArgumentError if the specified faraday_adapter is invalid" do
|
191
|
+
assert_raises(ArgumentError, "Invalid faraday_adapter: :bogus") do
|
192
|
+
@em.run(faraday_adapter: :bogus)
|
193
|
+
end
|
194
|
+
end
|
180
195
|
end
|
181
196
|
|
182
197
|
{ synchrony: SynchronyProxyMock, run: RunProxyMock }.each do |method, proxy_mock|
|