ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/t/80_ssltest.t
(Generate patch)

Comparing AnyEvent/t/80_ssltest.t (file contents):
Revision 1.5 by root, Sat Jul 18 00:05:29 2009 UTC vs.
Revision 1.9 by root, Mon Sep 5 07:21:55 2011 UTC

1#!/usr/bin/perl 1#!/usr/bin/perl
2 2
3BEGIN { eval "use Net::SSLeay (); 1" or ((print "1..0 # SKIP no Net::SSLeay\n"), exit 0) } 3BEGIN { eval "use Net::SSLeay 1.33 (); 1" or ((print "1..0 # SKIP no usable Net::SSLeay\n"), exit 0) }
4 4
5use Test::More tests => 410; 5use Test::More tests => 415;
6 6
7no warnings;
7use strict qw(vars subs); 8use strict qw(vars subs);
8 9
9use AnyEvent::Socket; 10use AnyEvent::Socket;
10use AnyEvent::Handle; 11use AnyEvent::Handle;
11use AnyEvent::TLS; 12use AnyEvent::TLS;
12 13
13my $ctx = new AnyEvent::TLS cert_file => $0; 14my $ctx = new AnyEvent::TLS cert_file => $0;
14 15
15for my $mode (1..5) { 16for my $mode (1..5) {
17 ok (1, "mode $mode");
18
16 my $server_done = AnyEvent->condvar; 19 my $server_done = AnyEvent->condvar;
17 my $client_done = AnyEvent->condvar; 20 my $client_done = AnyEvent->condvar;
18 21
19 my $server_port = AnyEvent->condvar; 22 my $server_port = AnyEvent->condvar;
20 23
80 83
81 }, sub { 84 }, sub {
82 $server_port->send ($_[2]); 85 $server_port->send ($_[2]);
83 }; 86 };
84 87
85 tcp_connect "localhost", $server_port->recv, sub { 88 my $hd; $hd = new AnyEvent::Handle
86 my ($fh) = @_; 89 connect => ["127.0.0.1", $server_port->recv],
90 tls => "connect",
91 tls_ctx => $ctx,
92 timeout => 8,
93 on_connect => sub {
94 ok (1, "client_connect $mode");
95 },
96 on_error => sub {
97 ok (0, "client_error <$!>");
98 $client_done->send; undef $hd;
99 },
100 on_eof => sub {
101 ok (1, "client_eof");
102 $client_done->send; undef $hd;
103 };
87 104
88 ok (1, "client_connect $mode"); 105 if ($mode == 1) {
89 106 $hd->push_write ("1\n");
90 my $hd; $hd = new AnyEvent::Handle 107 $hd->on_drain (sub {
91 tls => "connect",
92 tls_ctx => $ctx,
93 fh => $fh,
94 timeout => 8,
95 on_error => sub {
96 ok (0, "client_error <$!>"); 108 ok (1, "client_drain");
97 $client_done->send; undef $hd; 109 $client_done->send; undef $hd;
98 },
99 on_eof => sub {
100 ok (1, "client_eof");
101 $client_done->send; undef $hd;
102 }; 110 });
103
104 if ($mode == 1) { 111 } elsif ($mode == 2) {
112 $hd->push_read (line => sub {
113 ok ($_[1] eq "2", "line 2 <$_[1]>");
114 });
115 } elsif ($mode == 3) {
116 $hd->push_write ("3\n");
117 $hd->push_read (line => sub {
118 ok ($_[1] eq "4", "line 4 <$_[1]>");
119 });
120 } elsif ($mode == 4) {
121 $hd->push_read (line => sub {
122 ok ($_[1] eq "5", "line 5 <$_[1]>");
105 $hd->push_write ("1\n"); 123 $hd->push_write ("6\n");
106 $hd->on_drain (sub { 124 $hd->on_drain (sub {
107 ok (1, "client_drain"); 125 ok (1, "client_drain");
108 $client_done->send; undef $hd; 126 $client_done->send; undef $hd;
109 }); 127 });
128 });
110 } elsif ($mode == 2) { 129 } elsif ($mode == 5) {
130 # some randomly-sized blocks
131 srand 0;
132 my $cnt = 64;
133 my $block; $block = sub {
134 my $len = (16 << int rand 14) - 16 + int rand 32;
135 ok (1, "write $len");
136 $hd->push_write ("$len\n");
137 $hd->push_write (packstring => "N", "\x00" x $len);
138 };
139
140 for my $i (1..$cnt) {
111 $hd->push_read (line => sub { 141 $hd->push_read (line => sub {
112 ok ($_[1] eq "2", "line 2 <$_[1]>"); 142 my ($i, $cnt, $block) = ($i, $cnt, $block); # 5.8.9. bug workaround
113 }); 143 my $len = $_[1];
114 } elsif ($mode == 3) { 144 ok (1, "client block $len/1");
115 $hd->push_write ("3\n");
116 $hd->push_read (line => sub { 145 $hd->unshift_read (packstring => "N", sub {
117 ok ($_[1] eq "4", "line 4 <$_[1]>"); 146 ok ($len == length $_[1], "client block $len/2");
118 }); 147
119 } elsif ($mode == 4) { 148 if ($i != $cnt) {
120 $hd->push_read (line => sub { 149 $block->();
121 ok ($_[1] eq "5", "line 5 <$_[1]>"); 150 } else {
122 $hd->push_write ("6\n");
123 $hd->on_drain (sub {
124 ok (1, "client_drain"); 151 ok (1, "client_drain 5");
125 $client_done->send; undef $hd; 152 $client_done->send; undef $hd;
153 }
126 }); 154 });
127 }); 155 });
128 } elsif ($mode == 5) {
129 # some randomly-sized blocks
130 srand 0;
131 my $cnt = 64;
132 my $block; $block = sub {
133 my $len = (16 << int rand 14) - 16 + int rand 32;
134 ok (1, "write $len");
135 $hd->push_write ("$len\n");
136 $hd->push_write (packstring => "N", "\x00" x $len);
137 }; 156 }
138 157
139 for my $i (1..$cnt) {
140 $hd->push_read (line => sub {
141 my $len = $_[1];
142 ok (1, "client block $len/1");
143 $hd->unshift_read (packstring => "N", sub {
144 ok ($len == length $_[1], "client block $len/2");
145
146 if ($i != $cnt) {
147 $block->();
148 } else {
149 ok (1, "client_drain");
150 $client_done->send; undef $hd;
151 }
152 });
153 });
154 }
155
156 $block->(); 158 $block->();
157 }
158 }; 159 }
159 160
160 $server_done->recv; 161 $server_done->recv;
161 $client_done->recv; 162 $client_done->recv;
162} 163}
163 164

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines