File: live-unixis.t

package info (click to toggle)
libhijk-perl 0.27-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 332 kB
  • ctags: 198
  • sloc: perl: 3,070; makefile: 2
file content (42 lines) | stat: -rw-r--r-- 1,385 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
#!/usr/bin/env perl

use strict;
use warnings;
use Hijk;
use Test::More;
use Test::Exception;

unless ($ENV{TEST_LIVE}) {
    plan skip_all => "Enable live testing by setting env: TEST_LIVE=1";
}

if($ENV{http_proxy}) {
    plan skip_all => "http_proxy is set. We cannot test when proxy is required to visit u.nix.is";
}

for my $i (1..1000) {
    lives_ok {
        my $res = Hijk::request({
            host            => 'u.nix.is',
            port            => 80,
            connect_timeout => 3,
            read_timeout    => 3,
            path            => "/?Hijk_test_nr=$i",
            head   => [
                "X-Request-Nr" => $i,
                "Referer" => "Hijk (file:" . __FILE__ . "; iteration: $i)",
            ],

        });

        ok !exists($res->{error}), '$res->{error} does not exist, because we do not expect connect timeout to happen';
        cmp_ok $res->{status}, '==', 200, "We got a 200 OK response";
        if (exists $res->{head}->{Connection} and $res->{head}->{Connection} eq 'close') {
            cmp_ok scalar(keys %{$Hijk::SOCKET_CACHE}), '==', 0, "We were told to close the connection. We should have no entry in the socket cache";
        } else {
            cmp_ok scalar(keys %{$Hijk::SOCKET_CACHE}), '==', 1, "We have an entry in the global socket cache";
        }
    } "We could make request number $i";
}

done_testing;