Mercurial > hg > nginx-tests
comparison spdy.t @ 581:8593f34a12e5
Tests: fixed spdy tests hang on win32.
Rewrote spdy_read()/raw_read() using IO::Select since the blocking system
calls cannot be interrupted with alarm() on win32 due to portability issues.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Mon, 18 May 2015 20:40:48 +0300 |
parents | 2cd00179f4b2 |
children | 6cdfd177319b |
comparison
equal
deleted
inserted
replaced
580:fa71c725d40a | 581:8593f34a12e5 |
---|---|
569 TODO: { | 569 TODO: { |
570 local $TODO = 'not yet'; | 570 local $TODO = 'not yet'; |
571 | 571 |
572 $sess = new_session(); | 572 $sess = new_session(); |
573 spdy_stream($sess, { path => '/s' }, 2); | 573 spdy_stream($sess, { path => '/s' }, 2); |
574 $frames = spdy_read($sess); | 574 $frames = spdy_read($sess, all => [{ type => 'GOAWAY' }]); |
575 | 575 |
576 ($frame) = grep { $_->{type} eq "GOAWAY" } @$frames; | 576 ($frame) = grep { $_->{type} eq "GOAWAY" } @$frames; |
577 ok($frame, 'even stream - GOAWAY frame'); | 577 ok($frame, 'even stream - GOAWAY frame'); |
578 is($frame->{code}, 1, 'even stream - error code'); | 578 is($frame->{code}, 1, 'even stream - error code'); |
579 is($frame->{sid}, 0, 'even stream - last used stream'); | 579 is($frame->{sid}, 0, 'even stream - last used stream'); |
585 TODO: { | 585 TODO: { |
586 local $TODO = 'not yet'; | 586 local $TODO = 'not yet'; |
587 | 587 |
588 $sess = new_session(); | 588 $sess = new_session(); |
589 $sid1 = spdy_stream($sess, { path => '/s' }, 3); | 589 $sid1 = spdy_stream($sess, { path => '/s' }, 3); |
590 spdy_read($sess); | 590 spdy_read($sess, all => [{ type => 'GOAWAY' }]); |
591 | 591 |
592 $sid2 = spdy_stream($sess, { path => '/s' }, 1); | 592 $sid2 = spdy_stream($sess, { path => '/s' }, 1); |
593 $frames = spdy_read($sess); | 593 $frames = spdy_read($sess, all => [{ type => 'GOAWAY' }]); |
594 | 594 |
595 ($frame) = grep { $_->{type} eq "GOAWAY" } @$frames; | 595 ($frame) = grep { $_->{type} eq "GOAWAY" } @$frames; |
596 ok($frame, 'backward stream - GOAWAY frame'); | 596 ok($frame, 'backward stream - GOAWAY frame'); |
597 is($frame->{code}, 1, 'backward stream - error code'); | 597 is($frame->{code}, 1, 'backward stream - error code'); |
598 is($frame->{sid}, $sid1, 'backward stream - last used stream'); | 598 is($frame->{sid}, $sid1, 'backward stream - last used stream'); |
606 | 606 |
607 $sess = new_session(); | 607 $sess = new_session(); |
608 $sid1 = spdy_stream($sess, { path => '/s' }, 3); | 608 $sid1 = spdy_stream($sess, { path => '/s' }, 3); |
609 spdy_read($sess, all => [{ sid => $sid1, fin => 1 }]); | 609 spdy_read($sess, all => [{ sid => $sid1, fin => 1 }]); |
610 $sid2 = spdy_stream($sess, { path => '/s' }, 3); | 610 $sid2 = spdy_stream($sess, { path => '/s' }, 3); |
611 $frames = spdy_read($sess); | 611 $frames = spdy_read($sess, all => [{ type => 'RST_STREAM' }]); |
612 | 612 |
613 ($frame) = grep { $_->{type} eq "RST_STREAM" } @$frames; | 613 ($frame) = grep { $_->{type} eq "RST_STREAM" } @$frames; |
614 ok($frame, 'dup stream - RST_STREAM frame'); | 614 ok($frame, 'dup stream - RST_STREAM frame'); |
615 is($frame->{code}, 1, 'dup stream - error code'); | 615 is($frame->{code}, 1, 'dup stream - error code'); |
616 is($frame->{sid}, $sid1, 'dup stream - stream'); | 616 is($frame->{sid}, $sid1, 'dup stream - stream'); |
640 $t->stop(); | 640 $t->stop(); |
641 | 641 |
642 TODO: { | 642 TODO: { |
643 local $TODO = 'not yet'; | 643 local $TODO = 'not yet'; |
644 | 644 |
645 $frames = spdy_read($sess); | 645 $frames = spdy_read($sess, all => [{ type => 'RST_STREAM' }]); |
646 | 646 |
647 ($frame) = grep { $_->{type} eq "GOAWAY" } @$frames; | 647 ($frame) = grep { $_->{type} eq "GOAWAY" } @$frames; |
648 ok($frame, 'GOAWAY on connection close'); | 648 ok($frame, 'GOAWAY on connection close'); |
649 | 649 |
650 } | 650 } |
685 my ($sess, %extra) = @_; | 685 my ($sess, %extra) = @_; |
686 my ($length, @got); | 686 my ($length, @got); |
687 my $s = $sess->{socket}; | 687 my $s = $sess->{socket}; |
688 my $buf = ''; | 688 my $buf = ''; |
689 | 689 |
690 eval { | 690 while (1) { |
691 local $SIG{ALRM} = sub { die "timeout\n" }; | |
692 local $SIG{PIPE} = sub { die "sigpipe\n" }; | |
693 again: | |
694 alarm(1); | |
695 | |
696 $buf = raw_read($s, $buf, 8); | 691 $buf = raw_read($s, $buf, 8); |
692 last unless length $buf; | |
697 | 693 |
698 my $type = unpack("B", $buf); | 694 my $type = unpack("B", $buf); |
699 $length = 8 + hex unpack("x5 H6", $buf); | 695 $length = 8 + hex unpack("x5 H6", $buf); |
700 $buf = raw_read($s, $buf, $length); | 696 $buf = raw_read($s, $buf, $length); |
697 last unless length $buf; | |
701 | 698 |
702 if ($type == 0) { | 699 if ($type == 0) { |
703 push @got, dframe($buf); | 700 push @got, dframe($buf); |
704 | 701 |
705 } else { | 702 } else { |
706 my $ctype = unpack("x2 n", $buf); | 703 my $ctype = unpack("x2 n", $buf); |
707 push @got, $cframe{$ctype}($sess, $buf); | 704 push @got, $cframe{$ctype}($sess, $buf); |
708 } | 705 } |
709 $buf = substr($buf, $length); | 706 $buf = substr($buf, $length); |
710 | 707 |
711 goto again if test_fin($got[-1], $extra{all}); | 708 last unless test_fin($got[-1], $extra{all}); |
712 alarm(0); | |
713 }; | 709 }; |
714 alarm(0); | |
715 return \@got; | 710 return \@got; |
716 } | 711 } |
717 | 712 |
718 sub test_fin { | 713 sub test_fin { |
719 my ($frame, $all) = @_; | 714 my ($frame, $all) = @_; |
955 | 950 |
956 sub raw_read { | 951 sub raw_read { |
957 my ($s, $buf, $len) = @_; | 952 my ($s, $buf, $len) = @_; |
958 my $got = ''; | 953 my $got = ''; |
959 | 954 |
960 while (length($buf) < $len) { | 955 while (length($buf) < $len && IO::Select->new($s)->can_read(1)) { |
961 $s->sysread($got, $len - length($buf)) or die; | 956 $s->sysread($got, $len - length($buf)) or last; |
962 log_in($got); | 957 log_in($got); |
963 $buf .= $got; | 958 $buf .= $got; |
964 } | 959 } |
965 return $buf; | 960 return $buf; |
966 } | 961 } |