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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 23aa4209588ee0dc66a1c96e25d1a524e1191f7d6f46a0acdfae90c04f19bf93
4
- data.tar.gz: 1c40477122edb3b80bdfae312e486ef8a85cf4bac2c9ee78793e6de97bd72b5e
3
+ metadata.gz: 7337c98f6e124b7e27327707ad7996bea893fe5c005ae57627e855ec35c77ff4
4
+ data.tar.gz: 2603dc05990ab4c3f257409382f8fc6453f8e22446a82a1ad9841564b509994e
5
5
  SHA512:
6
- metadata.gz: 3fec9e8a041a72ee6c521d1ffb33eeef2a470c3df92b41dacaf7c57d6aa33fe0e3d2ee85392f68261c6ed00e29c0264f809dee303ba896bfc471682f161f2303
7
- data.tar.gz: 04d48f19f25bcae51e5b97bf318f78c44151b3d3417dac6b536f25f7b2d778736de0b226aa80c540fbd14801c587c2ffd80e0f4c2890c2ef7003f46fb24f5add
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
- - For users of `Faraday` connections, its `default_adapter` is configured to `:em_synchrony` when starting
12
- the `EventMachine` reactor so that the reactor does not get blocked when using `Faraday`
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- exceptional_synchrony (1.4.0.pre.1)
4
+ exceptional_synchrony (1.4.0.pre.2)
5
5
  em-http-request
6
6
  em-synchrony
7
7
  eventmachine
@@ -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
- def run(on_error: :log, &block)
79
- configure_faraday
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
- Faraday.default_adapter = :em_synchrony
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
 
@@ -1,3 +1,3 @@
1
1
  module ExceptionalSynchrony
2
- VERSION = '1.4.0.pre.1'
2
+ VERSION = '1.4.0.pre.2'
3
3
  end
@@ -159,7 +159,7 @@ describe ExceptionalSynchrony::EventMachineProxy do
159
159
  end
160
160
 
161
161
  describe "run with faraday" do
162
- it "should conigure Faraday default_adapter to :em_synchrony if Faraday is defined" do
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|
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.0.pre.1
4
+ version: 1.4.0.pre.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Invoca