exceptional_synchrony 1.3.0.pre.lee.1 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/CHANGELOG.md +11 -8
- data/Gemfile.lock +30 -66
- data/Rakefile +1 -0
- data/exceptional_synchrony.gemspec +1 -1
- data/lib/exceptional_synchrony/event_machine_proxy.rb +18 -16
- data/lib/exceptional_synchrony/version.rb +1 -1
- data/test/unit/event_machine_proxy_test.rb +39 -29
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa270b85777fd65a8aae32439cb7031d28f9204e21fbfc627b7659890f47c966
|
4
|
+
data.tar.gz: fea79c101de02959aefb8596b9635f2ccb24266c6173be354465b764264265ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed1b737065894c49b88eeaad73f202d8e5b512b117fb36d9ea810f993d201a9999635380f0d2632978b59726c85d0682a589748d82d0fb72b9c5e7e7fd0b52c9
|
7
|
+
data.tar.gz: ba46f65a0f74e86806dc40eda128b4b3172219d4c214d0ab697781334d371b7fda9f4f8e1f378d548fc7a053e01d83ea5ea747ea32266fb58ba0c81df4ada212
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.7.5
|
data/CHANGELOG.md
CHANGED
@@ -6,15 +6,13 @@ 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.3.
|
10
|
-
###
|
11
|
-
-
|
12
|
-
the `EventMachine` reactor so that the reactor does not get blocked when using `Faraday`
|
13
|
-
|
14
|
-
## [1.1.1] - 2020-05-03
|
15
|
-
- Replace hobo_support with invoca_utils
|
9
|
+
## [1.3.1] - 2024-03-04
|
10
|
+
### Changed
|
11
|
+
- Updated `exception_handling` dependency to allow usage of version 3.0
|
16
12
|
|
17
|
-
[1.
|
13
|
+
## [1.3.0] - 2021-02-04
|
14
|
+
### Added
|
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.
|
18
16
|
|
19
17
|
## [1.2.0] - 2020-06-02
|
20
18
|
### Changed
|
@@ -27,4 +25,9 @@ All notable changes to this project will be documented in this file.
|
|
27
25
|
We expect that outer edge handler to log the exception chain (the wrapper plus nested `cause` exception(s))
|
28
26
|
and exit the process with a non-0 status code.
|
29
27
|
|
28
|
+
## [1.1.1] - 2020-05-03
|
29
|
+
- Replace hobo_support with invoca_utils
|
30
|
+
|
31
|
+
[1.3.0]: https://github.com/Invoca/exceptional_synchrony/compare/v1.2.0...v1.3.0
|
30
32
|
[1.2.0]: https://github.com/Invoca/exceptional_synchrony/compare/v1.1.1...v1.2.0
|
33
|
+
[1.1.1]: https://github.com/Invoca/exceptional_synchrony/compare/v1.1.0...v1.1.1
|
data/Gemfile.lock
CHANGED
@@ -1,58 +1,42 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
exceptional_synchrony (1.3.
|
4
|
+
exceptional_synchrony (1.3.1)
|
5
5
|
em-http-request
|
6
6
|
em-synchrony
|
7
7
|
eventmachine
|
8
|
-
exception_handling (
|
8
|
+
exception_handling (>= 2.2)
|
9
9
|
invoca-utils (~> 0.3)
|
10
10
|
|
11
11
|
GEM
|
12
12
|
remote: https://rubygems.org/
|
13
13
|
specs:
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
activejob (= 6.1.1)
|
18
|
-
activesupport (= 6.1.1)
|
19
|
-
mail (~> 2.5, >= 2.5.4)
|
20
|
-
rails-dom-testing (~> 2.0)
|
21
|
-
actionpack (6.1.1)
|
22
|
-
actionview (= 6.1.1)
|
23
|
-
activesupport (= 6.1.1)
|
24
|
-
rack (~> 2.0, >= 2.0.9)
|
25
|
-
rack-test (>= 0.6.3)
|
26
|
-
rails-dom-testing (~> 2.0)
|
27
|
-
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
28
|
-
actionview (6.1.1)
|
29
|
-
activesupport (= 6.1.1)
|
30
|
-
builder (~> 3.1)
|
31
|
-
erubi (~> 1.4)
|
32
|
-
rails-dom-testing (~> 2.0)
|
33
|
-
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
34
|
-
activejob (6.1.1)
|
35
|
-
activesupport (= 6.1.1)
|
36
|
-
globalid (>= 0.3.6)
|
37
|
-
activesupport (6.1.1)
|
14
|
+
activesupport (7.1.3.2)
|
15
|
+
base64
|
16
|
+
bigdecimal
|
38
17
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
18
|
+
connection_pool (>= 2.2.5)
|
19
|
+
drb
|
39
20
|
i18n (>= 1.6, < 2)
|
40
21
|
minitest (>= 5.1)
|
22
|
+
mutex_m
|
41
23
|
tzinfo (~> 2.0)
|
42
|
-
zeitwerk (~> 2.3)
|
43
24
|
addressable (2.7.0)
|
44
25
|
public_suffix (>= 2.0.2, < 5.0)
|
45
26
|
ansi (1.5.0)
|
27
|
+
base64 (0.2.0)
|
28
|
+
bigdecimal (3.1.6)
|
46
29
|
builder (3.2.4)
|
47
30
|
coderay (1.1.2)
|
48
|
-
concurrent-ruby (1.
|
49
|
-
|
31
|
+
concurrent-ruby (1.2.3)
|
32
|
+
connection_pool (2.4.1)
|
33
|
+
contextual_logger (1.2.0)
|
50
34
|
activesupport
|
51
35
|
json
|
52
|
-
cookiejar (0.3.
|
36
|
+
cookiejar (0.3.4)
|
53
37
|
crack (0.4.3)
|
54
38
|
safe_yaml (~> 1.0.0)
|
55
|
-
|
39
|
+
drb (2.2.1)
|
56
40
|
em-http-request (1.1.7)
|
57
41
|
addressable (>= 2.3.4)
|
58
42
|
cookiejar (!= 0.3.1)
|
@@ -63,65 +47,45 @@ GEM
|
|
63
47
|
eventmachine (>= 1.0.0.beta.4)
|
64
48
|
em-synchrony (1.0.6)
|
65
49
|
eventmachine (>= 1.0.0.beta.1)
|
66
|
-
|
50
|
+
escalate (0.3.0)
|
67
51
|
eventmachine (1.2.7)
|
68
|
-
exception_handling (
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
contextual_logger (~> 0.7)
|
73
|
-
eventmachine (~> 1.0)
|
52
|
+
exception_handling (3.0.0)
|
53
|
+
activesupport (>= 5.2)
|
54
|
+
contextual_logger (~> 1.0)
|
55
|
+
escalate (~> 0.3)
|
74
56
|
invoca-utils (~> 0.3)
|
75
|
-
|
76
|
-
activesupport (>= 4.2.0)
|
57
|
+
psych (~> 3.0)
|
77
58
|
hashdiff (1.0.1)
|
78
|
-
http_parser.rb (0.
|
79
|
-
i18n (1.
|
59
|
+
http_parser.rb (0.8.0)
|
60
|
+
i18n (1.14.1)
|
80
61
|
concurrent-ruby (~> 1.0)
|
81
|
-
invoca-utils (0.
|
82
|
-
|
83
|
-
|
84
|
-
crass (~> 1.0.2)
|
85
|
-
nokogiri (>= 1.5.9)
|
86
|
-
mail (2.7.1)
|
87
|
-
mini_mime (>= 0.1.1)
|
62
|
+
invoca-utils (0.5.1)
|
63
|
+
activesupport (>= 5.0)
|
64
|
+
json (2.7.1)
|
88
65
|
method_source (1.0.0)
|
89
|
-
mini_mime (1.0.2)
|
90
|
-
mini_portile2 (2.5.0)
|
91
66
|
minitest (5.14.0)
|
92
67
|
minitest-reporters (1.4.2)
|
93
68
|
ansi
|
94
69
|
builder
|
95
70
|
minitest (>= 5.0)
|
96
71
|
ruby-progressbar
|
97
|
-
|
98
|
-
mini_portile2 (~> 2.5.0)
|
99
|
-
racc (~> 1.4)
|
72
|
+
mutex_m (0.2.0)
|
100
73
|
pry (0.13.1)
|
101
74
|
coderay (~> 1.1)
|
102
75
|
method_source (~> 1.0)
|
76
|
+
psych (3.3.4)
|
103
77
|
public_suffix (4.0.4)
|
104
|
-
racc (1.5.2)
|
105
|
-
rack (2.2.3)
|
106
|
-
rack-test (1.1.0)
|
107
|
-
rack (>= 1.0, < 3)
|
108
|
-
rails-dom-testing (2.0.3)
|
109
|
-
activesupport (>= 4.2.0)
|
110
|
-
nokogiri (>= 1.6)
|
111
|
-
rails-html-sanitizer (1.3.0)
|
112
|
-
loofah (~> 2.3)
|
113
78
|
rake (13.0.1)
|
114
79
|
rr (1.2.1)
|
115
80
|
ruby-progressbar (1.10.1)
|
116
81
|
safe_yaml (1.0.5)
|
117
82
|
thor (1.0.1)
|
118
|
-
tzinfo (2.0.
|
83
|
+
tzinfo (2.0.6)
|
119
84
|
concurrent-ruby (~> 1.0)
|
120
85
|
webmock (1.24.6)
|
121
86
|
addressable (>= 2.3.6)
|
122
87
|
crack (>= 0.3.2)
|
123
88
|
hashdiff
|
124
|
-
zeitwerk (2.4.2)
|
125
89
|
|
126
90
|
PLATFORMS
|
127
91
|
ruby
|
@@ -137,4 +101,4 @@ DEPENDENCIES
|
|
137
101
|
webmock (~> 1.24)
|
138
102
|
|
139
103
|
BUNDLED WITH
|
140
|
-
|
104
|
+
2.3.22
|
data/Rakefile
CHANGED
@@ -19,6 +19,6 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.add_dependency 'em-synchrony'
|
20
20
|
spec.add_dependency 'em-http-request'
|
21
21
|
spec.add_dependency 'eventmachine'
|
22
|
-
spec.add_dependency 'exception_handling', '
|
22
|
+
spec.add_dependency 'exception_handling', '>= 2.2'
|
23
23
|
spec.add_dependency 'invoca-utils', '~> 0.3'
|
24
24
|
end
|
@@ -64,6 +64,10 @@ module ExceptionalSynchrony
|
|
64
64
|
@proxy_class.next_tick { } #Fake out EventMachine's epoll mechanism so we don't block until timers fire
|
65
65
|
end
|
66
66
|
|
67
|
+
def defers_finished?
|
68
|
+
@proxy_class.defers_finished?
|
69
|
+
end
|
70
|
+
|
67
71
|
def connect(server, port = nil, handler = nil, *args, &block)
|
68
72
|
@proxy_class.connect(server, port, handler, *args, &block)
|
69
73
|
end
|
@@ -72,7 +76,6 @@ module ExceptionalSynchrony
|
|
72
76
|
# :log - log any rescued StandardError exceptions and continue
|
73
77
|
# :raise - raise FatalRunError for any rescued StandardError exceptions
|
74
78
|
def run(on_error: :log, &block)
|
75
|
-
configure_faraday
|
76
79
|
case on_error
|
77
80
|
when :log then run_with_error_logging(&block)
|
78
81
|
when :raise then run_with_error_raising(&block)
|
@@ -80,16 +83,21 @@ module ExceptionalSynchrony
|
|
80
83
|
end
|
81
84
|
end
|
82
85
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
EventMachine::Synchrony.sync(deferrable)
|
86
|
+
# This method will execute the block on the background thread pool
|
87
|
+
# By default, it will block the caller until the background thread has finished, so that the result can be returned
|
88
|
+
# :wait_for_result - setting this to false will prevent the caller from being blocked by this deferred work
|
89
|
+
def defer(context, wait_for_result: true, &block)
|
90
|
+
if wait_for_result
|
91
|
+
deferrable = EventMachine::DefaultDeferrable.new
|
92
|
+
callback = -> (result) { deferrable.succeed(result) }
|
91
93
|
|
92
|
-
|
94
|
+
EventMachine.defer(nil, callback) { CallbackExceptions.return_exception(&block) }
|
95
|
+
EventMachine::Synchrony.sync(deferrable)
|
96
|
+
CallbackExceptions.map_deferred_result(deferrable)
|
97
|
+
else
|
98
|
+
EventMachine.defer { ExceptionHandling.ensure_completely_safe("defer", &block) }
|
99
|
+
nil
|
100
|
+
end
|
93
101
|
end
|
94
102
|
|
95
103
|
def reactor_running?
|
@@ -125,12 +133,6 @@ module ExceptionalSynchrony
|
|
125
133
|
|
126
134
|
private
|
127
135
|
|
128
|
-
def configure_faraday
|
129
|
-
if defined?(Faraday)
|
130
|
-
Faraday.default_adapter = :em_synchrony
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
136
|
def run_with_error_logging(&block)
|
135
137
|
ensure_completely_safe("run_with_error_logging") do
|
136
138
|
if @proxy_class.respond_to?(:synchrony)
|
@@ -24,6 +24,14 @@ describe ExceptionalSynchrony::EventMachineProxy do
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
+
def stop_em_after_defers_finish!(em)
|
28
|
+
check_finished_counter = 0
|
29
|
+
em.add_periodic_timer(0.1) do
|
30
|
+
(check_finished_counter += 1) > 20 and raise "defer never finished!"
|
31
|
+
em.defers_finished? and em.stop
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
27
35
|
before do
|
28
36
|
@em = ExceptionalSynchrony::EventMachineProxy.new(EventMachine, nil)
|
29
37
|
@yielded_value = nil
|
@@ -78,18 +86,41 @@ describe ExceptionalSynchrony::EventMachineProxy do
|
|
78
86
|
end
|
79
87
|
|
80
88
|
describe "#defer" do
|
81
|
-
|
82
|
-
|
89
|
+
before do
|
90
|
+
logger = Logger.new(STDERR)
|
91
|
+
logger.extend ContextualLogger::LoggerMixin
|
92
|
+
ExceptionHandling.logger = logger
|
93
|
+
end
|
83
94
|
|
95
|
+
it "should output its block's output when it doesn't raise an error, by default" do
|
84
96
|
@em.run do
|
85
97
|
assert_equal 12, @em.defer("#defer success") { 12 }
|
86
98
|
@em.stop
|
87
99
|
end
|
88
100
|
end
|
89
101
|
|
90
|
-
it "should
|
91
|
-
|
102
|
+
it "should not wait for its block to run if option is passed" do
|
103
|
+
@block_ran = false
|
104
|
+
|
105
|
+
@em.run do
|
106
|
+
assert_nil @em.defer("#defer success", wait_for_result: false) { @block_ran = true; 12 }
|
107
|
+
refute @block_ran
|
108
|
+
stop_em_after_defers_finish!(@em)
|
109
|
+
end
|
110
|
+
|
111
|
+
assert @block_ran
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should handle exceptions when not waiting for its block to run" do
|
115
|
+
mock(ExceptionHandling).log_error(is_a(RuntimeError), "defer")
|
116
|
+
|
117
|
+
@em.run do
|
118
|
+
assert_nil @em.defer("#defer success", wait_for_result: false) { raise RuntimeError, "error in defer" }
|
119
|
+
stop_em_after_defers_finish!(@em)
|
120
|
+
end
|
121
|
+
end
|
92
122
|
|
123
|
+
it "should raise an error when its block raises an error" do
|
93
124
|
@em.run do
|
94
125
|
ex = assert_raises(ArgumentError) do
|
95
126
|
@em.defer("#defer raising an error") { raise ArgumentError, "!!!" }
|
@@ -109,45 +140,24 @@ describe ExceptionalSynchrony::EventMachineProxy do
|
|
109
140
|
end
|
110
141
|
|
111
142
|
it "add_timer" do
|
112
|
-
mock(ExceptionHandling).log_error(EXCEPTION, "add_timer"
|
143
|
+
mock(ExceptionHandling).log_error(EXCEPTION, "add_timer")
|
113
144
|
mock(EventMachine::Synchrony).add_timer(10) { |duration, *args| args.first.call }
|
114
145
|
@em.add_timer(10) { raise EXCEPTION }
|
115
146
|
end
|
116
147
|
|
117
148
|
it "add_periodic_timer" do
|
118
|
-
mock(ExceptionHandling).log_error(EXCEPTION, "add_periodic_timer"
|
149
|
+
mock(ExceptionHandling).log_error(EXCEPTION, "add_periodic_timer")
|
119
150
|
mock(EventMachine::Synchrony).add_periodic_timer(10) { |duration, *args| args.first.call }
|
120
151
|
@em.add_periodic_timer(10) { raise EXCEPTION }
|
121
152
|
end
|
122
153
|
|
123
154
|
it "next_tick" do
|
124
|
-
mock(ExceptionHandling).log_error(EXCEPTION, "next_tick"
|
155
|
+
mock(ExceptionHandling).log_error(EXCEPTION, "next_tick")
|
125
156
|
mock(EventMachine::Synchrony).next_tick { |*args| args.first.call }
|
126
157
|
@em.next_tick { raise EXCEPTION }
|
127
158
|
end
|
128
159
|
end
|
129
160
|
|
130
|
-
describe "run with faraday" do
|
131
|
-
it "should conigure Faraday default_adapter to :em_synchrony if Faraday is defined" do
|
132
|
-
class Faraday
|
133
|
-
class << self
|
134
|
-
attr_reader :default_adapter
|
135
|
-
|
136
|
-
def default_adapter=(adapter)
|
137
|
-
@default_adapter = adapter
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
self.default_adapter = :net_http
|
142
|
-
end
|
143
|
-
|
144
|
-
mock(@em).run_with_error_logging
|
145
|
-
assert_equal :net_http, Faraday.default_adapter
|
146
|
-
@em.run
|
147
|
-
assert_equal :em_synchrony, Faraday.default_adapter
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
161
|
{ synchrony: SynchronyProxyMock, run: RunProxyMock }.each do |method, proxy_mock|
|
152
162
|
describe "run" do
|
153
163
|
before do
|
@@ -179,7 +189,7 @@ describe ExceptionalSynchrony::EventMachineProxy do
|
|
179
189
|
|
180
190
|
describe "when using #{method} and on_error = :log" do
|
181
191
|
it "should rescue any exceptions and log them" do
|
182
|
-
mock(ExceptionHandling).log_error(EXCEPTION, "run_with_error_logging"
|
192
|
+
mock(ExceptionHandling).log_error(EXCEPTION, "run_with_error_logging")
|
183
193
|
|
184
194
|
@proxy.run(on_error: :log) { raise EXCEPTION }
|
185
195
|
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.3.
|
4
|
+
version: 1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Invoca
|
@@ -56,14 +56,14 @@ dependencies:
|
|
56
56
|
name: exception_handling
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '2.2'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '2.2'
|
69
69
|
- !ruby/object:Gem::Dependency
|
@@ -126,11 +126,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
126
126
|
version: '0'
|
127
127
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
|
-
- - "
|
129
|
+
- - ">="
|
130
130
|
- !ruby/object:Gem::Version
|
131
|
-
version:
|
131
|
+
version: '0'
|
132
132
|
requirements: []
|
133
|
-
rubygems_version: 3.
|
133
|
+
rubygems_version: 3.1.6
|
134
134
|
signing_key:
|
135
135
|
specification_version: 4
|
136
136
|
summary: Extensions to EventMachine/Synchrony to work well with exceptions
|