Skip to content

Commit 02af1c3

Browse files
authored
Merge pull request #125 from lifull-dev/add_exe_duration_in_jobs
feat: end_time and duration
2 parents d0021a9 + aaf12fe commit 02af1c3

File tree

6 files changed

+51
-30
lines changed

6 files changed

+51
-30
lines changed

.circleci/config.yml

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ jobs:
3838
working_directory: ~/bucky-core
3939
docker:
4040
- image: cimg/ruby:3.2.0
41-
environment:
42-
CC_TEST_REPORTER_ID: fd7bd9d517bdf8953c4d4803ca4ad7539d12d5c760048b8daf80cbc7d54fb262
4341
steps:
4442
- checkout
4543
- type: cache-restore
@@ -49,17 +47,15 @@ jobs:
4947
key: unit-test-{{ checksum "Gemfile.lock" }}
5048
paths:
5149
- vendor/bundle
52-
# Download test-reporter
50+
# Run rspec
5351
- run:
54-
name: Setup Code Climate test-reporter
55-
command: |
56-
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
57-
chmod +x ./cc-test-reporter
58-
# Run rspec and show on code climate
59-
- run: |
60-
./cc-test-reporter before-build
61-
bundle exec rspec
62-
./cc-test-reporter after-build --coverage-input-type simplecov --exit-code $?
52+
name: Run RSpec tests
53+
command: bundle exec rspec --format progress --format RspecJunitFormatter --out test-results/rspec/results.xml
54+
# Store test results
55+
- store_test_results:
56+
path: test-results
57+
- store_artifacts:
58+
path: test-results
6359
static_code_analysis:
6460
docker:
6561
- image: cimg/ruby:3.2.0
@@ -83,7 +79,7 @@ jobs:
8379
- image: cimg/ruby:3.2.0
8480
steps:
8581
- add_ssh_keys:
86-
finerprints:
82+
fingerprints:
8783
- "6a:f3:d3:b5:a5:da:ce:e0:9f:22:f8:4a:2f:51:67:2b"
8884
- checkout
8985
- run:

Dockerfile.dev

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ RUN apk update && \
1616
mysql-dev \
1717
openssh \
1818
ruby-dev \
19-
ruby-json \
2019
tzdata \
2120
yaml \
2221
yaml-dev \

Dockerfile.system-test

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ RUN apk update && \
1616
mysql-dev \
1717
openssh \
1818
ruby-dev \
19-
ruby-json \
2019
tzdata \
2120
yaml \
2221
yaml-dev \

lib/bucky/core/database/test_data_operator.rb

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def initialize
2121
def save_job_record_and_get_job_id(start_time, command_and_option, fqdn)
2222
return 0 if $debug
2323

24-
job_id = @connector.con[:jobs].insert(start_time: start_time, command_and_option: command_and_option, base_fqdn: fqdn)
24+
job_id = @connector.con[:jobs].insert(start_time:, command_and_option:, base_fqdn: fqdn)
2525
@connector.disconnect
2626
job_id
2727
end
@@ -95,7 +95,7 @@ def get_ng_test_cases_at_last_execution(cond)
9595
def get_test_case_id(test_suite_id, case_name)
9696
return nil if $debug
9797

98-
test_case = @connector.con[:test_cases].filter(test_suite_id: test_suite_id, case_name: case_name).first
98+
test_case = @connector.con[:test_cases].filter(test_suite_id:, case_name:).first
9999
@connector.disconnect
100100
raise "Cannot get test_case id. test_suite_id: #{test_suite_id}, case_name: #{case_name}" if test_case.nil?
101101

@@ -106,11 +106,26 @@ def get_test_case_id(test_suite_id, case_name)
106106
# @param [Int] job_id
107107
# @return [Int] round
108108
def get_last_round_from_job_id(job_id)
109-
round = @connector.con[:test_case_results].where(job_id: job_id).max(:round)
109+
round = @connector.con[:test_case_results].where(job_id:).max(:round)
110110
@connector.disconnect
111111
round
112112
end
113113

114+
# Update job record with end_time and duration
115+
# @param [Integer] job_id
116+
# @param [Time] end_time
117+
# @param [Float] duration
118+
def update_job_record(job_id, end_time, duration)
119+
rounded_duration = duration.round(2)
120+
return if $debug
121+
122+
@connector.con[:jobs].where(id: job_id).update(
123+
end_time:,
124+
duration: rounded_duration
125+
)
126+
@connector.disconnect
127+
end
128+
114129
private
115130

116131
# Common method for getting suite
@@ -131,7 +146,7 @@ def get_suite_id_from_saved_test_suite(saved_test_suite, test_data)
131146
test_suite_name: test_data[:test_suite_name],
132147
suite_description: test_data[:suite][:desc],
133148
github_url: @config[:test_code_repo],
134-
file_path: file_path
149+
file_path:
135150
)
136151
saved_test_suite[:id]
137152
else # If there is no test_suite, save new record and return suite_id.
@@ -143,7 +158,7 @@ def get_suite_id_from_saved_test_suite(saved_test_suite, test_data)
143158
test_suite_name: test_data[:test_suite_name],
144159
suite_description: test_data[:suite][:desc],
145160
github_url: @config[:test_code_repo],
146-
file_path: file_path
161+
file_path:
147162
)
148163
end
149164
end
@@ -159,11 +174,11 @@ def insert_and_return_label_ids(labels)
159174
return nil if labels.empty?
160175

161176
labels.each do |label_name|
162-
label = @connector.con[:labels].filter(label_name: label_name).first
177+
label = @connector.con[:labels].filter(label_name:).first
163178
label_ids << if label
164179
label[:id]
165180
else
166-
@connector.con[:labels].insert(label_name: label_name)
181+
@connector.con[:labels].insert(label_name:)
167182
end
168183
end
169184
label_ids
@@ -180,14 +195,14 @@ def update_test_case_and_test_case_label(suite_id, test_case, label_ids)
180195
# Create new connection
181196
# If there is no labels, return nil
182197
label_ids&.each do |label_id|
183-
@connector.con[:test_case_labels].insert(test_case_id: saved_test_case[:id], label_id: label_id)
198+
@connector.con[:test_case_labels].insert(test_case_id: saved_test_case[:id], label_id:)
184199
end
185200
else
186201
# Add case data
187202
test_case_id = @connector.con[:test_cases].insert(test_suite_id: suite_id, case_name: test_case[:case_name], case_description: test_case[:desc])
188203
# If there is no labels, return nil
189204
label_ids&.each do |label_id|
190-
@connector.con[:test_case_labels].insert(test_case_id: test_case_id, label_id: label_id)
205+
@connector.con[:test_case_labels].insert(test_case_id:, label_id:)
191206
end
192207
end
193208
end

lib/bucky/core/test_core/test_manager.rb

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def parallel_distribute_into_workers(data_set, max_processes, &block)
5555
data_set_grouped = data_set.group_by.with_index { |_elem, index| index % max_processes }
5656
r_pipe, w_pipe = IO.pipe
5757
# Use 'values' method to get only hash's key into an array
58-
data_set_grouped.values.each do |data_for_pre_worker|
58+
data_set_grouped.each_value do |data_for_pre_worker|
5959
# Number of child process is equal to max_processes (or equal to data_set length when data_set length is less than max_processes)
6060
fork do
6161
data_for_pre_worker.each { |data| block.call(data, w_pipe) }
@@ -112,6 +112,11 @@ def initialize(test_cond)
112112

113113
def run
114114
execute_test
115+
116+
# Update job record with end_time and duration when test completes
117+
@end_time = Time.now
118+
@duration = @end_time - @start_time
119+
@tdo.update_job_record($job_id, @end_time, @duration)
115120
end
116121

117122
# Rerun by job id
@@ -122,6 +127,11 @@ def rerun
122127
is_error: 1, job_id: rerun_job_id, round: $round
123128
)
124129
execute_test
130+
131+
# Update job record with end_time and duration when test completes
132+
@end_time = Time.now
133+
@duration = @end_time - @start_time
134+
@tdo.update_job_record($job_id, @end_time, @duration)
125135
end
126136

127137
private
@@ -142,10 +152,10 @@ def do_test_suites(test_suite_data)
142152
linkstatus_parallel_num = Bucky::Utils::Config.instance[:linkstatus_parallel_num]
143153
tcg = Bucky::Core::TestCore::TestClassGenerator.new(@test_cond)
144154
case @test_cond[:test_category]
145-
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) }
146-
when 'linkstatus' then
155+
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:) }
156+
when 'linkstatus'
147157
linkstatus_url_log = {}
148-
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) }
158+
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:) }
149159
end
150160

151161
results_set

spec/core/test_core/test_manager_spec.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@
1010
before do
1111
allow(Bucky::Core::Database::TestDataOperator).to receive(:new).and_return(tdo)
1212
allow(tdo).to receive(:save_job_record_and_get_job_id)
13+
allow(tdo).to receive(:update_job_record)
1314
allow(tdo).to receive(:get_ng_test_cases_at_last_execution).and_return(ng_case_data)
1415
allow(tm).to receive(:do_test_suites).and_return({})
1516
end
1617

1718
describe '#run' do
18-
let(:tm) { Bucky::Core::TestCore::TestManager.new(re_test_count: re_test_count) }
19+
let(:tm) { Bucky::Core::TestCore::TestManager.new(re_test_count:) }
1920

2021
describe '@re_test_count: run untill max round' do
2122
context '@re_test_count is 1' do
@@ -50,9 +51,10 @@
5051
end
5152

5253
describe '#rerun' do
53-
let(:tm) { Bucky::Core::TestCore::TestManager.new(re_test_count: re_test_count, job: rerun_job_id) }
54+
let(:tm) { Bucky::Core::TestCore::TestManager.new(re_test_count:, job: rerun_job_id) }
5455
before do
5556
allow(tdo).to receive(:get_last_round_from_job_id)
57+
allow(tdo).to receive(:update_job_record)
5658
end
5759

5860
describe 'call execute_test on rerun method' do

0 commit comments

Comments
 (0)