abstractivator 0.15.0 → 0.16.0
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 -0
- data/lib/abstractivator/fiber_defer.rb +6 -0
- data/lib/abstractivator/version.rb +1 -1
- data/spec/lib/abstractivator/fiber_defer_spec.rb +33 -5
- data/spec/lib/abstractivator/lazy_spec.rb +2 -2
- data/spec/lib/abstractivator/trees/tree_map_spec.rb +2 -2
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 26f878ae4109bef8680cc85a6b0d903b97778871
|
4
|
+
data.tar.gz: ce8833f063703cdba55a4c7367cc66143f19c622
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d45dc88be70f404b5449d61cc8684bf2b45c2deb2a07503d5586d75a1ab3295b15fde8fc5c2e180a266f1e7602832c82b2e409d94b8270b5b1d1b32445eafc30
|
7
|
+
data.tar.gz: 96b27bef0776b6c25c5ea7bc0c1aff4f0801439e53f866938e6c4e02db8e14efda2f7bc2203352066b75b2c9a17a493d8e6cdd227c7909df702245beb8b30a1b
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.4.1
|
@@ -98,6 +98,12 @@ module Abstractivator
|
|
98
98
|
safe_action = proc do
|
99
99
|
begin
|
100
100
|
[action.call, nil]
|
101
|
+
rescue SignalException => e
|
102
|
+
# The thread has been instructed to shut down, so let it.
|
103
|
+
# Don't pass on the exception to another thread/fiber.
|
104
|
+
# We will assume whatever is shutting down the thread will
|
105
|
+
# also account for the paused fiber on its own.
|
106
|
+
raise
|
101
107
|
rescue Exception => e
|
102
108
|
[nil, e]
|
103
109
|
end
|
@@ -40,7 +40,7 @@ describe Abstractivator::FiberDefer do
|
|
40
40
|
it 'propagates the thread/fiber-local variables into the block' do
|
41
41
|
EM.run do
|
42
42
|
guard = {
|
43
|
-
|
43
|
+
Thread.current[:meaning] => proc { |x| Thread.current[:meaning] = x }
|
44
44
|
}
|
45
45
|
with_fiber_defer(guard) do
|
46
46
|
expect(Thread.current[:meaning]).to eql 42
|
@@ -123,6 +123,34 @@ describe Abstractivator::FiberDefer do
|
|
123
123
|
end
|
124
124
|
end
|
125
125
|
end
|
126
|
+
it 'terminates the worker thread on SignalError' do
|
127
|
+
EM.run do
|
128
|
+
with_fiber_defer do
|
129
|
+
worker_thread = nil
|
130
|
+
f = Fiber.current
|
131
|
+
fiber_defer do
|
132
|
+
worker_thread = Thread.current
|
133
|
+
worker_thread.abort_on_exception = false # don't immediately exit() the main thread when we raise
|
134
|
+
EM.next_tick { f.resume([nil, nil]) } # allow fiber_defer to return when control returns to the event loop on the main thread
|
135
|
+
raise SignalException.new('TERM')
|
136
|
+
end
|
137
|
+
expect { worker_thread.join(1) }.to raise_error SignalException # join raises when Thread#abort_on_exception is false
|
138
|
+
expect(worker_thread.alive?).to be_falsey
|
139
|
+
EM.threadpool.clear # otherwise, EM will try to re-join these during its cleanup, crash, and leave the EM singleton in a bad state for future tests
|
140
|
+
EM.stop
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
it 'does not terminate the worker thread on non-SignalErrors' do
|
145
|
+
EM.run do
|
146
|
+
with_fiber_defer do
|
147
|
+
worker_thread = nil
|
148
|
+
expect{fiber_defer{ worker_thread = Thread.current; raise 'oops' }}.to raise_error 'oops'
|
149
|
+
expect(worker_thread.alive?).to be_truthy
|
150
|
+
EM.stop
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
126
154
|
it 'works with simultaneous deferred actions' do
|
127
155
|
EM.run do
|
128
156
|
log = []
|
@@ -205,15 +233,15 @@ describe Abstractivator::FiberDefer do
|
|
205
233
|
it 'applies the inherited guard and then the local guard upon entering and exiting the block' do
|
206
234
|
EM.run do
|
207
235
|
guard1 = {
|
208
|
-
|
209
|
-
|
236
|
+
Thread.current[:a] => proc {|x| Thread.current[:a] = x},
|
237
|
+
Thread.current[:b] => proc {|x| Thread.current[:b] = x}
|
210
238
|
}
|
211
239
|
with_fiber_defer(guard1) do
|
212
240
|
Thread.current[:b] = 22
|
213
241
|
Thread.current[:c] = 33
|
214
242
|
guard2 = {
|
215
|
-
|
216
|
-
|
243
|
+
Thread.current[:b] => proc {|x| Thread.current[:b] = x},
|
244
|
+
Thread.current[:c] => proc {|x| Thread.current[:c] = x}
|
217
245
|
}
|
218
246
|
fiber_defer(guard2) do
|
219
247
|
expect(Thread.current[:a]).to eql 1
|
@@ -29,7 +29,7 @@ describe Abstractivator::Lazy do
|
|
29
29
|
expect(lazy { 42 } != 42).to be false
|
30
30
|
expect(lazy { 42 } != 99).to be true
|
31
31
|
expect(lazy { 42 } === 42).to be true
|
32
|
-
expect(
|
32
|
+
expect(Integer === lazy { 42 }).to be true
|
33
33
|
expect(Array === lazy { 42 }).to be false
|
34
34
|
expect(!(lazy { true })).to be false
|
35
35
|
expect(!(lazy { false })).to be true
|
@@ -54,7 +54,7 @@ describe Abstractivator::Lazy do
|
|
54
54
|
it 'reveals the value type if the value has already been forced' do
|
55
55
|
value = lazy { 42 }
|
56
56
|
value.to_s
|
57
|
-
expect(value.inspect).to match /#<Abstractivator::Lazy:
|
57
|
+
expect(value.inspect).to match /#<Abstractivator::Lazy:Integer:0x[0-9a-f]+>/
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
@@ -118,7 +118,7 @@ describe Abstractivator::Trees do
|
|
118
118
|
expect(call_count).to eql 2
|
119
119
|
end
|
120
120
|
it 'raises an error is the value is not an array' do
|
121
|
-
expect{transform_one_path({a: 1}, 'a[]') { |x| x }}.to raise_error 'Expected an array but got
|
121
|
+
expect{transform_one_path({a: 1}, 'a[]') { |x| x }}.to raise_error 'Expected an array but got Integer: 1'
|
122
122
|
expect{transform_one_path({a: {b: 1}}, 'a[]') { |x| x }}.to raise_error 'Expected an array but got Hash: {:b=>1}'
|
123
123
|
end
|
124
124
|
end
|
@@ -140,7 +140,7 @@ describe Abstractivator::Trees do
|
|
140
140
|
expect(call_count).to eql 2
|
141
141
|
end
|
142
142
|
it 'raises an error is the value is not a hash' do
|
143
|
-
expect{transform_one_path({a: 1}, 'a{}') { |x| x }}.to raise_error 'Expected a hash but got
|
143
|
+
expect{transform_one_path({a: 1}, 'a{}') { |x| x }}.to raise_error 'Expected a hash but got Integer: 1'
|
144
144
|
expect{transform_one_path({a: [1, 2]}, 'a{}') { |x| x }}.to raise_error 'Expected a hash but got Array: [1, 2]'
|
145
145
|
end
|
146
146
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: abstractivator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.16.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Winton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-04
|
11
|
+
date: 2017-08-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -109,6 +109,7 @@ extra_rdoc_files: []
|
|
109
109
|
files:
|
110
110
|
- ".gitignore"
|
111
111
|
- ".rspec"
|
112
|
+
- ".ruby-version"
|
112
113
|
- CHANGES.md
|
113
114
|
- Gemfile
|
114
115
|
- LICENSE.txt
|
@@ -185,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
185
186
|
version: '0'
|
186
187
|
requirements: []
|
187
188
|
rubyforge_project:
|
188
|
-
rubygems_version: 2.6.
|
189
|
+
rubygems_version: 2.6.12
|
189
190
|
signing_key:
|
190
191
|
specification_version: 4
|
191
192
|
summary: Utilities
|
@@ -212,4 +213,3 @@ test_files:
|
|
212
213
|
- spec/lib/abstractivator/value_map_spec.rb
|
213
214
|
- spec/lib/enumerable_ext_spec.rb
|
214
215
|
- spec/lib/exception_ext_spec.rb
|
215
|
-
has_rdoc:
|