File: eagain.t

package info (click to toggle)
speedy-cgi-perl 2.22-4
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,128 kB
  • ctags: 890
  • sloc: ansic: 4,487; sh: 1,105; perl: 945; makefile: 89
file content (59 lines) | stat: -rwxr-xr-x 1,395 bytes parent folder | download | duplicates (4)
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

# In rev 1.7.2 speedy forgot to check for EAGAIN after doing a write
# on a non-blocking file descriptor.

# Also run the test for stdin, since read is in different code.  Since stderr
# is done with the same code as stdout, so no need for a separate test for it.


my $num		= 10000;
my $tmp         = "/tmp/speedy_eagain.$$";
my $sleeplen	= 5;

$SIG{PIPE} = IGNORE;

print "1..2\n";

&do_test(0);
&do_test(1);

sub do_test { my($do_stdin) = @_;

    # Write a list of numbers to the script.
    if ($do_stdin) {
	open(F, "| $ENV{SPEEDY} t/scripts/stdio 0 >$tmp");
    } else {
	open(F, ">$tmp");
    }
    for (my $i = 1; $i < $num; ++$i) {
	print F "$i\n";
	# Sleep in the middle of sending data.  Should cause an error if
	# the bug is present.
	sleep($sleeplen) if ($do_stdin && $i == $num/2);
    }
    close(F);

    # Read the numbers back from the script.  Should get the same list.
    my $ok = 1;
    if ($do_stdin) {
	open(F, "<$tmp");
    } else {
	open(F, "$ENV{SPEEDY} t/scripts/stdio 0 <$tmp |");
    }
    for (my $i = 1; $i < $num; ++$i) {
	$_ = <F>;
	#print STDERR "Got $_";

	# Sleep halfway through, and if bug is present we should get an error
	# because the buffer is flushed instead of being retried.
	sleep($sleeplen) if (!$do_stdin && $_ == $num/2);

	if ($_ != $i) {
	    $ok = 0; last;
	}
    }
    close(F);
    print $ok ? "ok\n" : "not ok\n";

    unlink($tmp);
}