From a5c84085b6bd009a0a904ec2d870eaacb1858680 Mon Sep 17 00:00:00 2001 From: Manuel Naranjo Date: Thu, 22 Oct 2026 12:49:51 +0200 Subject: [PATCH] t: fix flaky memory_bytes check in 05_stats.t memory_bytes is the change in process memory size (VmSize from /proc/self/statm) across an eval. It is negative whenever V8 unmaps memory during the eval, so asserting memory_bytes >= 0 failed in roughly 5-25% of runs. Check that it is a number instead; elapsed_us keeps the >= 0 check. Co-Authored-By: Claude Opus 5.5 --- t/05_stats.t | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/t/05_stats.t b/t/05_stats.t index e52a106..caa5f33 100644 --- a/t/05_stats.t +++ b/t/05_stats.t @@ -2,6 +2,7 @@ use strict; use warnings; use Data::Dumper; +use Scalar::Util qw(looks_like_number); use Test::More; my $CLASS = 'JavaScript::V8::XS'; @@ -36,7 +37,13 @@ sub test_stats { my $data = $stats->{$category}; foreach my $name (qw/ memory_bytes elapsed_us /) { ok(exists $data->{$name}, "name $name exists in stats for $category"); - ok($data->{$name} >= 0, "name $name has a valid value in stats for $category"); + # memory_bytes is a delta of process memory and can + # be negative if V8 releases memory (e.g. on GC) + if ($name eq 'memory_bytes') { + ok(looks_like_number($data->{$name}), "name $name has a valid value in stats for $category"); + } else { + ok($data->{$name} >= 0, "name $name has a valid value in stats for $category"); + } } } }