diff --git a/features/step_definitions/file.rb b/features/step_definitions/file.rb index afffa6e836..e6b572d30a 100644 --- a/features/step_definitions/file.rb +++ b/features/step_definitions/file.rb @@ -34,15 +34,27 @@ Given /^I get time difference using "(.+)" and "(.+)" in (.+) file$/ do |s1, s2, filename| ##This isn't a generic step-definition yet & specific to logs of machineset-controller## - split1 = File.open(filename){ |f| f.read }.split(s1)[0].split("Watching")[0] - split2 = File.open(filename){ |f| f.read }.split(s2)[0].split(s1)[2].strip + log_content = File.read(filename) + + # Extract timestamp from line containing the marker + # Log format: YYYY/MM/DD HH:MM:SS Message + # Example: 2026/06/16 08:36:17 Registering Components. + match1 = log_content.match(/(\d{4}\/\d{2}\/\d{2}\s+\d{2}:\d{2}:\d{2})\s+#{Regexp.escape(s1)}/) + match2 = log_content.match(/(\d{4}\/\d{2}\/\d{2}\s+\d{2}:\d{2}:\d{2})\s+#{Regexp.escape(s2)}/) + + raise "Could not find timestamp for '#{s1}' in log" unless match1 + raise "Could not find timestamp for '#{s2}' in log" unless match2 + + split1 = match1[1] + split2 = match2[1] #Calculating time difference in seconds time_start = DateTime.parse split1 time_end = DateTime.parse split2 time_difference = ((time_end - time_start)* 24 * 60 * 60).to_i + if time_difference > 30 - raise ("Upgrade can cause issues for new machinesets") + raise ("Upgrade can cause issues for new machinesets (#{time_difference}s > 30s)") end end # This step is used to delete lines from file. If multiline match is needed,