File: 160-fork.t

package info (click to toggle)
libprometheus-tiny-shared-perl 0.027-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 200 kB
  • sloc: perl: 830; makefile: 2
file content (35 lines) | stat: -rw-r--r-- 544 bytes parent folder | download | duplicates (2)
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
#!perl

use Test::More;

use Prometheus::Tiny::Shared;
use File::Temp qw(tmpnam);

my $filename = scalar tmpnam();

my $p = Prometheus::Tiny::Shared->new(filename => $filename);

# parent, mark it and start a count
$p->set('parent', 1);
$p->set('count', 1);

my $pid = fork;
if (!$pid) {
  # child, mark it too and bump the count
  $p->set('child', 1);
  $p->inc('count');
  exit 0;
}

# parent, bump the count here too
$p->inc('count');

wait();

is $p->format, <<EOF, 'correct metrics after fork';
child 1
count 3
parent 1
EOF

done_testing;