Skip to content

Commit

Permalink
Improve log pattern test
Browse files Browse the repository at this point in the history
  • Loading branch information
senhalil committed Dec 10, 2021
1 parent 8c79aa6 commit cadb07d
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions test/api/v01/vrp_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,8 @@ def test_block_call_under_clustering
end

def test_unfounded_avancement_message_change
todays = [Date.today]
times = [Time.now]
lines_with_avancement = ''
Dir.mktmpdir('temp_', 'test/') { |tmpdir|
begin
Expand Down Expand Up @@ -314,26 +316,34 @@ def test_unfounded_avancement_message_change
output&.unlink
end
}
todays << Date.today
times << Time.now

assert_msg = "\nThe structure of avancement message has changed! If the modification is on purpose " \
"fix this test \n(#{self.class.name}::#{self.name}) to represent the actual functionality."
# Currently the expected output is in the following form
# [date time] jobid - INFO: avancement: repetition (1..2)/2 - clustering phase (y: 1..2)/2 - step (1..y)/(y)
# [date time] jobid - INFO: avancement: repetition (1..2)/2 - process (1..9)/10 - solving periodic heuristic
# [date time_with_ms_and_zone] jobid - INFO: avancement: repetition (1..2)/2 - clustering phase (y: 1..2)/2 - step (1..y)/(y)
# [date time_with_ms_and_zone] jobid - INFO: avancement: repetition (1..2)/2 - process (1..9)/10 - solving periodic heuristic

lines_with_avancement.each{ |line|
date_time_jobid = '\[(?<date>[0-9-]*) (?<hour>[0-9:. +]*)\] (?<job_id>[0-9a-z]*)'
date_time_jobid_pattern = '\[(?<date>[0-9-]*) (?<time_with_ms_and_zone>[0-9:. +]*)\] (?<job_id>[0-9a-z]*)'
# There needs to be avancement and repetition
%r{#{date_time_jobid} - INFO: avancement: repetition [1-2]/2 - (?<rest>.*)\n} =~ line
%r{#{date_time_jobid_pattern} - INFO: avancement: repetition [1-2]/2 - (?<remaining_log>.*)\n} =~ line

refute_nil Regexp.last_match, assert_msg
refute_nil Regexp.last_match(:date)&.to_date, assert_msg
refute_nil Regexp.last_match(:hour)&.to_time, assert_msg
matched_date = Regexp.last_match(:date)&.to_date
refute_nil matched_date, assert_msg
assert_includes todays, matched_date, assert_msg

rest = Regexp.last_match(:rest)
matched_time = Regexp.last_match(:time_with_ms_and_zone)&.to_time
refute_nil matched_time, assert_msg
assert_operator matched_time, :>=, times.first, assert_msg
assert_operator matched_time, :<=, times.last, assert_msg

# The rest needs to be either clustering or heuristic solution
%r{clustering phase [1-2]/2 - step [1-2]/[1-2] } =~ rest || %r{process [1-9]/8 - periodic heuristic } =~ rest
remaining_log = Regexp.last_match(:remaining_log)

# The remaining_log needs to be either clustering or heuristic solution
%r{clustering phase [1-2]/2 - step [1-2]/[1-2] } =~ remaining_log || %r{process [1-9]/8 - periodic heuristic } =~ remaining_log

refute_nil Regexp.last_match, assert_msg
}
Expand Down

0 comments on commit cadb07d

Please sign in to comment.