Skip to content

Commit

Permalink
added test (and fixtures) for dir_size
Browse files Browse the repository at this point in the history
  • Loading branch information
mwarin committed Jun 20, 2024
1 parent d6a0a45 commit dc7507a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
2 changes: 2 additions & 0 deletions t/fixtures/dir_size/README1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
don't change this file or any in/under this dir
if you do, you'll break the dir_size test in t/job_metrics.t
1 change: 1 addition & 0 deletions t/fixtures/dir_size/README2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
also don't change this file, please
1 change: 1 addition & 0 deletions t/fixtures/dir_size/subdir/README3
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
and most importantly don't change this file either, sill-voo-play
29 changes: 25 additions & 4 deletions t/job_metrics.t
Original file line number Diff line number Diff line change
Expand Up @@ -102,23 +102,44 @@ describe "HTFeed::JobMetrics" => sub {
# 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 $t1 = $jm->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 $t2 = $jm->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
ok( ($delta_t - $sleep_time) < $resolution_tolerance);
# e.g. (0.103... - 0.1 ) < 0.01
};
it "reports dir size, recursively, with bytes as base unit" => sub {
# To check that it counts file sizes recursively,
# we have this fixture dir:
#
# feed/t/fixtures/dir_size$ tree
# .
# ├── README1 (108B)
# ├── README2 (36B)
# └── subdir
# └── README3 (66B)
#
# Please don't change anything in these fixture dirs,
# without also updating the dir sizes in this test.

my $dir = "/usr/local/feed/t/fixtures/dir_size";
my $expected_dir_size = 210; # (108 + 36) + 66
my $subdir = "$dir/subdir";
my $expected_subdir_size = 66;

ok($jm->dir_size($dir) == $expected_dir_size);
ok($jm->dir_size($subdir) == $expected_subdir_size);
};
# TESTS todo
it "could have some histogram tests once we figure out histograms" => sub {};
# TESTS end
Expand Down

0 comments on commit dc7507a

Please sign in to comment.