Permalink
Browse files

tests: loop on short binary packet reads

Awesome bug goes like this:

let "c1" be the commit of the "good state" and "c2" be the commit
immediately after (in a bad state).  "t1" is the state of the tree in "c1"
and "t2" is the state of the tree in "c2"

In their natural states, we have this:

c1 -> t1 -> success
c1 -> t2 -> fail

However, if you take

c1 -> t1 -> patch to t2 -> success
c2 -> t2 -> patch to t1 -> fail

So t1 *and* t2 both succeed if the committed tree is c1, but both fail of
the committed tree is c2.

The difference?  c1 has a tag that points to it so the version number is
"1.2.10" whereas the version number for the unreleased c2 is
"1.4.10-1-gee486ab" -- a bit longer, breaks stuff in tests that try to
print stats.
  • Loading branch information...
1 parent 97354c3 commit 85db132d127a42ccc2bcdef447813fa8895307ae @dustin dustin committed Jan 26, 2012
Showing with 7 additions and 3 deletions.
  1. +7 −3 t/binary.t
View
10 t/binary.t
@@ -573,11 +573,15 @@ sub _handle_single_response {
my $self = shift;
my $myopaque = shift;
- $self->{socket}->recv(my $response, ::MIN_RECV_BYTES);
- Test::More::is(length($response), ::MIN_RECV_BYTES, "Expected read length");
+ my $hdr = "";
+ while(::MIN_RECV_BYTES - length($hdr) > 0) {
+ $self->{socket}->recv(my $response, ::MIN_RECV_BYTES - length($hdr));
+ $hdr .= $response;
+ }
+ Test::More::is(length($hdr), ::MIN_RECV_BYTES, "Expected read length");
my ($magic, $cmd, $keylen, $extralen, $datatype, $status, $remaining,
- $opaque, $ident_hi, $ident_lo) = unpack(::RES_PKT_FMT, $response);
+ $opaque, $ident_hi, $ident_lo) = unpack(::RES_PKT_FMT, $hdr);
Test::More::is($magic, ::RES_MAGIC, "Got proper response magic");
my $cas = ($ident_hi * 2 ** 32) + $ident_lo;

0 comments on commit 85db132

Please sign in to comment.