File: 36_inactivity_timeout.t

package info (click to toggle)
libfurl-perl 3.14-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 660 kB
  • sloc: perl: 2,188; makefile: 5; sh: 1
file content (61 lines) | stat: -rw-r--r-- 1,341 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
61
use strict;
use warnings;
use Socket qw(inet_aton pack_sockaddr_in);
use Test::More;
use Test::TCP;
use Test::Requires qw(HTTP::Server::PSGI);

use Furl::HTTP;
use FindBin;
use lib "$FindBin::Bin/../..";
use t::Slowloris;

test_tcp(
	server => sub {
		my $port = shift;
		$Slowloris::SleepBeforeWrite = 1;
		Slowloris::Server->new(port => $port)->run(sub {
			my $env = shift;
			return [ 200,
				[],
				[ "hello" ]
			];
		});
	},
	client => sub {
		my $port = shift;

		# should not timeout
		my $furl = Furl::HTTP->new(
			timeout => 10,
			inactivity_timeout => 10,
		);
		my $start = time;
		my ($minor_version, $code, $msg, $headers, $body) = $furl->request(
			method     => "GET",
			host       => "127.0.0.1",
			port       => $port,
			path_query => "/",
		);
		is $code, 200, "status code:inactivity_timeout=10";
		is $body, "hello", "content:inactivity_timeout=10";
		diag "took @{[time - $start]} seconds";

		# should timeout
		$furl = Furl::HTTP->new(
			timeout            => 10,
			inactivity_timeout => 0.5,
		);
		$start = time;
		($minor_version, $code, $msg, $headers, $body) = $furl->request(
			method     => "GET",
			host       => "127.0.0.1",
			port       => $port,
			path_query => "/",
		);
		is $code, 500, "status code:inactivity_timeout=0.5";
		diag "took @{[time - $start]} seconds";
	},
);

done_testing;