Class: Toaster::TestOrchestrator
- Inherits:
-
Object
- Object
- Toaster::TestOrchestrator
- Defined in:
- lib/toaster/test/test_orchestrator.rb
Instance Attribute Summary collapse
-
#automation_run ⇒ Object
Returns the value of attribute automation_run.
-
#end_time ⇒ Object
Returns the value of attribute end_time.
-
#repeat_task_uuids ⇒ Object
Returns the value of attribute repeat_task_uuids.
-
#skip_task_uuids ⇒ Object
Returns the value of attribute skip_task_uuids.
-
#start_time ⇒ Object
Returns the value of attribute start_time.
-
#test_suite ⇒ Object
Returns the value of attribute test_suite.
-
#uuid ⇒ Object
Returns the value of attribute uuid.
Instance Method Summary collapse
- #add_host(host) ⇒ Object
- #all_hosts ⇒ Object
- #await_results(test_suite_uuid) ⇒ Object
- #clean_hosts ⇒ Object
- #distribute_test_cases(tests_to_run) ⇒ Object
- #distribute_tests(test_suite) ⇒ Object
- #exec_on_all_hosts(command, output = true, parallel = true) ⇒ Object
- #generate_tests(test_suite_uuid, coverage_goal) ⇒ Object
- #generate_tests_for_suite(test_suite) ⇒ Object
-
#initialize(config = {}) ⇒ TestOrchestrator
constructor
A new instance of TestOrchestrator.
- #select_host ⇒ Object
- #update_all_services ⇒ Object
Constructor Details
#initialize(config = {}) ⇒ TestOrchestrator
20 21 22 23 24 |
# File 'lib/toaster/test/test_orchestrator.rb', line 20 def initialize(config = {}) @hosts = [] @host_proxies = {} @round_robin_counter = -1 end |
Instance Attribute Details
#automation_run ⇒ Object
Returns the value of attribute automation_run.
18 19 20 |
# File 'lib/toaster/test/test_orchestrator.rb', line 18 def automation_run @automation_run end |
#end_time ⇒ Object
Returns the value of attribute end_time.
18 19 20 |
# File 'lib/toaster/test/test_orchestrator.rb', line 18 def end_time @end_time end |
#repeat_task_uuids ⇒ Object
Returns the value of attribute repeat_task_uuids.
18 19 20 |
# File 'lib/toaster/test/test_orchestrator.rb', line 18 def repeat_task_uuids @repeat_task_uuids end |
#skip_task_uuids ⇒ Object
Returns the value of attribute skip_task_uuids.
18 19 20 |
# File 'lib/toaster/test/test_orchestrator.rb', line 18 def skip_task_uuids @skip_task_uuids end |
#start_time ⇒ Object
Returns the value of attribute start_time.
18 19 20 |
# File 'lib/toaster/test/test_orchestrator.rb', line 18 def start_time @start_time end |
#test_suite ⇒ Object
Returns the value of attribute test_suite.
18 19 20 |
# File 'lib/toaster/test/test_orchestrator.rb', line 18 def test_suite @test_suite end |
#uuid ⇒ Object
Returns the value of attribute uuid.
18 19 20 |
# File 'lib/toaster/test/test_orchestrator.rb', line 18 def uuid @uuid end |
Instance Method Details
#add_host(host) ⇒ Object
26 27 28 |
# File 'lib/toaster/test/test_orchestrator.rb', line 26 def add_host(host) @hosts << host end |
#all_hosts ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/toaster/test/test_orchestrator.rb', line 38 def all_hosts() result = [] @hosts.each do |host| result << get_proxy(host) end return result end |
#await_results(test_suite_uuid) ⇒ Object
136 137 138 139 140 141 142 143 144 145 |
# File 'lib/toaster/test/test_orchestrator.rb', line 136 def await_results(test_suite_uuid) puts "INFO: Waiting for test results..." suite = TestSuite.find({"uuid" => test_suite_uuid})[0] unfinished_tests = suite.query_unfinished_tests while !unfinished_tests.empty? puts "INFO: Waiting some time for new test results (#{unfinished_tests.size} tests remaining)..." sleep 10 unfinished_tests = suite.query_unfinished_tests end end |
#clean_hosts ⇒ Object
147 148 149 150 151 |
# File 'lib/toaster/test/test_orchestrator.rb', line 147 def clean_hosts() Util.exec_in_parallel(all_hosts) do |h| h.clean() end end |
#distribute_test_cases(tests_to_run) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/toaster/test/test_orchestrator.rb', line 99 def distribute_test_cases(tests_to_run) tests = tests_to_run tests_orig = tests_to_run.dup puts "INFO: Distributing #{tests.size} generated tests to #{@hosts.size} hosts" tests_by_host = {} while !tests.empty? test = tests.shift host = select_host() tests_by_host[host] = [] if !tests_by_host[host] tests_by_host[host] << test.uuid test.executing_host = host.host end tests_orig.each do |t| # save test case to store "t.executing_host" to DB t.save end tests_by_host.each do |host,test_case_list| puts "INFO: Sending test case list #{test_case_list} to host #{host}" blocking = false output = host.runtest(test_case_list.join(","), blocking) end end |
#distribute_tests(test_suite) ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/toaster/test/test_orchestrator.rb', line 122 def distribute_tests(test_suite) if !test_suite.kind_of?(TestSuite) test_suite = TestSuite.find(:uuid => test_suite)[0] end tests = test_suite.test_cases tests_to_run = [] tests.each do |t| if !t.executed?() tests_to_run << t end end distribute_test_cases(tests_to_run) end |
#exec_on_all_hosts(command, output = true, parallel = true) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/toaster/test/test_orchestrator.rb', line 55 def exec_on_all_hosts(command, output=true, parallel=true) out_total = "" mutex = Mutex.new block = lambda do |host| p = get_proxy(host) out_tmp = "" out_tmp += "INFO: Executing command on #{host}: #{command}\n" out = p.exec(command) out_tmp += "#{out}\n" mutex.synchronize do out_total += "#{out_tmp}\n" end if output puts out end end if parallel Util.exec_in_parallel(@hosts, &block) else @hosts.each &block end return out_total end |
#generate_tests(test_suite_uuid, coverage_goal) ⇒ Object
79 80 81 82 83 |
# File 'lib/toaster/test/test_orchestrator.rb', line 79 def generate_tests(test_suite_uuid, coverage_goal) suite = TestSuite.find({"uuid" => test_suite_uuid})[0] suite.coverage_goal = coverage_goal generate_tests_for_suite(suite) end |
#generate_tests_for_suite(test_suite) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/toaster/test/test_orchestrator.rb', line 85 def generate_tests_for_suite(test_suite) gen = TestGenerator.new(test_suite) puts "INFO: Starting to generate tests..." tests = gen.gen_all_tests() puts "INFO: Generated #{tests.size} test cases for test suite #{test_suite.uuid} (#{test_suite.test_cases.size} test cases so far)." tests.each do |test| if !test_suite.contains_equal_test?(test) test_suite.test_cases << test end end puts "INFO: Test suite #{test_suite.uuid} now contains #{test_suite.test_cases.size} test cases." test_suite.save end |
#select_host ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/toaster/test/test_orchestrator.rb', line 30 def select_host() raise "No hosts have been defined yet." if @hosts.empty? @round_robin_counter = @round_robin_counter >= @hosts.size - 1 ? 0 : @round_robin_counter + 1 host = @hosts[@round_robin_counter] client = get_proxy(host) return client end |
#update_all_services ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/toaster/test/test_orchestrator.rb', line 46 def update_all_services() all_hosts.each do |h| t = Thread.start { h.update_code() } end sleep 9 end |