miga-base 0.6.4.2 → 0.7.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,158 @@
1
+ require 'test_helper'
2
+ require 'miga/common/with_daemon'
3
+
4
+ class WithDaemonTest < Test::Unit::TestCase
5
+
6
+ def setup
7
+ $jruby_tests = !ENV['JRUBY_TESTS'].nil?
8
+ $tmp = Dir.mktmpdir
9
+ end
10
+
11
+ def teardown
12
+ FileUtils.rm_rf $tmp
13
+ end
14
+
15
+ class TestWithDaemon < MiGA::MiGA
16
+ include MiGA::Common::WithDaemon
17
+ extend MiGA::Common::WithDaemonClass
18
+
19
+ attr :daemon_home
20
+
21
+ def daemon_first_loop
22
+ puts 'Hello, Underworld!'
23
+ end
24
+
25
+ def daemon_loop
26
+ puts 'This is one loop'
27
+ sleep(1)
28
+ true
29
+ end
30
+
31
+ def daemon_name
32
+ 'TestDaemon'
33
+ end
34
+
35
+ def initialize(path)
36
+ @daemon_home = path
37
+ end
38
+
39
+ def say(*o)
40
+ puts(*o)
41
+ end
42
+ end
43
+
44
+ class TestWithDaemon2 < TestWithDaemon
45
+ def daemon_loop
46
+ puts 'I am 2.0!'
47
+ sleep(3)
48
+ false
49
+ end
50
+
51
+ def terminate
52
+ FileUtils.touch("#{alive_file}.x")
53
+ end
54
+ end
55
+
56
+ def test_with_daemon
57
+ d = TestWithDaemon.new($tmp)
58
+ assert_respond_to(d, :pid_file)
59
+ assert_respond_to(d.class, :daemon_home)
60
+ assert_nil(d.loop_i)
61
+ end
62
+
63
+ def test_daemon_run
64
+ d = TestWithDaemon2.new($tmp)
65
+ capture_stdout { d.run }
66
+ assert_path_not_exist(d.pid_file)
67
+ end
68
+
69
+ def test_daemmon_status
70
+ d = TestWithDaemon.new($tmp)
71
+ out = capture_stdout { d.status }.string
72
+ assert_match(/Not running/, out)
73
+
74
+ FileUtils.touch(d.output_file)
75
+ capture_stdout { d.start }
76
+ sleep(1)
77
+ out = capture_stdout { d.status }.string
78
+ assert_match(/Running with pid /, out)
79
+
80
+ capture_stdout { d.stop }
81
+ sleep(1)
82
+ out = capture_stdout { d.status }.string
83
+ assert_match(/Not running/, out)
84
+ end
85
+
86
+ def test_daemon_operations
87
+ d = TestWithDaemon.new($tmp)
88
+ FileUtils.touch(d.output_file)
89
+ assert_not_predicate(d, :active?)
90
+
91
+ omit_if($jruby_tests, 'JRuby doesn\'t implement fork.')
92
+ capture_stdout do
93
+ pid = d.start
94
+ assert_gt(pid, 0)
95
+ sleep(1)
96
+ end
97
+ assert_predicate(d, :active?)
98
+
99
+ capture_stdout { d.status }
100
+ assert_predicate(d, :active?)
101
+
102
+ assert_raise { d.declare_alive }
103
+
104
+ assert_predicate(d, :active?)
105
+ out = capture_stdout { d.stop }.string
106
+ assert_match(/Sending termination message/, out)
107
+ assert_nil(d.declare_alive_pid)
108
+ assert_not_predicate(d, :active?)
109
+
110
+ out = capture_stdout { d.stop }.string
111
+ assert_match(/No running instances/, out)
112
+ end
113
+
114
+ def test_termination_file
115
+ d = TestWithDaemon2.new($tmp)
116
+ assert { !d.termination_file?(nil) }
117
+ FileUtils.touch(d.terminate_file)
118
+ err = capture_stdout do
119
+ assert { d.termination_file?(nil) }
120
+ sleep(1)
121
+ assert_path_exist("#{d.alive_file}.x")
122
+ end.string
123
+ assert_match(/Found termination file/, err)
124
+ end
125
+
126
+ def test_process_alive
127
+ d = TestWithDaemon2.new($tmp)
128
+ assert { d.process_alive?(Process.pid) }
129
+ assert { !d.process_alive?(1e9) }
130
+ end
131
+
132
+ def test_declare_alive_loop
133
+ d = TestWithDaemon.new(File.join($tmp, 'nope'))
134
+ assert_equal(:no_home, d.declare_alive_loop)
135
+
136
+ d = TestWithDaemon.new($tmp)
137
+ assert_equal(:no_process_alive, d.declare_alive_loop(1e9))
138
+
139
+ omit_if($jruby_tests, 'JRuby doesn\'t implement fork.')
140
+ FileUtils.touch(d.terminate_file)
141
+ child = fork { sleep(3) }
142
+ capture_stdout do
143
+ assert_equal(:termination_file, d.declare_alive_loop(child))
144
+ end
145
+ end
146
+
147
+ def test_write_alive_file
148
+ d = TestWithDaemon.new(File.join($tmp, 'nope'))
149
+ assert_not_predicate(d, :active?)
150
+ assert_raise { d.write_alive_file }
151
+ assert_not_predicate(d, :active?)
152
+
153
+ d = TestWithDaemon.new($tmp)
154
+ assert_not_predicate(d, :active?)
155
+ d.write_alive_file
156
+ assert_predicate(d, :active?)
157
+ end
158
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: miga-base
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.4.2
4
+ version: 0.7.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luis M. Rodriguez-R
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-15 00:00:00.000000000 Z
11
+ date: 2020-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: daemons
@@ -158,6 +158,8 @@ files:
158
158
  - lib/miga/common/format.rb
159
159
  - lib/miga/common/hooks.rb
160
160
  - lib/miga/common/path.rb
161
+ - lib/miga/common/with_daemon.rb
162
+ - lib/miga/common/with_daemon_class.rb
161
163
  - lib/miga/common/with_result.rb
162
164
  - lib/miga/daemon.rb
163
165
  - lib/miga/daemon/base.rb
@@ -215,6 +217,7 @@ files:
215
217
  - test/format_test.rb
216
218
  - test/hook_test.rb
217
219
  - test/json_test.rb
220
+ - test/lair_test.rb
218
221
  - test/metadata_test.rb
219
222
  - test/project_test.rb
220
223
  - test/remote_dataset_test.rb
@@ -224,6 +227,7 @@ files:
224
227
  - test/tax_index_test.rb
225
228
  - test/taxonomy_test.rb
226
229
  - test/test_helper.rb
230
+ - test/with_daemon_test.rb
227
231
  - utils/adapters.fa
228
232
  - utils/cleanup-databases.rb
229
233
  - utils/core-pan-plot.R
@@ -536,7 +540,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
536
540
  requirements:
537
541
  - - ">="
538
542
  - !ruby/object:Gem::Version
539
- version: '2.1'
543
+ version: '2.3'
540
544
  required_rubygems_version: !ruby/object:Gem::Requirement
541
545
  requirements:
542
546
  - - ">="