xli-dtr 0.0.5 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2007-2008 Li Xiao
|
1
|
+
# Copyright (c) 2007-2008 Li Xiao <iam@li-xiao.com>
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -13,6 +13,6 @@
|
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
15
|
require 'dtr/shared/sync_codebase/package'
|
16
|
-
require 'dtr/shared/sync_codebase/
|
16
|
+
require 'dtr/shared/sync_codebase/copiable_package'
|
17
17
|
require 'dtr/shared/sync_codebase/sync_service'
|
18
18
|
require 'dtr/shared/sync_codebase/master_ext'
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2007-2008 Li Xiao
|
1
|
+
# Copyright (c) 2007-2008 Li Xiao <iam@li-xiao.com>
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -18,22 +18,21 @@ module DTR
|
|
18
18
|
module SyncLogger
|
19
19
|
class UndumpedLogger
|
20
20
|
include DRbUndumped
|
21
|
-
include MessageDecorator
|
22
21
|
|
23
22
|
def initialize(logger)
|
24
23
|
@logger = logger
|
25
24
|
end
|
26
25
|
|
27
26
|
def debug(message=nil, &block)
|
28
|
-
|
27
|
+
@logger.send(:debug, message, &block)
|
29
28
|
end
|
30
29
|
|
31
30
|
def info(message=nil, &block)
|
32
|
-
|
31
|
+
@logger.send(:info, message, &block)
|
33
32
|
end
|
34
33
|
|
35
34
|
def error(message=nil, &block)
|
36
|
-
|
35
|
+
@logger.send(:error, message, &block)
|
37
36
|
end
|
38
37
|
|
39
38
|
def datetime_format=(format)
|
@@ -44,15 +43,8 @@ module DTR
|
|
44
43
|
@logger.level = level
|
45
44
|
end
|
46
45
|
|
47
|
-
|
48
|
-
|
49
|
-
if block_given?
|
50
|
-
@logger.send(level) do
|
51
|
-
decorate_message(block.call)
|
52
|
-
end
|
53
|
-
else
|
54
|
-
@logger.send(level, decorate_message(msg))
|
55
|
-
end
|
46
|
+
def level
|
47
|
+
@logger.level
|
56
48
|
end
|
57
49
|
end
|
58
50
|
|
data/lib/dtr/shared/utils/cmd.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2007-2008 Li Xiao
|
1
|
+
# Copyright (c) 2007-2008 Li Xiao <iam@li-xiao.com>
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -18,12 +18,12 @@ module DTR
|
|
18
18
|
class Cmd
|
19
19
|
def self.execute(cmd)
|
20
20
|
return true if cmd.nil? || cmd.empty?
|
21
|
-
DTR.info "Executing: #{cmd.inspect}"
|
21
|
+
DTR.info {"Executing: #{cmd.inspect}"}
|
22
22
|
output = %x[#{cmd} 2>&1]
|
23
23
|
# don't put the following message into a block which maybe passed to remote process
|
24
|
-
|
25
|
-
DTR.info "Execution is done, status: #{
|
26
|
-
DTR.error "#{cmd.inspect} output:\n#{output}" if
|
24
|
+
status = $?.exitstatus
|
25
|
+
DTR.info {"Execution is done, status: #{status}"}
|
26
|
+
DTR.error "#{cmd.inspect} output:\n#{output}" if status != 0
|
27
27
|
$?.exitstatus == 0
|
28
28
|
end
|
29
29
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2007-2008 Li Xiao
|
1
|
+
# Copyright (c) 2007-2008 Li Xiao <iam@li-xiao.com>
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -13,9 +13,26 @@
|
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
15
|
require 'logger'
|
16
|
+
require 'fileutils'
|
16
17
|
|
17
18
|
module DTR
|
18
19
|
module LoggerExt
|
20
|
+
DATETIME_FORMAT = "%m-%d %H:%M:%S"
|
21
|
+
|
22
|
+
LOGGER_LEVEL = {:info => Logger::INFO, :error => Logger::ERROR, :debug => Logger::DEBUG}
|
23
|
+
|
24
|
+
module OutputErrorIntoConsole
|
25
|
+
def self.included(base)
|
26
|
+
base.alias_method_chain :error, :output_into_console
|
27
|
+
end
|
28
|
+
|
29
|
+
def error_with_output_into_console(message = nil, &block)
|
30
|
+
$stderr.puts "\n" + format_message(format_severity(Logger::ERROR), Time.now, nil, message || block.call)
|
31
|
+
error_without_output_into_console(message, &block)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
Logger.send(:include, OutputErrorIntoConsole)
|
35
|
+
|
19
36
|
def logger(file=nil)
|
20
37
|
@logger ||= create_default_logger(file)
|
21
38
|
end
|
@@ -24,12 +41,13 @@ module DTR
|
|
24
41
|
@logger = logger
|
25
42
|
end
|
26
43
|
|
27
|
-
def create_default_logger(file
|
28
|
-
dir =
|
29
|
-
|
30
|
-
|
44
|
+
def create_default_logger(file)
|
45
|
+
dir = 'log'
|
46
|
+
FileUtils.mkdir_p(dir)
|
47
|
+
log_file = File.join(dir, file || 'dtr.log')
|
48
|
+
do_println "DTR logfile at #{Dir.pwd}/#{log_file}"
|
31
49
|
logger = Logger.new(log_file, 1, 5*1024*1024)
|
32
|
-
logger.datetime_format =
|
50
|
+
logger.datetime_format = DATETIME_FORMAT
|
33
51
|
logger.level = (ENV['DTR_LOG_LEVEL'] || Logger::INFO).to_i
|
34
52
|
logger
|
35
53
|
end
|
@@ -40,6 +58,10 @@ module DTR
|
|
40
58
|
end
|
41
59
|
end
|
42
60
|
|
61
|
+
def do_println(str)
|
62
|
+
do_print("#{str}\n")
|
63
|
+
end
|
64
|
+
|
43
65
|
def debug(message=nil, &block)
|
44
66
|
output(:debug, message, &block)
|
45
67
|
end
|
@@ -53,17 +75,11 @@ module DTR
|
|
53
75
|
end
|
54
76
|
|
55
77
|
def output(level, msg=nil, &block)
|
56
|
-
logger.
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
if level == :error
|
62
|
-
$stderr.puts ''
|
63
|
-
$stderr.puts "#{Time.now}: #{message}"
|
64
|
-
end
|
65
|
-
message
|
66
|
-
end
|
78
|
+
return if LOGGER_LEVEL[level] < logger.level
|
79
|
+
|
80
|
+
msg = block.call if block_given?
|
81
|
+
# puts "log: #{msg}"
|
82
|
+
logger.send(level, msg)
|
67
83
|
end
|
68
84
|
end
|
69
85
|
|
data/lib/dtr/shared/utils.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2007-2008 Li Xiao
|
1
|
+
# Copyright (c) 2007-2008 Li Xiao <iam@li-xiao.com>
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -15,7 +15,7 @@
|
|
15
15
|
module DTR
|
16
16
|
class WorkingEnv
|
17
17
|
def initialize
|
18
|
-
files = (defined?($argv_dup) ? $argv_dup : []).dup
|
18
|
+
files = (defined?($argv_dup) && $argv_dup ? $argv_dup : []).dup
|
19
19
|
@env = {:libs => $LOAD_PATH.dup, :files => files, :created_at => Time.now.to_s, :dtr_master_env => ENV['DTR_MASTER_ENV'], :agent_env_setup_cmd => ENV['DTR_AGENT_ENV_SETUP_CMD'], :identifier => "#{Time.now.to_s}:#{rand}:#{object_id}", :host => Socket.gethostname, :pwd => Dir.pwd}
|
20
20
|
end
|
21
21
|
|
data/lib/dtr/shared.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2007-2008 Li Xiao
|
1
|
+
# Copyright (c) 2007-2008 Li Xiao <iam@li-xiao.com>
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -12,8 +12,6 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
-
require 'timeout'
|
16
|
-
|
17
15
|
module DTR
|
18
16
|
module TestUnit
|
19
17
|
class DRbTestRunner
|
@@ -33,18 +31,11 @@ module DTR
|
|
33
31
|
end
|
34
32
|
end
|
35
33
|
|
36
|
-
def run_test_on(runner
|
37
|
-
|
38
|
-
runner.run(@test, @result, &@progress_block)
|
39
|
-
end
|
40
|
-
rescue Timeout::Error => e
|
41
|
-
DTR.info {"Run test timeout(#{timeout}), reboot runner"}
|
42
|
-
runner.reboot rescue nil
|
43
|
-
DTR.info {"rerun test: #{@test.name}"}
|
44
|
-
self.run
|
34
|
+
def run_test_on(runner)
|
35
|
+
runner.run(@test, @result, &@progress_block)
|
45
36
|
rescue DRb::DRbConnError => e
|
46
|
-
DTR.info {"
|
47
|
-
DTR.debug {
|
37
|
+
DTR.info {"#{cause.class.name}(#{cause.message}), rerun test: #{@test.name}"}
|
38
|
+
DTR.debug { cause.backtrace.join("\n") }
|
48
39
|
self.run
|
49
40
|
rescue Exception => e
|
50
41
|
DTR.info{ "#{@test.name}, rescue an exception: #{e.message}, add error into result." }
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2007-2008 Li Xiao
|
1
|
+
# Copyright (c) 2007-2008 Li Xiao <iam@li-xiao.com>
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -12,7 +12,6 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
-
require 'test/unit/testcase'
|
16
15
|
require 'test/unit/ui/testrunnermediator'
|
17
16
|
|
18
17
|
module DTR
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2007-2008 Li Xiao
|
1
|
+
# Copyright (c) 2007-2008 Li Xiao <iam@li-xiao.com>
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -15,22 +15,22 @@
|
|
15
15
|
module DTR
|
16
16
|
module TestUnit
|
17
17
|
module TestCaseInjection
|
18
|
+
class Proxy
|
19
|
+
def initialize(test)
|
20
|
+
@test = test
|
21
|
+
end
|
22
|
+
|
23
|
+
def run(result, &progress_block)
|
24
|
+
DRbTestRunner.new(@test, result, &progress_block).run
|
25
|
+
end
|
18
26
|
|
19
|
-
|
20
|
-
|
21
|
-
#have to use class_eval for adding it back after removed reject_dtr method
|
22
|
-
base.class_eval do
|
23
|
-
def self.reject_dtr
|
24
|
-
remove_method :run
|
25
|
-
alias_method :run, :run_without_dtr_injection
|
26
|
-
remove_method :run_without_dtr_injection
|
27
|
-
(class << self; self; end;).send :remove_method, :reject_dtr
|
28
|
-
end
|
27
|
+
def size
|
28
|
+
@test.size
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
def
|
33
|
-
|
32
|
+
def proxy
|
33
|
+
Proxy.new(self)
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# Copyright (c) 2007-2008 Li Xiao <iam@li-xiao.com>
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
module DTR
|
16
|
+
module TestUnit
|
17
|
+
module TestSuiteInjection
|
18
|
+
def proxy
|
19
|
+
@tests.collect! {|t| t.proxy}
|
20
|
+
self
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2007-2008 Li Xiao
|
1
|
+
# Copyright (c) 2007-2008 Li Xiao <iam@li-xiao.com>
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -12,18 +12,22 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
+
require 'test/unit/testcase'
|
16
|
+
require 'test/unit/testsuite'
|
17
|
+
|
15
18
|
module DTR
|
16
19
|
module TestUnit
|
17
20
|
module TestRunnerMediatorInjection
|
18
|
-
|
19
21
|
class SuiteWrapper
|
20
22
|
def initialize(suite)
|
21
23
|
@suite = suite
|
22
24
|
end
|
25
|
+
|
23
26
|
def run(result, &block)
|
24
27
|
@suite.run(result, &block)
|
25
28
|
WorkerClub.instance.graceful_shutdown
|
26
29
|
end
|
30
|
+
|
27
31
|
def size
|
28
32
|
@suite.size
|
29
33
|
end
|
@@ -55,16 +59,12 @@ module DTR
|
|
55
59
|
|
56
60
|
def run_suite_with_dtr_injection
|
57
61
|
DTR.logger('dtr_master_process.log')
|
58
|
-
|
62
|
+
# inject testcase&testsuite as late as possible, for it's too easy to be hacked in ruby world
|
63
|
+
Test::Unit::TestCase.send(:include, TestUnit::TestCaseInjection)
|
64
|
+
Test::Unit::TestSuite.send(:include, TestUnit::TestSuiteInjection)
|
65
|
+
@suite = SuiteWrapper.new(@suite.proxy)
|
59
66
|
with_dtr_master do
|
60
|
-
|
61
|
-
# DTR should be the last one to add dtr injection chain into run method
|
62
|
-
Test::Unit::TestCase.send(:include, TestUnit::TestCaseInjection)
|
63
|
-
begin
|
64
|
-
run_suite_without_dtr_injection
|
65
|
-
ensure
|
66
|
-
Test::Unit::TestCase.reject_dtr
|
67
|
-
end
|
67
|
+
run_suite_without_dtr_injection
|
68
68
|
end
|
69
69
|
end
|
70
70
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2007-2008 Li Xiao
|
1
|
+
# Copyright (c) 2007-2008 Li Xiao <iam@li-xiao.com>
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -12,8 +12,6 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
-
require 'drb'
|
16
|
-
|
17
15
|
module DTR
|
18
16
|
module TestUnit
|
19
17
|
class ThreadSafeTestResult
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2007-2008 Li Xiao
|
1
|
+
# Copyright (c) 2007-2008 Li Xiao <iam@li-xiao.com>
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -23,7 +23,7 @@ module DTR
|
|
23
23
|
|
24
24
|
def start_thread(drb_runner, remote_runner)
|
25
25
|
thread = Thread.new(drb_runner, remote_runner) do |local, remote|
|
26
|
-
local.run_test_on(remote
|
26
|
+
local.run_test_on(remote)
|
27
27
|
end
|
28
28
|
thread[:started_on] = Time.now
|
29
29
|
workers.add(thread)
|
@@ -33,16 +33,16 @@ module DTR
|
|
33
33
|
# too long. It waits by ENV['RUN_TEST_TIMEOUT'] || 60 seconds
|
34
34
|
def graceful_shutdown
|
35
35
|
while reap_dead_workers("shutdown") > 0
|
36
|
-
DTR.info "Waiting for #{workers.list.length} threads to finish, could take #{timeout} seconds."
|
36
|
+
DTR.info {"Waiting for #{workers.list.length} threads to finish, could take #{timeout} seconds."}
|
37
37
|
sleep timeout / 60
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
+
private
|
41
42
|
def timeout
|
42
|
-
ENV['RUN_TEST_TIMEOUT'] || DEFAULT_RUN_TEST_TIMEOUT
|
43
|
+
(ENV['RUN_TEST_TIMEOUT'] || DEFAULT_RUN_TEST_TIMEOUT).to_i
|
43
44
|
end
|
44
45
|
|
45
|
-
private
|
46
46
|
def workers
|
47
47
|
@workers ||= ThreadGroup.new
|
48
48
|
end
|
@@ -52,14 +52,14 @@ module DTR
|
|
52
52
|
# after the reap is done. It only runs if there are workers to reap.
|
53
53
|
def reap_dead_workers(reason='unknown')
|
54
54
|
if workers.list.length > 0
|
55
|
-
DTR.info "Reaping #{workers.list.length} threads because of '#{reason}'"
|
55
|
+
DTR.info {"Reaping #{workers.list.length} threads because of '#{reason}'"}
|
56
56
|
error_msg = "#{Time.now}: WorkerClub timed out this thread: #{reason}"
|
57
57
|
mark = Time.now
|
58
58
|
workers.list.each do |worker|
|
59
59
|
worker[:started_on] = Time.now if not worker[:started_on]
|
60
60
|
|
61
61
|
if mark - worker[:started_on] > timeout
|
62
|
-
DTR.info "Thread #{worker.inspect} is too old, killing."
|
62
|
+
DTR.info {"Thread #{worker.inspect} is too old, killing."}
|
63
63
|
worker.raise(TimeoutError.new(error_msg))
|
64
64
|
end
|
65
65
|
end
|
data/lib/dtr/test_unit.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2007-2008 Li Xiao
|
1
|
+
# Copyright (c) 2007-2008 Li Xiao <iam@li-xiao.com>
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -18,5 +18,6 @@ require 'dtr/test_unit/worker_club'
|
|
18
18
|
require 'dtr/test_unit/thread_safe_test_result'
|
19
19
|
require 'dtr/test_unit/drb_test_runner'
|
20
20
|
require 'dtr/test_unit/test_case_injection'
|
21
|
+
require 'dtr/test_unit/test_suite_injection'
|
21
22
|
require 'dtr/test_unit/testrunnermediator_injection'
|
22
23
|
require 'dtr/test_unit/injection'
|
data/lib/dtr.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2007-2008 Li Xiao
|
1
|
+
# Copyright (c) 2007-2008 Li Xiao <iam@li-xiao.com>
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -12,42 +12,11 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
-
|
15
|
+
require 'dtr/facade'
|
16
|
+
|
17
|
+
DTRVERSION="1.0.0"
|
16
18
|
DTR_AGENT_OPTIONS = {:runners => [], :agent_env_setup_cmd => nil}
|
17
19
|
|
18
20
|
module DTR
|
19
|
-
|
20
|
-
def start_agent
|
21
|
-
launch_agent(DTR_AGENT_OPTIONS[:runners], DTR_AGENT_OPTIONS[:agent_env_setup_cmd])
|
22
|
-
end
|
23
|
-
|
24
|
-
def launch_agent(names, setup=nil)
|
25
|
-
require 'dtr/agent'
|
26
|
-
names = names || "DTR(#{Time.now})"
|
27
|
-
DTR::Agent.start(names, setup)
|
28
|
-
end
|
29
|
-
|
30
|
-
def lib_path
|
31
|
-
File.expand_path(File.dirname(__FILE__))
|
32
|
-
end
|
33
|
-
|
34
|
-
def broadcast_list=(list)
|
35
|
-
require 'dtr/shared'
|
36
|
-
DTR.configuration.broadcast_list = list
|
37
|
-
DTR.configuration.save
|
38
|
-
end
|
39
|
-
|
40
|
-
def port=(port)
|
41
|
-
require 'dtr/shared'
|
42
|
-
DTR.configuration.rinda_server_port = port
|
43
|
-
DTR.configuration.save
|
44
|
-
end
|
45
|
-
|
46
|
-
def monitor
|
47
|
-
require 'dtr/monitor'
|
48
|
-
DTR.logger('dtr_monitor.log')
|
49
|
-
Monitor.new.start
|
50
|
-
end
|
51
|
-
|
52
|
-
module_function :start_agent, :launch_agent, :lib_path, :broadcast_list=, :monitor, :port=
|
21
|
+
extend Facade
|
53
22
|
end
|
@@ -7,40 +7,34 @@ class AgentWorkingEnvTest < Test::Unit::TestCase
|
|
7
7
|
def setup
|
8
8
|
#start_agents first for test files loaded would be copied into sub processes
|
9
9
|
start_agents
|
10
|
-
DTR.inject
|
11
10
|
end
|
12
11
|
|
13
12
|
def teardown
|
14
|
-
DTR.reject
|
15
13
|
stop_agents
|
16
|
-
$argv_dup = nil
|
17
14
|
end
|
18
15
|
|
19
16
|
def test_run_2_project_should_be_independence
|
20
|
-
|
17
|
+
assert_fork_process_exits_ok do
|
21
18
|
$argv_dup = ['an_error_test_case.rb']
|
22
|
-
require 'an_error_test_case'
|
23
19
|
|
24
20
|
suite = Test::Unit::TestSuite.new('test_run_2_project_should_be_independence 1')
|
25
21
|
suite << AnErrorTestCase.suite
|
26
22
|
|
27
|
-
|
28
|
-
@result = runit(suite)
|
23
|
+
@result = runit(suite)
|
29
24
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
end
|
25
|
+
assert_false @result.passed?
|
26
|
+
assert_equal 1, @result.run_count
|
27
|
+
assert_equal 0, @result.failure_count
|
28
|
+
assert_equal 1, @result.error_count
|
35
29
|
end
|
36
30
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
31
|
+
assert_fork_process_exits_ok do
|
32
|
+
Dir.chdir("another_project") do
|
33
|
+
$argv_dup = ['passed_test_case.rb']
|
34
|
+
require 'passed_test_case'
|
35
|
+
suite = Test::Unit::TestSuite.new('test_run_2_project_should_be_independence 2')
|
36
|
+
suite << PassedTestCase.suite
|
42
37
|
|
43
|
-
assert_fork_process_exits_ok do
|
44
38
|
@result = runit(suite)
|
45
39
|
|
46
40
|
assert @result.passed?
|
@@ -52,13 +46,13 @@ class AgentWorkingEnvTest < Test::Unit::TestCase
|
|
52
46
|
end
|
53
47
|
|
54
48
|
def test_run_same_project_twice_should_be_independence
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
49
|
+
assert_fork_process_exits_ok do
|
50
|
+
Dir.chdir("another_project") do
|
51
|
+
$argv_dup = ['passed_test_case.rb']
|
52
|
+
require 'passed_test_case'
|
53
|
+
suite = Test::Unit::TestSuite.new('test_run_same_project_twice_should_be_independence 1')
|
54
|
+
suite << PassedTestCase.suite
|
60
55
|
|
61
|
-
assert_fork_process_exits_ok do
|
62
56
|
@result = runit(suite)
|
63
57
|
|
64
58
|
assert @result.passed?
|
@@ -68,24 +62,24 @@ class AgentWorkingEnvTest < Test::Unit::TestCase
|
|
68
62
|
end
|
69
63
|
end
|
70
64
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
65
|
+
assert_fork_process_exits_ok do
|
66
|
+
Dir.chdir("another_project") do
|
67
|
+
FileUtils.cp("./../an_error_test_case.rb", '.')
|
68
|
+
begin
|
69
|
+
$argv_dup = ['an_error_test_case.rb']
|
70
|
+
require 'an_error_test_case'
|
71
|
+
suite = Test::Unit::TestSuite.new('test_run_same_project_twice_should_be_independence 2')
|
72
|
+
suite << AnErrorTestCase.suite
|
78
73
|
|
79
|
-
assert_fork_process_exits_ok do
|
80
74
|
@result = runit(suite)
|
81
75
|
|
82
76
|
assert_false @result.passed?
|
83
77
|
assert_equal 1, @result.run_count
|
84
78
|
assert_equal 0, @result.failure_count
|
85
79
|
assert_equal 1, @result.error_count
|
80
|
+
ensure
|
81
|
+
FileUtils.rm_f('an_error_test_case.rb')
|
86
82
|
end
|
87
|
-
ensure
|
88
|
-
FileUtils.rm_f('an_error_test_case.rb')
|
89
83
|
end
|
90
84
|
end
|
91
85
|
end
|
@@ -10,7 +10,7 @@ class DTRPackageTaskTest < Test::Unit::TestCase
|
|
10
10
|
assert File.exists?(testdata_dir + "/dtr_pkg/codebase-dump/lib/lib_test_case.rb")
|
11
11
|
assert File.exists?(testdata_dir + "/dtr_pkg/codebase-dump/is_required_by_a_test.rb")
|
12
12
|
|
13
|
-
assert File.exists?(testdata_dir + "/dtr_pkg/codebase-dump.
|
13
|
+
assert File.exists?(testdata_dir + "/dtr_pkg/codebase-dump.zip")
|
14
14
|
|
15
15
|
%x[rake --rakefile package_task_test_rakefile dtr_clobber_package]
|
16
16
|
|
@@ -18,9 +18,19 @@ class DTRPackageTaskTest < Test::Unit::TestCase
|
|
18
18
|
assert !File.exists?(testdata_dir + "/dtr_pkg/codebase-dump/lib/lib_test_case.rb")
|
19
19
|
assert !File.exists?(testdata_dir + "/dtr_pkg/codebase-dump/is_required_by_a_test.rb")
|
20
20
|
|
21
|
-
assert !File.exists?(testdata_dir + "/dtr_pkg/codebase-dump.
|
21
|
+
assert !File.exists?(testdata_dir + "/dtr_pkg/codebase-dump.zip")
|
22
22
|
end
|
23
23
|
ensure
|
24
24
|
FileUtils.rm_rf(testdata_dir + "/dtr_pkg") rescue nil
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
|
+
def test_should_not_include_dtr_pkg_dir
|
28
|
+
testdata_dir = File.expand_path(File.dirname(__FILE__) + '/../../testdata')
|
29
|
+
Dir.chdir(testdata_dir) do
|
30
|
+
%x[rake dtr_repackage]
|
31
|
+
assert !File.exists?(testdata_dir + "/dtr_pkg/codebase-dump/dtr_pkg")
|
32
|
+
end
|
33
|
+
ensure
|
34
|
+
FileUtils.rm_rf(testdata_dir + "/dtr_pkg") rescue nil
|
35
|
+
end
|
36
|
+
end
|