Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TEST: added test for time
Browse files Browse the repository at this point in the history
mwarin committed Jun 20, 2024
1 parent 93d3185 commit d6a0a45
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions t/job_metrics.t
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@ use FindBin;
use lib "$FindBin::Bin/lib";
use Test::Spec;
use Test::Exception;
use Time::HiRes qw(usleep);

use HTFeed::JobMetrics;

@@ -95,6 +96,28 @@ describe "HTFeed::JobMetrics" => sub {
} while ($kid > 0);
ok($jm->get_value($item_metric) == 5);
};
it "reports time w/ second as base unit, at high resolution" => sub {
# To do this we sleep 10% of a second (don't want to slow down tests).
# Time::HirRes::usleep lets us sleep with microsec precision.
# The "tolerance" is somewhat arbitrary, for testing purposes only,
# since we're not really testing that Time::HiRes works as promised,
# but rather that our assumptions around time are correct.
my $t1 = HTFeed::JobMetrics->time;
my $sleep_time = 0.1;
my $sleep_time_in_microsec = $sleep_time * 1000000;
my $resolution_tolerance = 0.01;

usleep $sleep_time_in_microsec;
my $t2 = HTFeed::JobMetrics->time;
my $delta_t = $t2 - $t1;

# Now prove that t1 and t2 are (very close to) 0.25 sec apart.
# Numbers will be relatively similar to:
# t1: e.24969, t2: e.50003, delta_t: 0.250342845916748
# ... where e is the current epoch in whole seconds
ok( ($delta_t - $sleep_time) < $resolution_tolerance);
# e.g. (0.103... - 0.1 ) < 0.01
};

# TESTS todo
it "could have some histogram tests once we figure out histograms" => sub {};

0 comments on commit d6a0a45

Please sign in to comment.