Skip to content

Commit 2d2b35b

Browse files
committed
test(file-age): widen time-drift tolerance in test_scenario3_perfdata
The mean/median perfdata assertions pinned the computed age to a 3-second window around the nominal value, which was too tight to survive a CI runner under load. Between the `touch -d 'N seconds ago'` call and the plugin invocation, real elapsed time and any file-system mtime rounding push the reported age upwards, and the fourth-file "even" mean assertion (81.0 < age < 84.0 around the nominal 83.75 from (10+25+100+200)/4) was the first to trip. Widen all four perfdata assertions to roughly 5 seconds of upward headroom and annotate each with its nominal value so future adjustments do not have to re-derive the expected mean/median.
1 parent 0be9383 commit 2d2b35b

File tree

1 file changed

+16
-10
lines changed
  • check-plugins/file-age/unit-test

1 file changed

+16
-10
lines changed

check-plugins/file-age/unit-test/run

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -235,45 +235,51 @@ class TestCheck(unittest.TestCase):
235235
"""
236236
lib.base.coe(lib.shell.shell_exec('bash', stdin=bash.encode()))
237237

238-
# the output is being checked against a range as there's some time derivation from touch caused by certain file systems
239-
240-
# check mean uneven
238+
# Perfdata ages are checked against a loose range because real
239+
# elapsed time between the `touch` command and the plugin call
240+
# drifts the reported age upwards on slow runners, and some
241+
# file systems round the mtime. The ranges are intentionally
242+
# wide enough (~5s) to survive a CI container under load; a
243+
# tighter window produces flaky failures when the test host
244+
# is busy.
245+
246+
# check mean uneven (expected ~45.0s = (10+25+100)/3)
241247
cmd = f"../file-age --filename '{tmpdir}/*' --warning '15:' --warning-count '3:' --critical '20:' --critical-count '2:' --perfdata-mode=mean"
242248
stdout, _stderr, _retc = lib.base.coe(lib.shell.shell_exec(cmd))
243249
age = float(
244250
stdout.rpartition('|')[2].rpartition('=')[2].split('s')[0]
245251
) # extract age from perfdata string
246-
self.assertTrue(43.0 < age < 46.0)
252+
self.assertTrue(43.0 < age < 50.0)
247253

248-
# check median uneven
254+
# check median uneven (expected ~25.0s)
249255
cmd = f"../file-age --filename '{tmpdir}/*' --warning '15:' --warning-count '3:' --critical '20:' --critical-count '2:' --perfdata-mode=median"
250256
stdout, _stderr, _retc = lib.base.coe(lib.shell.shell_exec(cmd))
251257
age = float(
252258
stdout.rpartition('|')[2].rpartition('=')[2].split('s')[0]
253259
) # extract age from perfdata string
254-
self.assertTrue(23.0 < age < 26.0)
260+
self.assertTrue(23.0 < age < 30.0)
255261

256262
# add one file to make it an even file list
257263
bash = f"""
258264
touch -d '200 seconds ago' {tmpdir}/file4
259265
"""
260266
lib.base.coe(lib.shell.shell_exec('bash', stdin=bash.encode()))
261267

262-
# check mean even
268+
# check mean even (expected ~83.75s = (10+25+100+200)/4)
263269
cmd = f"../file-age --filename '{tmpdir}/*' --warning '15:' --warning-count '3:' --critical '20:' --critical-count '2:' --perfdata-mode=mean"
264270
stdout, _stderr, _retc = lib.base.coe(lib.shell.shell_exec(cmd))
265271
age = float(
266272
stdout.rpartition('|')[2].rpartition('=')[2].split('s')[0]
267273
) # extract age from perfdata string
268-
self.assertTrue(81.0 < age < 84.0)
274+
self.assertTrue(81.0 < age < 90.0)
269275

270-
# check median even
276+
# check median even (expected ~62.5s = (25+100)/2)
271277
cmd = f"../file-age --filename '{tmpdir}/*' --warning '15:' --warning-count '3:' --critical '20:' --critical-count '2:' --perfdata-mode=median"
272278
stdout, _stderr, _retc = lib.base.coe(lib.shell.shell_exec(cmd))
273279
age = float(
274280
stdout.rpartition('|')[2].rpartition('=')[2].split('s')[0]
275281
) # extract age from perfdata string
276-
self.assertTrue(60.0 < age < 63.0)
282+
self.assertTrue(60.0 < age < 68.0)
277283

278284

279285
if __name__ == '__main__':

0 commit comments

Comments
 (0)