diff --git a/Dockerfile.dev b/Dockerfile.dev index a8ea7f21..3baf5377 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -16,7 +16,6 @@ RUN apk update && \ mysql-dev \ openssh \ ruby-dev \ - ruby-json \ tzdata \ yaml \ yaml-dev \ diff --git a/Dockerfile.system-test b/Dockerfile.system-test index 0bff879c..e6aca55f 100644 --- a/Dockerfile.system-test +++ b/Dockerfile.system-test @@ -16,7 +16,6 @@ RUN apk update && \ mysql-dev \ openssh \ ruby-dev \ - ruby-json \ tzdata \ yaml \ yaml-dev \ diff --git a/lib/bucky/core/database/test_data_operator.rb b/lib/bucky/core/database/test_data_operator.rb index 8cab581d..ea9b9581 100644 --- a/lib/bucky/core/database/test_data_operator.rb +++ b/lib/bucky/core/database/test_data_operator.rb @@ -21,7 +21,7 @@ def initialize def save_job_record_and_get_job_id(start_time, command_and_option, fqdn) return 0 if $debug - job_id = @connector.con[:jobs].insert(start_time: start_time, command_and_option: command_and_option, base_fqdn: fqdn) + job_id = @connector.con[:jobs].insert(start_time:, command_and_option:, base_fqdn: fqdn) @connector.disconnect job_id end @@ -95,7 +95,7 @@ def get_ng_test_cases_at_last_execution(cond) def get_test_case_id(test_suite_id, case_name) return nil if $debug - test_case = @connector.con[:test_cases].filter(test_suite_id: test_suite_id, case_name: case_name).first + test_case = @connector.con[:test_cases].filter(test_suite_id:, case_name:).first @connector.disconnect raise "Cannot get test_case id. test_suite_id: #{test_suite_id}, case_name: #{case_name}" if test_case.nil? @@ -106,11 +106,28 @@ def get_test_case_id(test_suite_id, case_name) # @param [Int] job_id # @return [Int] round def get_last_round_from_job_id(job_id) - round = @connector.con[:test_case_results].where(job_id: job_id).max(:round) + round = @connector.con[:test_case_results].where(job_id:).max(:round) @connector.disconnect round end + # Update job record with end_time and duration + # @param [Integer] job_id + # @param [Time] end_time + # @param [Float] duration + def update_job_record(job_id, end_time, duration) + rounded_duration = duration.round(2) + puts "DEBUG: Updating job #{job_id} with end_time #{end_time} and duration #{rounded_duration}" + return if $debug + + @connector.connect + @connector.con[:jobs].where(id: job_id).update( + end_time:, + duration: rounded_duration + ) + @connector.disconnect + end + private # Common method for getting suite @@ -131,7 +148,7 @@ def get_suite_id_from_saved_test_suite(saved_test_suite, test_data) test_suite_name: test_data[:test_suite_name], suite_description: test_data[:suite][:desc], github_url: @config[:test_code_repo], - file_path: file_path + file_path: ) saved_test_suite[:id] else # If there is no test_suite, save new record and return suite_id. @@ -143,7 +160,7 @@ def get_suite_id_from_saved_test_suite(saved_test_suite, test_data) test_suite_name: test_data[:test_suite_name], suite_description: test_data[:suite][:desc], github_url: @config[:test_code_repo], - file_path: file_path + file_path: ) end end @@ -159,11 +176,11 @@ def insert_and_return_label_ids(labels) return nil if labels.empty? labels.each do |label_name| - label = @connector.con[:labels].filter(label_name: label_name).first + label = @connector.con[:labels].filter(label_name:).first label_ids << if label label[:id] else - @connector.con[:labels].insert(label_name: label_name) + @connector.con[:labels].insert(label_name:) end end label_ids @@ -180,14 +197,14 @@ def update_test_case_and_test_case_label(suite_id, test_case, label_ids) # Create new connection # If there is no labels, return nil label_ids&.each do |label_id| - @connector.con[:test_case_labels].insert(test_case_id: saved_test_case[:id], label_id: label_id) + @connector.con[:test_case_labels].insert(test_case_id: saved_test_case[:id], label_id:) end else # Add case data test_case_id = @connector.con[:test_cases].insert(test_suite_id: suite_id, case_name: test_case[:case_name], case_description: test_case[:desc]) # If there is no labels, return nil label_ids&.each do |label_id| - @connector.con[:test_case_labels].insert(test_case_id: test_case_id, label_id: label_id) + @connector.con[:test_case_labels].insert(test_case_id:, label_id:) end end end diff --git a/lib/bucky/core/test_core/test_manager.rb b/lib/bucky/core/test_core/test_manager.rb index 5d7f48ce..ea13ba4e 100644 --- a/lib/bucky/core/test_core/test_manager.rb +++ b/lib/bucky/core/test_core/test_manager.rb @@ -55,7 +55,7 @@ def parallel_distribute_into_workers(data_set, max_processes, &block) data_set_grouped = data_set.group_by.with_index { |_elem, index| index % max_processes } r_pipe, w_pipe = IO.pipe # Use 'values' method to get only hash's key into an array - data_set_grouped.values.each do |data_for_pre_worker| + data_set_grouped.each_value do |data_for_pre_worker| # Number of child process is equal to max_processes (or equal to data_set length when data_set length is less than max_processes) fork do data_for_pre_worker.each { |data| block.call(data, w_pipe) } @@ -112,6 +112,11 @@ def initialize(test_cond) def run execute_test + + # Update job record with end_time and duration when test completes + @end_time = Time.now + @duration = @end_time - @start_time + @tdo.update_job_record($job_id, @end_time, @duration) end # Rerun by job id @@ -122,6 +127,11 @@ def rerun is_error: 1, job_id: rerun_job_id, round: $round ) execute_test + + # Update job record with end_time and duration when test completes + @end_time = Time.now + @duration = @end_time - @start_time + @tdo.update_job_record($job_id, @end_time, @duration) end private @@ -142,10 +152,10 @@ def do_test_suites(test_suite_data) linkstatus_parallel_num = Bucky::Utils::Config.instance[:linkstatus_parallel_num] tcg = Bucky::Core::TestCore::TestClassGenerator.new(@test_cond) case @test_cond[:test_category] - when 'e2e' then results_set = parallel_new_worker_each(test_suite_data, e2e_parallel_num) { |data, w_pipe| tcg.generate_test_class(data: data, w_pipe: w_pipe) } - when 'linkstatus' then + when 'e2e' then results_set = parallel_new_worker_each(test_suite_data, e2e_parallel_num) { |data, w_pipe| tcg.generate_test_class(data:, w_pipe:) } + when 'linkstatus' linkstatus_url_log = {} - results_set = parallel_distribute_into_workers(test_suite_data, linkstatus_parallel_num) { |data, w_pipe| tcg.generate_test_class(data: data, linkstatus_url_log: linkstatus_url_log, w_pipe: w_pipe) } + results_set = parallel_distribute_into_workers(test_suite_data, linkstatus_parallel_num) { |data, w_pipe| tcg.generate_test_class(data:, linkstatus_url_log:, w_pipe:) } end results_set diff --git a/spec/core/test_core/test_manager_spec.rb b/spec/core/test_core/test_manager_spec.rb index 11450f1c..fa6eae84 100644 --- a/spec/core/test_core/test_manager_spec.rb +++ b/spec/core/test_core/test_manager_spec.rb @@ -10,12 +10,13 @@ before do allow(Bucky::Core::Database::TestDataOperator).to receive(:new).and_return(tdo) allow(tdo).to receive(:save_job_record_and_get_job_id) + allow(tdo).to receive(:update_job_record) allow(tdo).to receive(:get_ng_test_cases_at_last_execution).and_return(ng_case_data) allow(tm).to receive(:do_test_suites).and_return({}) end describe '#run' do - let(:tm) { Bucky::Core::TestCore::TestManager.new(re_test_count: re_test_count) } + let(:tm) { Bucky::Core::TestCore::TestManager.new(re_test_count:) } describe '@re_test_count: run untill max round' do context '@re_test_count is 1' do @@ -50,9 +51,10 @@ end describe '#rerun' do - let(:tm) { Bucky::Core::TestCore::TestManager.new(re_test_count: re_test_count, job: rerun_job_id) } + let(:tm) { Bucky::Core::TestCore::TestManager.new(re_test_count:, job: rerun_job_id) } before do allow(tdo).to receive(:get_last_round_from_job_id) + allow(tdo).to receive(:update_job_record) end describe 'call execute_test on rerun method' do