service_skeleton 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.git-blame-ignore-revs +2 -0
- data/.github/workflows/ci.yml +16 -0
- data/.rubocop.yml +2 -0
- data/lib/service_skeleton/generator.rb +1 -1
- data/lib/service_skeleton/runner.rb +1 -1
- data/service_skeleton.gemspec +0 -1
- data/ultravisor/.yardopts +1 -0
- data/ultravisor/Guardfile +9 -0
- data/ultravisor/README.md +404 -0
- data/ultravisor/lib/ultravisor.rb +216 -0
- data/ultravisor/lib/ultravisor/child.rb +481 -0
- data/ultravisor/lib/ultravisor/child/call.rb +21 -0
- data/ultravisor/lib/ultravisor/child/call_receiver.rb +14 -0
- data/ultravisor/lib/ultravisor/child/cast.rb +16 -0
- data/ultravisor/lib/ultravisor/child/cast_receiver.rb +11 -0
- data/ultravisor/lib/ultravisor/child/process_cast_call.rb +39 -0
- data/ultravisor/lib/ultravisor/error.rb +25 -0
- data/ultravisor/lib/ultravisor/logging_helpers.rb +32 -0
- data/ultravisor/spec/example_group_methods.rb +19 -0
- data/ultravisor/spec/example_methods.rb +8 -0
- data/ultravisor/spec/spec_helper.rb +52 -0
- data/ultravisor/spec/ultravisor/add_child_spec.rb +79 -0
- data/ultravisor/spec/ultravisor/child/call_spec.rb +121 -0
- data/ultravisor/spec/ultravisor/child/cast_spec.rb +111 -0
- data/ultravisor/spec/ultravisor/child/id_spec.rb +21 -0
- data/ultravisor/spec/ultravisor/child/new_spec.rb +152 -0
- data/ultravisor/spec/ultravisor/child/restart_delay_spec.rb +40 -0
- data/ultravisor/spec/ultravisor/child/restart_spec.rb +70 -0
- data/ultravisor/spec/ultravisor/child/run_spec.rb +95 -0
- data/ultravisor/spec/ultravisor/child/shutdown_spec.rb +124 -0
- data/ultravisor/spec/ultravisor/child/spawn_spec.rb +107 -0
- data/ultravisor/spec/ultravisor/child/unsafe_instance_spec.rb +55 -0
- data/ultravisor/spec/ultravisor/child/wait_spec.rb +32 -0
- data/ultravisor/spec/ultravisor/new_spec.rb +71 -0
- data/ultravisor/spec/ultravisor/remove_child_spec.rb +49 -0
- data/ultravisor/spec/ultravisor/run_spec.rb +334 -0
- data/ultravisor/spec/ultravisor/shutdown_spec.rb +106 -0
- metadata +34 -16
@@ -0,0 +1,106 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative "../spec_helper"
|
3
|
+
|
4
|
+
require_relative "../../lib/ultravisor"
|
5
|
+
|
6
|
+
describe Ultravisor do
|
7
|
+
let(:args) { {} }
|
8
|
+
let(:ultravisor) { Ultravisor.new(**args) }
|
9
|
+
let(:mock_thread) { instance_double(Thread) }
|
10
|
+
|
11
|
+
describe "#shutdown" do
|
12
|
+
it "takes the @op_m lock" do
|
13
|
+
expect(ultravisor.instance_variable_get(:@op_m)).to receive(:synchronize).and_call_original
|
14
|
+
|
15
|
+
ultravisor.shutdown
|
16
|
+
end
|
17
|
+
|
18
|
+
context "when the ultravisor isn't running" do
|
19
|
+
it "returns itself" do
|
20
|
+
expect(ultravisor.shutdown).to eq(ultravisor)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "when the ultravisor is running" do
|
25
|
+
before(:each) do
|
26
|
+
ultravisor.instance_variable_set(:@running_thread, mock_thread)
|
27
|
+
allow(ultravisor.instance_variable_get(:@op_cv))
|
28
|
+
.to receive(:wait) do
|
29
|
+
ultravisor.instance_variable_set(:@running_thread, nil)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
it "signals the ultravisor to shutdown" do
|
34
|
+
expect(ultravisor.instance_variable_get(:@queue)).to receive(:<<).with(:shutdown)
|
35
|
+
|
36
|
+
ultravisor.shutdown
|
37
|
+
end
|
38
|
+
|
39
|
+
it "waits until the CV is signalled" do
|
40
|
+
expect(ultravisor.instance_variable_get(:@op_cv)).to receive(:wait) do |m|
|
41
|
+
expect(m).to eq(ultravisor.instance_variable_get(:@op_m))
|
42
|
+
ultravisor.instance_variable_set(:@running_thread, nil)
|
43
|
+
nil
|
44
|
+
end
|
45
|
+
|
46
|
+
ultravisor.shutdown
|
47
|
+
end
|
48
|
+
|
49
|
+
context "when asked to not wait" do
|
50
|
+
it "doesn't wait on the CV" do
|
51
|
+
expect(ultravisor.instance_variable_get(:@op_cv)).to_not receive(:wait)
|
52
|
+
|
53
|
+
ultravisor.shutdown(wait: false)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
it "returns itself" do
|
58
|
+
expect(ultravisor.shutdown).to eq(ultravisor)
|
59
|
+
end
|
60
|
+
|
61
|
+
context "when forced" do
|
62
|
+
before(:each) do
|
63
|
+
allow(mock_thread).to receive(:kill)
|
64
|
+
end
|
65
|
+
|
66
|
+
it "kills the thread" do
|
67
|
+
expect(mock_thread).to receive(:kill)
|
68
|
+
|
69
|
+
ultravisor.shutdown(force: true)
|
70
|
+
end
|
71
|
+
|
72
|
+
it "tells everyone waiting for the shutdown that the deed is done" do
|
73
|
+
expect(ultravisor.instance_variable_get(:@op_cv)).to receive(:broadcast)
|
74
|
+
|
75
|
+
ultravisor.shutdown(force: true)
|
76
|
+
end
|
77
|
+
|
78
|
+
it "unsets the running thread" do
|
79
|
+
ultravisor.shutdown(force: true)
|
80
|
+
|
81
|
+
expect(ultravisor.instance_variable_get(:@running_thread)).to be(nil)
|
82
|
+
end
|
83
|
+
|
84
|
+
it "doesn't wait on the CV" do
|
85
|
+
expect(ultravisor.instance_variable_get(:@op_cv)).to_not receive(:wait)
|
86
|
+
|
87
|
+
ultravisor.shutdown(force: true)
|
88
|
+
end
|
89
|
+
|
90
|
+
context "with children" do
|
91
|
+
let(:child) { Ultravisor::Child.new(id: :one, klass: Object, method: :to_s) }
|
92
|
+
|
93
|
+
before(:each) do
|
94
|
+
ultravisor.instance_variable_set(:@children, [[:child, child]])
|
95
|
+
end
|
96
|
+
|
97
|
+
it "forcibly shuts down the children" do
|
98
|
+
expect(child).to receive(:shutdown).with(force: true)
|
99
|
+
|
100
|
+
ultravisor.shutdown(force: true)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: service_skeleton
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Palmer
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-01
|
12
|
+
date: 2021-02-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: frankenstein
|
@@ -87,20 +87,6 @@ dependencies:
|
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0.2'
|
90
|
-
- !ruby/object:Gem::Dependency
|
91
|
-
name: ultravisor
|
92
|
-
requirement: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - "~>"
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: 0.a
|
97
|
-
type: :runtime
|
98
|
-
prerelease: false
|
99
|
-
version_requirements: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - "~>"
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: 0.a
|
104
90
|
- !ruby/object:Gem::Dependency
|
105
91
|
name: bundler
|
106
92
|
requirement: !ruby/object:Gem::Requirement
|
@@ -297,6 +283,7 @@ extensions: []
|
|
297
283
|
extra_rdoc_files: []
|
298
284
|
files:
|
299
285
|
- ".editorconfig"
|
286
|
+
- ".git-blame-ignore-revs"
|
300
287
|
- ".github/workflows/ci.yml"
|
301
288
|
- ".gitignore"
|
302
289
|
- ".rubocop.yml"
|
@@ -332,6 +319,37 @@ files:
|
|
332
319
|
- lib/service_skeleton/ultravisor_children.rb
|
333
320
|
- lib/service_skeleton/ultravisor_loggerstash.rb
|
334
321
|
- service_skeleton.gemspec
|
322
|
+
- ultravisor/.yardopts
|
323
|
+
- ultravisor/Guardfile
|
324
|
+
- ultravisor/README.md
|
325
|
+
- ultravisor/lib/ultravisor.rb
|
326
|
+
- ultravisor/lib/ultravisor/child.rb
|
327
|
+
- ultravisor/lib/ultravisor/child/call.rb
|
328
|
+
- ultravisor/lib/ultravisor/child/call_receiver.rb
|
329
|
+
- ultravisor/lib/ultravisor/child/cast.rb
|
330
|
+
- ultravisor/lib/ultravisor/child/cast_receiver.rb
|
331
|
+
- ultravisor/lib/ultravisor/child/process_cast_call.rb
|
332
|
+
- ultravisor/lib/ultravisor/error.rb
|
333
|
+
- ultravisor/lib/ultravisor/logging_helpers.rb
|
334
|
+
- ultravisor/spec/example_group_methods.rb
|
335
|
+
- ultravisor/spec/example_methods.rb
|
336
|
+
- ultravisor/spec/spec_helper.rb
|
337
|
+
- ultravisor/spec/ultravisor/add_child_spec.rb
|
338
|
+
- ultravisor/spec/ultravisor/child/call_spec.rb
|
339
|
+
- ultravisor/spec/ultravisor/child/cast_spec.rb
|
340
|
+
- ultravisor/spec/ultravisor/child/id_spec.rb
|
341
|
+
- ultravisor/spec/ultravisor/child/new_spec.rb
|
342
|
+
- ultravisor/spec/ultravisor/child/restart_delay_spec.rb
|
343
|
+
- ultravisor/spec/ultravisor/child/restart_spec.rb
|
344
|
+
- ultravisor/spec/ultravisor/child/run_spec.rb
|
345
|
+
- ultravisor/spec/ultravisor/child/shutdown_spec.rb
|
346
|
+
- ultravisor/spec/ultravisor/child/spawn_spec.rb
|
347
|
+
- ultravisor/spec/ultravisor/child/unsafe_instance_spec.rb
|
348
|
+
- ultravisor/spec/ultravisor/child/wait_spec.rb
|
349
|
+
- ultravisor/spec/ultravisor/new_spec.rb
|
350
|
+
- ultravisor/spec/ultravisor/remove_child_spec.rb
|
351
|
+
- ultravisor/spec/ultravisor/run_spec.rb
|
352
|
+
- ultravisor/spec/ultravisor/shutdown_spec.rb
|
335
353
|
homepage: https://github.com/discourse/service_skeleton
|
336
354
|
licenses: []
|
337
355
|
metadata: {}
|