File: memusage.t

package info (click to toggle)
libtest2-plugin-memusage-perl 0.002003-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 120 kB
  • sloc: perl: 45; makefile: 2
file content (65 lines) | stat: -rw-r--r-- 1,635 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use strict;
use warnings;
use Test2::API qw/intercept context/;

use Test2::Tools::Defer qw/def do_def/;

use vars qw/@CALLBACKS/;

BEGIN {
    no warnings 'redefine';
    local *Test2::API::test2_add_callback_exit = sub { push @CALLBACKS => @_ };

    require Test2::Plugin::MemUsage;
    def ok => (!scalar(@CALLBACKS), "requiring the module does not add a callback");

    Test2::Plugin::MemUsage->import();

    def ok => (scalar(@CALLBACKS), "importing the module does add a callback");
}

use Test2::Tools::Basic;
use Test2::Tools::Compare qw/like is hash field etc/;

do_def;

is(Test2::Plugin::MemUsage->proc_file(), "/proc/$$/status", "Correct procfile");

my $events = intercept {
    sub {
        no warnings 'redefine';
        local *Test2::Plugin::MemUsage::proc_file = sub { 't/procfile' };
        my $ctx = context();
        $CALLBACKS[0]->($ctx);
        $ctx->release;
    }->();
};

chomp(my $summary = <<EOT);
rss:  16604kB
size: 25176kB
peak: 25176kB
EOT

is(
    $events->[0],
    hash {
        field info   => [{details => $summary, tag => 'MEMORY'}];
        field about  => {details => $summary, package => 'Test2::Plugin::MemUsage'};
        field memory => {
            details => $summary,
            size    => ['25176', 'kB'],
            peak    => ['25176', 'kB'],
            rss     => ['16604', 'kB'],
        };
        field harness_job_fields => [
            {name => 'mem_rss',  details => '16604kB'},
            {name => 'mem_size', details => '25176kB'},
            {name => 'mem_peak', details => '25176kB'},
        ];
        etc;
    },
    "Got desired event"
);

done_testing();