File: static.pl

package info (click to toggle)
uwsgi 2.0.31-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,564 kB
  • sloc: ansic: 87,066; python: 7,004; cpp: 1,133; java: 708; perl: 678; sh: 585; ruby: 555; makefile: 148; xml: 130; cs: 121; objc: 37; php: 28; erlang: 20; javascript: 11
file content (82 lines) | stat: -rw-r--r-- 1,857 bytes parent folder | download | duplicates (8)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
use IO::Socket::INET;
use Digest::MD5 qw(md5) ;

$NUM = 50;

my @commands;

push @commands, "./uwsgi --http-socket :9191 --disable-logging --static-offload-to-thread 64 --static-map /foobar=./t_foobar.txt --pidfile ./t_foobar.pid &";
push @commands, "./uwsgi --http-socket :9191 --disable-logging -M -p 4 --static-offload-to-thread 64 --static-map /foobar=./t_foobar.txt --pidfile ./t_foobar.pid &";
push @commands, "./uwsgi --http :9191 --disable-logging --static-map /foobar=./t_foobar.txt --static-offload-to-thread 64 --pidfile ./t_foobar.pid &";

print "generating random data for the test...\n";

my $content = generate_random_content(1024*1024);
my $first_digest = md5($content);

open FOOBAR,'>t_foobar.txt';
print FOOBAR $content;
close FOOBAR;

foreach my $cmd(@commands) {

	system $cmd;
	sleep(1);


	my @s;

	print "sending requests to uWSGI...\n";

	for(my $i=0;$i<$NUM;$i++) {
		$s[$i] = IO::Socket::INET->new(PeerAddr => '127.0.0.1', PeerPort => 9191);	
		$s[$i]->send("GET /foobar HTTP/1.0\r\nHost: 127.0.0.1:9191\r\n\r\n");
	}

	my @body;

	print "receiving responses from uWSGI...\n";

	while(1) {
		$end = 0;
		for(my $i=0;$i<$NUM;$i++) {
			$s[$i]->recv(my $buf, 32768);
			$end++ unless $buf;
			$body[$i].=$buf;
		}
		last if $end >= $NUM;
	}

	print "checking uWSGI responses...\n";

	foreach my $data (@body) {
		$data =~ s/^(.|\n|\r)*\r\n\r\n//m;
		if (md5($data) ne $first_digest) {
			end_test("md5 does not match");
		}
	}

	system('kill -INT `cat t_foobar.pid`');

	sleep(3);
}

print "TEST PASSED\n";

sub generate_random_content {
	my $size = shift;
	my @chars=('a'..'z','A'..'Z','0'..'9');
	my $random_string = '';
	foreach (1..$size) {
		$random_string.=$chars[rand @chars];
	}

	return $random_string;
}

sub end_test {
	my $msg = shift;
	print 'TEST FAILED: '.$msg."\n";
	system('kill -INT `cat t_foobar.pid`');
	exit;
}