~bduggan/raku-curlie

ref: cf639b301572c8a5920ae3b1c643afbc636bb3ab raku-curlie/t/05-stress.rakutest -rw-r--r-- 1.3 KiB
cf639b30Brian Duggan skip stress test 1 year, 1 month ago
                                                                                
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
#!raku 

use Test;
use Curlie;
use Log::Async;

constant AUTHOR = ?%*ENV<TEST_AUTHOR_STRESS>;
do { plan 1; skip-rest "Skipping author stress test"; exit } unless AUTHOR;

logger.add-tap: -> $m { diag "$_" for $m<msg>.lines }, :level(* >= DEBUG);

{
  my \c = Curlie.new;
  c.get: 'https://httpbin.org/get';
  ok c.res.success, '1 request';
}

{
  diag 'running 2000 sequential requests with cleanups';
  my $i = 0;
  for 1..2000 {
    debug "{ ($_/20) } % done" if $_ %% 100;
    my $c will leave { .cleanup with $_ } = Curlie.new;
    $c.get: 'https://httpbin.org/get';
    $i += 1 if $c.res.success;
  }
  is $i, 2000, 'sequential requests';
}

{
  my \c = Curlie.new;
  diag 'running 2000 sequential requests with resets';
  my $i = 0;
  for 1..2000 {
    debug "{ ($_/20) } % done" if $_ %% 100;
    c.get: 'https://httpbin.org/get';
    $i += 1 if c.res.success;
  }
  is $i, 2000, 'sequential requests';
}

{
  my atomicint $i = 0;
  my @p;
  for 1..100 {
    push @p: 
      start {
        my \c = Curlie.new;
        for 1..20 {
          if c.get('https://httpbin.org/get') {
            $i⚛++;
          } else {
            debug "failure : " ~ c.res.gist;
          }
        }
      }
  }
  await Promise.allof(|@p);
  is $i, 2000, "parallel requests";
}

done-testing;