File: 110-store-stress.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 (60 lines) | stat: -rw-r--r-- 1,295 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
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
#!perl

use warnings;
use strict;

use Test::More;
use Test::Differences;

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

plan skip_all => "set PTS_STRESS_TEST=1 to run stress tests"
  unless $ENV{PTS_STRESS_TEST};

my @values = map {
  scalar rand_chars(set => 'alphanumeric', size => 10);
} (1..10_000);

for my $max (
  100,
  500,
  1_000,
  5_000,
  10_000,
  50_000,
  100_000,
  500_000,
  1_000_000,
  5_000_000,
  10_000_000,
) {
  my $p = Prometheus::Tiny->new;

  my $ps = Prometheus::Tiny::Shared->new(
    share_file => scalar tmpnam(),
  );

  my @metrics = map {
    my $metric = "metric_$_";
    $p->declare($metric, help => "some metric $_", type => 'counter');
    $ps->declare($metric, help => "some metric $_", type => 'counter');
    $metric;
  } (1..100);

  for (1..$max) {
    my $metric = $metrics[int(rand(scalar @metrics))];
    my $value  = $values[int(rand(scalar @values))];
    $p->inc($metric, { some_label => $value });
    $ps->inc($metric, { some_label => $value });
    #diag "done $_/$max iterations" if $_ % 10000 == 0;
  }

  eq_or_diff($p->format, $ps->format,
             "in-memory and cached metrics match ($max iterations)")
    or die "not running further tests\n";
}

done_testing;