xli-dtr 0.0.5 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +7 -0
- data/README.rdoc +208 -0
- data/Rakefile +54 -63
- data/TODO +7 -16
- data/bin/dtr +26 -20
- data/dtr.gemspec +7 -10
- data/lib/dtr/agent/brain.rb +13 -22
- data/lib/dtr/agent/herald.rb +24 -14
- data/lib/dtr/agent/runner.rb +22 -35
- data/lib/dtr/agent/sync_codebase.rb +1 -1
- data/lib/dtr/agent/sync_logger.rb +38 -8
- data/lib/dtr/agent/test_case.rb +53 -0
- data/lib/dtr/agent/test_unit.rb +3 -5
- data/lib/dtr/agent/worker.rb +29 -32
- data/lib/dtr/agent/working_env_ext.rb +4 -2
- data/lib/dtr/agent.rb +2 -1
- data/lib/dtr/facade.rb +65 -0
- data/lib/dtr/master.rb +3 -3
- data/lib/dtr/monitor.rb +69 -11
- data/lib/dtr/raketasks.rb +91 -19
- data/lib/dtr/shared/adapter.rb +29 -26
- data/lib/dtr/shared/configuration.rb +39 -11
- data/lib/dtr/shared/message_decorator.rb +1 -1
- data/lib/dtr/shared/ruby_ext.rb +1 -25
- data/lib/dtr/shared/service/agent.rb +5 -1
- data/lib/dtr/shared/service/file.rb +1 -1
- data/lib/dtr/shared/service/rinda.rb +11 -3
- data/lib/dtr/shared/service/runner.rb +6 -5
- data/lib/dtr/shared/service/working_env.rb +1 -1
- data/lib/dtr/shared/service.rb +1 -1
- data/lib/dtr/shared/sync_codebase/{codebase.rb → copiable_package.rb} +13 -5
- data/lib/dtr/shared/sync_codebase/master_ext.rb +6 -18
- data/lib/dtr/shared/sync_codebase/package.rb +16 -2
- data/lib/dtr/shared/sync_codebase/sync_service.rb +7 -12
- data/lib/dtr/shared/sync_codebase.rb +2 -2
- data/lib/dtr/shared/sync_logger.rb +6 -14
- data/lib/dtr/shared/utils/cmd.rb +5 -5
- data/lib/dtr/shared/utils/env_store.rb +1 -1
- data/lib/dtr/shared/utils/logger.rb +33 -17
- data/lib/dtr/shared/utils.rb +1 -1
- data/lib/dtr/shared/working_env.rb +2 -2
- data/lib/dtr/shared.rb +1 -1
- data/lib/dtr/test_unit/drb_test_runner.rb +5 -14
- data/lib/dtr/test_unit/injection.rb +1 -2
- data/lib/dtr/test_unit/test_case_injection.rb +13 -13
- data/lib/dtr/test_unit/test_suite_injection.rb +24 -0
- data/lib/dtr/test_unit/testrunnermediator_injection.rb +11 -11
- data/lib/dtr/test_unit/thread_safe_test_result.rb +1 -3
- data/lib/dtr/test_unit/worker_club.rb +7 -7
- data/lib/dtr/test_unit.rb +2 -1
- data/lib/dtr/test_unit_injection.rb +1 -1
- data/lib/dtr.rb +5 -36
- data/test/acceptance/agent_working_env_test.rb +28 -34
- data/test/acceptance/dtr_package_task_test.rb +13 -3
- data/test/acceptance/general_test.rb +139 -83
- data/test/acceptance/raketasks_test.rb +23 -0
- data/test/acceptance/sync_codebase_test.rb +12 -13
- data/test/acceptance/sync_logger_test.rb +12 -21
- data/test/agent_helper.rb +8 -10
- data/test/logger_stub.rb +4 -0
- data/test/test_helper.rb +33 -5
- data/test/unit/adapter_test.rb +58 -16
- data/test/unit/configuration_test.rb +44 -0
- data/test/unit/facade_test.rb +41 -0
- data/test/unit/logger_test.rb +72 -0
- data/test/unit/test_unit_test.rb +0 -21
- data/testdata/Rakefile +1 -5
- data/testdata/hacked_run_method_test_case.rb +15 -0
- data/testdata/raketasks/Rakefile +7 -0
- data/testdata/raketasks/success_test_case.rb +6 -0
- data/testdata/sleep_3_secs_test_case.rb +9 -0
- data/testdata/{should_not_sync_codebase_and_setup_working_dir_when_agent_is_in_same_dir_with_master_process → verify_dir_pwd}/verify_dir_pwd_test_case.rb +1 -1
- metadata +33 -13
- data/README +0 -182
- data/install.rb +0 -88
- /data/testdata/{should_not_sync_codebase_and_setup_working_dir_when_agent_is_in_same_dir_with_master_process → verify_dir_pwd}/Rakefile +0 -0
@@ -5,37 +5,20 @@ include DTR::AgentHelper
|
|
5
5
|
class GeneralTest < Test::Unit::TestCase
|
6
6
|
|
7
7
|
def setup
|
8
|
-
#start_agents first for test files loaded would be copied into sub processes
|
9
8
|
start_agents
|
10
|
-
# put these here for we don't want run them in current process
|
11
|
-
@pwd = Dir.pwd
|
12
|
-
Dir.chdir(File.expand_path(File.dirname(__FILE__) + "/../../testdata/"))
|
13
|
-
require 'a_test_case'
|
14
|
-
require 'a_test_case2'
|
15
|
-
require 'a_failed_test_case'
|
16
|
-
require 'an_error_test_case'
|
17
|
-
require 'a_file_system_test_case'
|
18
|
-
require 'scenario_test_case'
|
19
|
-
require 'setup_agent_env_test_case'
|
20
|
-
|
21
|
-
DTR.inject
|
22
9
|
end
|
23
10
|
|
24
11
|
def teardown
|
25
|
-
DTR.reject
|
26
|
-
Dir.chdir(@pwd)
|
27
12
|
stop_agents
|
28
|
-
$argv_dup = nil
|
29
13
|
end
|
30
14
|
|
31
15
|
def test_run_test_passed
|
32
|
-
$argv_dup = ['a_test_case.rb', 'a_test_case2.rb', 'a_file_system_test_case.rb']
|
33
|
-
suite = Test::Unit::TestSuite.new('run_test_passed')
|
34
|
-
suite << ATestCase.suite
|
35
|
-
suite << ATestCase2.suite
|
36
|
-
suite << AFileSystemTestCase.suite
|
37
|
-
|
38
16
|
assert_fork_process_exits_ok do
|
17
|
+
$argv_dup = ['a_test_case.rb', 'a_test_case2.rb', 'a_file_system_test_case.rb']
|
18
|
+
suite = Test::Unit::TestSuite.new('run_test_passed')
|
19
|
+
suite << ATestCase.suite
|
20
|
+
suite << ATestCase2.suite
|
21
|
+
suite << AFileSystemTestCase.suite
|
39
22
|
@result = runit(suite)
|
40
23
|
|
41
24
|
assert @result.passed?
|
@@ -46,12 +29,11 @@ class GeneralTest < Test::Unit::TestCase
|
|
46
29
|
end
|
47
30
|
|
48
31
|
def test_run_test_failed
|
49
|
-
$argv_dup = ['a_test_case.rb', 'a_failed_test_case.rb']
|
50
|
-
suite = Test::Unit::TestSuite.new('test_run_test_failed')
|
51
|
-
suite << ATestCase.suite
|
52
|
-
suite << AFailedTestCase.suite
|
53
|
-
|
54
32
|
assert_fork_process_exits_ok do
|
33
|
+
$argv_dup = ['a_test_case.rb', 'a_failed_test_case.rb']
|
34
|
+
suite = Test::Unit::TestSuite.new('test_run_test_failed')
|
35
|
+
suite << ATestCase.suite
|
36
|
+
suite << AFailedTestCase.suite
|
55
37
|
@result = runit(suite)
|
56
38
|
|
57
39
|
assert !@result.passed?
|
@@ -62,12 +44,12 @@ class GeneralTest < Test::Unit::TestCase
|
|
62
44
|
end
|
63
45
|
|
64
46
|
def test_run_test_error
|
65
|
-
$argv_dup = ['a_test_case.rb', 'an_error_test_case.rb']
|
66
|
-
suite = Test::Unit::TestSuite.new('test_run_test_error')
|
67
|
-
suite << ATestCase.suite
|
68
|
-
suite << AnErrorTestCase.suite
|
69
|
-
|
70
47
|
assert_fork_process_exits_ok do
|
48
|
+
$argv_dup = ['a_test_case.rb', 'an_error_test_case.rb']
|
49
|
+
suite = Test::Unit::TestSuite.new('test_run_test_error')
|
50
|
+
suite << ATestCase.suite
|
51
|
+
suite << AnErrorTestCase.suite
|
52
|
+
|
71
53
|
@result = runit(suite)
|
72
54
|
|
73
55
|
assert_false @result.passed?
|
@@ -78,11 +60,11 @@ class GeneralTest < Test::Unit::TestCase
|
|
78
60
|
end
|
79
61
|
|
80
62
|
def test_run_suite_should_be_independence
|
81
|
-
$argv_dup = ['an_error_test_case.rb']
|
82
|
-
suite = Test::Unit::TestSuite.new('test_run_suite_should_be_independence 1')
|
83
|
-
suite << AnErrorTestCase.suite
|
84
|
-
|
85
63
|
assert_fork_process_exits_ok do
|
64
|
+
$argv_dup = ['an_error_test_case.rb']
|
65
|
+
suite = Test::Unit::TestSuite.new('test_run_suite_should_be_independence 1')
|
66
|
+
suite << AnErrorTestCase.suite
|
67
|
+
|
86
68
|
@result = runit(suite)
|
87
69
|
|
88
70
|
assert_false @result.passed?
|
@@ -91,11 +73,11 @@ class GeneralTest < Test::Unit::TestCase
|
|
91
73
|
assert_equal 1, @result.error_count
|
92
74
|
end
|
93
75
|
|
94
|
-
$argv_dup = ['a_test_case.rb']
|
95
|
-
suite = Test::Unit::TestSuite.new('test_run_suite_should_be_independence 2')
|
96
|
-
suite << ATestCase.suite
|
97
|
-
|
98
76
|
assert_fork_process_exits_ok do
|
77
|
+
$argv_dup = ['a_test_case.rb']
|
78
|
+
suite = Test::Unit::TestSuite.new('test_run_suite_should_be_independence 2')
|
79
|
+
suite << ATestCase.suite
|
80
|
+
|
99
81
|
@result = runit(suite)
|
100
82
|
|
101
83
|
assert @result.passed?
|
@@ -106,11 +88,11 @@ class GeneralTest < Test::Unit::TestCase
|
|
106
88
|
end
|
107
89
|
|
108
90
|
def test_should_ignore_environment_file_not_exists
|
109
|
-
$argv_dup = ['a_test_case.rb', 'test_file_not_exists.rb']
|
110
|
-
suite = Test::Unit::TestSuite.new('test_run_test_file_not_exist')
|
111
|
-
suite << ATestCase.suite
|
112
|
-
|
113
91
|
assert_fork_process_exits_ok do
|
92
|
+
$argv_dup = ['a_test_case.rb', 'test_file_not_exists.rb']
|
93
|
+
suite = Test::Unit::TestSuite.new('test_run_test_file_not_exist')
|
94
|
+
suite << ATestCase.suite
|
95
|
+
|
114
96
|
@result = runit(suite)
|
115
97
|
|
116
98
|
assert @result.passed?
|
@@ -121,10 +103,10 @@ class GeneralTest < Test::Unit::TestCase
|
|
121
103
|
end
|
122
104
|
|
123
105
|
def test_run_empty_test_suite_and_no_test_files_in_environment
|
124
|
-
$argv_dup = []
|
125
|
-
suite = Test::Unit::TestSuite.new('test_run_without_test_files')
|
126
|
-
|
127
106
|
assert_fork_process_exits_ok do
|
107
|
+
$argv_dup = []
|
108
|
+
suite = Test::Unit::TestSuite.new('test_run_without_test_files')
|
109
|
+
|
128
110
|
@result = runit(suite)
|
129
111
|
|
130
112
|
assert @result.passed?
|
@@ -135,10 +117,10 @@ class GeneralTest < Test::Unit::TestCase
|
|
135
117
|
end
|
136
118
|
|
137
119
|
def test_run_empty_test_suite_should_not_crash_agent
|
138
|
-
$argv_dup = []
|
139
|
-
suite = Test::Unit::TestSuite.new('test_run_empty_test_suite_should_not_crash_agent')
|
140
|
-
|
141
120
|
assert_fork_process_exits_ok do
|
121
|
+
$argv_dup = []
|
122
|
+
suite = Test::Unit::TestSuite.new('test_run_empty_test_suite_should_not_crash_agent')
|
123
|
+
|
142
124
|
@result = runit(suite)
|
143
125
|
|
144
126
|
assert @result.passed?
|
@@ -147,9 +129,11 @@ class GeneralTest < Test::Unit::TestCase
|
|
147
129
|
assert_equal 0, @result.error_count
|
148
130
|
end
|
149
131
|
|
150
|
-
$argv_dup = ['a_test_case.rb']
|
151
|
-
suite << ATestCase.suite
|
152
132
|
assert_fork_process_exits_ok do
|
133
|
+
$argv_dup = ['a_test_case.rb']
|
134
|
+
suite = Test::Unit::TestSuite.new('test_run_empty_test_suite_should_not_crash_agent')
|
135
|
+
suite << ATestCase.suite
|
136
|
+
|
153
137
|
@result = runit(suite)
|
154
138
|
|
155
139
|
assert @result.passed?
|
@@ -160,10 +144,10 @@ class GeneralTest < Test::Unit::TestCase
|
|
160
144
|
end
|
161
145
|
|
162
146
|
def test_run_empty_test_suite_and_test_files_not_exist_in_environment
|
163
|
-
$argv_dup = ['test_file_not_exists.rb']
|
164
|
-
suite = Test::Unit::TestSuite.new('test_run_empty_test_suite_and_test_files_not_exist_in_environment')
|
165
|
-
|
166
147
|
assert_fork_process_exits_ok do
|
148
|
+
$argv_dup = ['test_file_not_exists.rb']
|
149
|
+
suite = Test::Unit::TestSuite.new('test_run_empty_test_suite_and_test_files_not_exist_in_environment')
|
150
|
+
|
167
151
|
@result = runit(suite)
|
168
152
|
|
169
153
|
assert @result.passed?
|
@@ -174,14 +158,14 @@ class GeneralTest < Test::Unit::TestCase
|
|
174
158
|
end
|
175
159
|
|
176
160
|
def test_run_test_specified_by_load_path
|
177
|
-
lib_path = File.expand_path(File.dirname(__FILE__) + '/../../testdata/lib')
|
178
|
-
$LOAD_PATH.unshift lib_path
|
179
|
-
require 'lib_test_case'
|
180
|
-
$argv_dup = ['lib_test_case.rb']
|
181
|
-
suite = Test::Unit::TestSuite.new('test_run_test_specified_by_load_path')
|
182
|
-
suite << LibTestCase.suite
|
183
|
-
|
184
161
|
assert_fork_process_exits_ok do
|
162
|
+
lib_path = File.expand_path(File.dirname(__FILE__) + '/../../testdata/lib')
|
163
|
+
$LOAD_PATH.unshift lib_path
|
164
|
+
require 'lib_test_case'
|
165
|
+
$argv_dup = ['lib_test_case.rb']
|
166
|
+
suite = Test::Unit::TestSuite.new('test_run_test_specified_by_load_path')
|
167
|
+
suite << LibTestCase.suite
|
168
|
+
|
185
169
|
@result = runit(suite)
|
186
170
|
|
187
171
|
assert @result.passed?
|
@@ -189,16 +173,14 @@ class GeneralTest < Test::Unit::TestCase
|
|
189
173
|
assert_equal 0, @result.failure_count
|
190
174
|
assert_equal 0, @result.error_count
|
191
175
|
end
|
192
|
-
ensure
|
193
|
-
$LOAD_PATH.delete lib_path
|
194
176
|
end
|
195
177
|
|
196
178
|
def test_message_of_errors_and_failures_should_include_runner_host_name
|
197
|
-
$argv_dup = ['scenario_test_case.rb']
|
198
|
-
suite = Test::Unit::TestSuite.new('test_should_wrapper_errors_by_dtr_remote_exception')
|
199
|
-
suite << ScenarioTestCase.suite
|
200
|
-
|
201
179
|
assert_fork_process_exits_ok do
|
180
|
+
$argv_dup = ['scenario_test_case.rb']
|
181
|
+
suite = Test::Unit::TestSuite.new('test_should_wrapper_errors_by_dtr_remote_exception')
|
182
|
+
suite << ScenarioTestCase.suite
|
183
|
+
|
202
184
|
@result = runit(suite)
|
203
185
|
|
204
186
|
assert !@result.passed?
|
@@ -216,11 +198,12 @@ class GeneralTest < Test::Unit::TestCase
|
|
216
198
|
end
|
217
199
|
|
218
200
|
def test_setup_agent_env_from_master_process
|
219
|
-
$argv_dup = ['setup_agent_env_test_case.rb']
|
220
|
-
suite = Test::Unit::TestSuite.new('setup_agent_env_from_master_process')
|
221
|
-
suite << SetupAgentEnvTestCase.suite
|
222
|
-
ENV['DTR_AGENT_ENV_SETUP_CMD'] = 'touch /tmp/test_setup_agent_env_from_master_process'
|
223
201
|
assert_fork_process_exits_ok do
|
202
|
+
$argv_dup = ['setup_agent_env_test_case.rb']
|
203
|
+
suite = Test::Unit::TestSuite.new('setup_agent_env_from_master_process')
|
204
|
+
suite << SetupAgentEnvTestCase.suite
|
205
|
+
ENV['DTR_AGENT_ENV_SETUP_CMD'] = 'touch /tmp/test_setup_agent_env_from_master_process'
|
206
|
+
|
224
207
|
@result = runit(suite)
|
225
208
|
assert @result.passed?
|
226
209
|
assert_equal 1, @result.run_count
|
@@ -229,23 +212,25 @@ class GeneralTest < Test::Unit::TestCase
|
|
229
212
|
end
|
230
213
|
ensure
|
231
214
|
File.delete('/tmp/test_setup_agent_env_from_master_process') rescue nil
|
232
|
-
ENV['DTR_AGENT_ENV_SETUP_CMD'] = nil
|
233
215
|
end
|
234
216
|
|
235
217
|
def test_multi_dtr_tasks_should_be_queued_and_processed_one_by_one
|
236
|
-
testdata_dir = File.expand_path(
|
237
|
-
$argv_dup = ['a_test_case.rb', 'a_test_case2.rb', 'a_file_system_test_case.rb']
|
238
|
-
suite = Test::Unit::TestSuite.new('run_test_passed')
|
239
|
-
suite << ATestCase.suite
|
240
|
-
suite << ATestCase2.suite
|
241
|
-
suite << AFileSystemTestCase.suite
|
218
|
+
testdata_dir = File.expand_path(File.dirname(__FILE__) + "/../../testdata/")
|
242
219
|
process_assertion = Proc.new do |master_dir|
|
243
220
|
FileUtils.cp_r testdata_dir, master_dir
|
244
221
|
begin
|
245
222
|
Dir.chdir(master_dir) do
|
246
|
-
|
247
|
-
|
248
|
-
|
223
|
+
$argv_dup = ['a_test_case.rb', 'a_test_case2.rb', 'a_file_system_test_case.rb']
|
224
|
+
setup_test_env
|
225
|
+
suite = Test::Unit::TestSuite.new('run_test_passed')
|
226
|
+
suite << ATestCase.suite
|
227
|
+
suite << ATestCase2.suite
|
228
|
+
suite << AFileSystemTestCase.suite
|
229
|
+
with_agent_helper_group do
|
230
|
+
result = runit(suite)
|
231
|
+
assert result.passed?
|
232
|
+
assert_equal 3, result.run_count
|
233
|
+
end
|
249
234
|
end
|
250
235
|
ensure
|
251
236
|
FileUtils.rm_rf master_dir
|
@@ -269,7 +254,78 @@ class GeneralTest < Test::Unit::TestCase
|
|
269
254
|
assert_equal 0, $?.exitstatus
|
270
255
|
ensure
|
271
256
|
@test_processes.each do |pid|
|
272
|
-
|
257
|
+
DTR.kill_process pid
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
def test_run_test_case_hacked_run_method
|
262
|
+
assert_fork_process_exits_ok do
|
263
|
+
require 'hacked_run_method_test_case'
|
264
|
+
|
265
|
+
$argv_dup = ['hacked_run_method_test_case.rb']
|
266
|
+
suite = Test::Unit::TestSuite.new('run_test_case_hacked_run_method')
|
267
|
+
suite << HackedRunMethodTestCase.suite
|
268
|
+
|
269
|
+
@result = runit(suite)
|
270
|
+
|
271
|
+
assert @result.passed?
|
272
|
+
assert_equal 1, @result.run_count
|
273
|
+
assert_equal 0, @result.failure_count
|
274
|
+
assert_equal 0, @result.error_count
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
def test_should_not_break_heartbeat_of_master_process_when_run_with_a_test_case_sleep_long_time
|
279
|
+
assert_fork_process_exits_ok do
|
280
|
+
DTR.configuration.master_heartbeat_interval = 1
|
281
|
+
DTR.configuration.follower_listen_heartbeat_timeout = 2
|
282
|
+
|
283
|
+
require 'sleep_3_secs_test_case'
|
284
|
+
|
285
|
+
$argv_dup = ['sleep_3_secs_test_case.rb']
|
286
|
+
suite = Test::Unit::TestSuite.new('run_test_case_sleep_3_secs')
|
287
|
+
suite << Sleep3SecsTestCase.suite
|
288
|
+
|
289
|
+
@result = runit(suite)
|
290
|
+
|
291
|
+
assert @result.passed?
|
292
|
+
assert_equal 1, @result.run_count
|
293
|
+
assert_equal 0, @result.failure_count
|
294
|
+
assert_equal 0, @result.error_count
|
295
|
+
end
|
296
|
+
end
|
297
|
+
|
298
|
+
def test_should_add_meaningful_error_when_runner_get_a_unknown_test
|
299
|
+
assert_fork_process_exits_ok do
|
300
|
+
$argv_dup = ['a_failed_test_case.rb']
|
301
|
+
suite = Test::Unit::TestSuite.new('should_add_meaningful_error_when_runner_get_a_unknown_test')
|
302
|
+
suite << ATestCase.suite
|
303
|
+
|
304
|
+
@result = runit(suite)
|
305
|
+
|
306
|
+
assert !@result.passed?
|
307
|
+
assert_equal 1, @result.run_count
|
308
|
+
assert_equal 0, @result.failure_count
|
309
|
+
assert_equal 1, @result.error_count
|
310
|
+
assert_equal "DTR::RemoteError: DTR::Agent::UnknownTestError from #{Socket.gethostname}: No such test loaded: ATestCase", @result.errors.first.message
|
311
|
+
end
|
312
|
+
end
|
313
|
+
|
314
|
+
def test_run_test_timeout
|
315
|
+
assert_fork_process_exits_ok do
|
316
|
+
require 'sleep_3_secs_test_case'
|
317
|
+
$argv_dup = ['sleep_3_secs_test_case.rb']
|
318
|
+
suite = Test::Unit::TestSuite.new('run_test_case_sleep_3_secs')
|
319
|
+
suite << Sleep3SecsTestCase.suite
|
320
|
+
|
321
|
+
ENV['RUN_TEST_TIMEOUT'] = '1'
|
322
|
+
@result = runit(suite)
|
323
|
+
|
324
|
+
assert !@result.passed?
|
325
|
+
assert_equal 1, @result.run_count
|
326
|
+
assert_equal 0, @result.failure_count
|
327
|
+
assert_equal 1, @result.error_count
|
328
|
+
assert @result.errors.first.message.include?('Timeout')
|
273
329
|
end
|
274
330
|
end
|
275
331
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
include DTR::AgentHelper
|
3
|
+
|
4
|
+
class RakeTasksTest < Test::Unit::TestCase
|
5
|
+
def test_test_task
|
6
|
+
FileUtils.mkdir_p("raketasks_test_agent")
|
7
|
+
Dir.chdir('raketasks_test_agent') do
|
8
|
+
start_agents
|
9
|
+
end
|
10
|
+
test_dir = File.expand_path(File.dirname(__FILE__) + '/../../testdata/raketasks')
|
11
|
+
Dir.chdir(test_dir) do
|
12
|
+
output = %x[rake dtr]
|
13
|
+
expected = <<-OUTPUT
|
14
|
+
1 tests, 1 assertions, 0 failures, 0 errors
|
15
|
+
OUTPUT
|
16
|
+
assert_equal 0, $?.exitstatus
|
17
|
+
assert output.include?(expected), "should include #{expected}"
|
18
|
+
end
|
19
|
+
ensure
|
20
|
+
stop_agents
|
21
|
+
FileUtils.rm_rf("raketasks_test_agent")
|
22
|
+
end
|
23
|
+
end
|
@@ -12,7 +12,7 @@ class SyncCodebaseTest < Test::Unit::TestCase
|
|
12
12
|
DTR.configuration.with_rinda_server do
|
13
13
|
Dir.chdir(testdata_dir) do
|
14
14
|
DTR::Cmd.execute('rake dtr_repackage')
|
15
|
-
provide_file DTR::SyncCodebase::
|
15
|
+
provide_file DTR::SyncCodebase::CopiablePackage.new
|
16
16
|
DRb.thread.join
|
17
17
|
end
|
18
18
|
end
|
@@ -31,8 +31,8 @@ class SyncCodebaseTest < Test::Unit::TestCase
|
|
31
31
|
assert !File.exists?("test_sync_codebase/#{package_copy_file}")
|
32
32
|
ensure
|
33
33
|
stop_service rescue nil
|
34
|
-
|
35
|
-
|
34
|
+
DTR.kill_process master
|
35
|
+
DTR.kill_process client
|
36
36
|
FileUtils.rm_rf("test_sync_codebase")
|
37
37
|
Dir.chdir(testdata_dir) do
|
38
38
|
DTR::Cmd.execute('rake dtr_clobber_package')
|
@@ -40,17 +40,17 @@ class SyncCodebaseTest < Test::Unit::TestCase
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def test_should_not_sync_codebase_and_setup_working_dir_when_agent_is_in_same_dir_with_master_process
|
43
|
-
@master_dir = File.expand_path(File.dirname(__FILE__) + '/../../testdata/
|
44
|
-
Dir.chdir(@master_dir) do
|
45
|
-
require 'verify_dir_pwd_test_case'
|
46
|
-
end
|
47
|
-
$argv_dup = ['verify_dir_pwd_test_case.rb']
|
48
|
-
suite = Test::Unit::TestSuite.new('test_should_not_sync_codebase_and_setup_working_dir')
|
49
|
-
suite << VerifyDirPwdTestCase.suite
|
43
|
+
@master_dir = File.expand_path(File.dirname(__FILE__) + '/../../testdata/verify_dir_pwd')
|
50
44
|
@agent = start_agent_at @master_dir, 2, false
|
51
45
|
begin
|
52
|
-
DTR.inject
|
53
46
|
assert_fork_process_exits_ok do
|
47
|
+
Dir.chdir(@master_dir) do
|
48
|
+
require 'verify_dir_pwd_test_case'
|
49
|
+
end
|
50
|
+
$argv_dup = ['verify_dir_pwd_test_case.rb']
|
51
|
+
suite = Test::Unit::TestSuite.new('test_should_not_sync_codebase_and_setup_working_dir')
|
52
|
+
suite << VerifyDirPwdTestCase.suite
|
53
|
+
|
54
54
|
Dir.chdir(@master_dir) do
|
55
55
|
result = runit(suite)
|
56
56
|
assert result.passed?
|
@@ -58,8 +58,7 @@ class SyncCodebaseTest < Test::Unit::TestCase
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
ensure
|
61
|
-
DTR.
|
62
|
-
Process.kill 'TERM', @agent rescue nil
|
61
|
+
DTR.kill_process @agent
|
63
62
|
Process.waitall
|
64
63
|
end
|
65
64
|
end
|
@@ -6,36 +6,27 @@ class SyncLoggerTest < Test::Unit::TestCase
|
|
6
6
|
|
7
7
|
def setup
|
8
8
|
start_agents
|
9
|
-
# put these here for we don't want run them in current process
|
10
|
-
@pwd = Dir.pwd
|
11
|
-
Dir.chdir(File.expand_path(File.dirname(__FILE__) + "/../../testdata/"))
|
12
|
-
require 'a_test_case'
|
13
|
-
@logger = LoggerStub.new
|
14
|
-
DTR.logger = @logger
|
15
|
-
DTR.inject
|
16
9
|
end
|
17
10
|
|
18
11
|
def teardown
|
19
|
-
DTR.reject
|
20
|
-
Dir.chdir(@pwd)
|
21
12
|
stop_agents
|
22
|
-
$argv_dup = nil
|
23
|
-
DTR.logger = nil
|
24
|
-
@logger.clear
|
25
13
|
end
|
26
14
|
|
27
|
-
#todo fix random failure
|
28
15
|
def test_master_process_should_get_log_of_agents
|
29
|
-
$argv_dup = ['a_test_case.rb']
|
30
|
-
suite = Test::Unit::TestSuite.new('test_master_process_should_get_log_of_agents')
|
31
|
-
suite << ATestCase.suite
|
32
16
|
assert_fork_process_exits_ok do
|
17
|
+
@logger = LoggerStub.new
|
18
|
+
DTR.logger = @logger
|
19
|
+
|
20
|
+
$argv_dup = ['a_test_case.rb']
|
21
|
+
suite = Test::Unit::TestSuite.new('master_process_should_get_log_of_agents')
|
22
|
+
suite << ATestCase.suite
|
33
23
|
runit(suite)
|
24
|
+
|
25
|
+
logs = @logger.logs.flatten.join("\n")
|
26
|
+
assert(/From #{Socket.gethostname}: => Herald starts off\.\.\./ =~ logs)
|
27
|
+
assert(/From #{Socket.gethostname}: runner0: test files loaded/ =~ logs)
|
28
|
+
#when use Delegator to implement UndumpedLogger, there are lots of 'nil' in the log
|
29
|
+
assert(/nil/ !~ logs)
|
34
30
|
end
|
35
|
-
logs = @logger.logs.flatten.join("\n")
|
36
|
-
assert(/From #{Socket.gethostname}: => Herald starts off\.\.\./ =~ logs)
|
37
|
-
assert(/From #{Socket.gethostname}: runner0: test files loaded/ =~ logs)
|
38
|
-
#when use Delegator to implement UndumpedLogger, there are lots of 'nil' in the log
|
39
|
-
assert(/nil/ !~ logs)
|
40
31
|
end
|
41
32
|
end
|
data/test/agent_helper.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
require 'fileutils'
|
2
2
|
module DTR
|
3
3
|
module AgentHelper
|
4
|
-
|
4
|
+
GROUP = 'dtr acceptance tests'
|
5
|
+
def start_agents(size = 3)
|
5
6
|
@agents_dir = File.join(Dir.pwd, 'agents')
|
6
7
|
@agents = []
|
7
|
-
@agents << start_agent_at(File.join(@agents_dir, 'agent1'),
|
8
|
+
@agents << start_agent_at(File.join(@agents_dir, 'agent1'), size)
|
8
9
|
# @agents << start_agent_at(File.join(@agents_dir, 'agent2'), 1)
|
9
10
|
end
|
10
11
|
|
@@ -14,13 +15,9 @@ module DTR
|
|
14
15
|
runner_names = []
|
15
16
|
size.times {|i| runner_names << "runner#{i}"}
|
16
17
|
Process.fork do
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
21
|
-
rescue Exception => e
|
22
|
-
puts e.message
|
23
|
-
puts e.backtrace.join("\n")
|
18
|
+
Dir.chdir(agent_dir) do
|
19
|
+
DTR.configuration.group = GROUP
|
20
|
+
DTR.launch_agent(runner_names, nil)
|
24
21
|
end
|
25
22
|
end
|
26
23
|
end
|
@@ -28,9 +25,10 @@ module DTR
|
|
28
25
|
def stop_agents
|
29
26
|
if @agents
|
30
27
|
@agents.each do |agent|
|
31
|
-
|
28
|
+
DTR.kill_process agent
|
32
29
|
end
|
33
30
|
Process.waitall
|
31
|
+
sleep 1
|
34
32
|
end
|
35
33
|
ensure
|
36
34
|
FileUtils.rm_rf(@agents_dir) rescue nil
|
data/test/logger_stub.rb
CHANGED
data/test/test_helper.rb
CHANGED
@@ -4,11 +4,11 @@ require 'test/unit/ui/console/testrunner'
|
|
4
4
|
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
|
5
5
|
|
6
6
|
require 'rubygems'
|
7
|
-
|
7
|
+
require 'growling_test'
|
8
8
|
require 'dtr'
|
9
9
|
require 'dtr/test_unit'
|
10
|
-
|
11
|
-
|
10
|
+
DTR.configuration.master_heartbeat_interval = 2
|
11
|
+
DTR.configuration.follower_listen_heartbeat_timeout = 3
|
12
12
|
|
13
13
|
require File.dirname(__FILE__) + '/agent_helper'
|
14
14
|
require File.dirname(__FILE__) + '/logger_stub'
|
@@ -23,17 +23,45 @@ module Test
|
|
23
23
|
end
|
24
24
|
def assert_fork_process_exits_ok(&block)
|
25
25
|
pid = Process.fork do
|
26
|
-
|
26
|
+
Dir.chdir(File.expand_path(File.dirname(__FILE__) + "/../testdata/")) do
|
27
|
+
setup_test_env
|
28
|
+
with_agent_helper_group(&block)
|
29
|
+
end
|
27
30
|
exit 0
|
28
31
|
end
|
29
32
|
Process.waitpid pid
|
30
33
|
assert_equal 0, $?.exitstatus
|
31
34
|
ensure
|
32
|
-
|
35
|
+
DTR.kill_process pid
|
36
|
+
end
|
37
|
+
|
38
|
+
def with_agent_helper_group(&block)
|
39
|
+
DTR.configuration.group = DTR::AgentHelper::GROUP
|
40
|
+
begin
|
41
|
+
block.call
|
42
|
+
ensure
|
43
|
+
DTR.configuration.group = nil
|
44
|
+
end
|
33
45
|
end
|
46
|
+
|
47
|
+
def setup_test_env
|
48
|
+
require 'a_test_case'
|
49
|
+
require 'a_test_case2'
|
50
|
+
require 'a_failed_test_case'
|
51
|
+
require 'an_error_test_case'
|
52
|
+
require 'a_file_system_test_case'
|
53
|
+
require 'scenario_test_case'
|
54
|
+
require 'setup_agent_env_test_case'
|
55
|
+
DTR.inject
|
56
|
+
end
|
57
|
+
|
34
58
|
def runit(suite)
|
35
59
|
Test::Unit::UI::Console::TestRunner.run(suite, Test::Unit::UI::SILENT)
|
36
60
|
end
|
61
|
+
def clear_configuration
|
62
|
+
DTR::EnvStore.destroy
|
63
|
+
DTR.configuration.load
|
64
|
+
end
|
37
65
|
end
|
38
66
|
end
|
39
67
|
end
|