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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines