Changeset 69

Show
Ignore:
Timestamp:
11/25/09 00:40:40 (5 years ago)
Author:
clinton
Message:

Add upload tests tid10737 tid10892

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/t/lib/MungoTestUtils.pm

    r65 r69  
    1111use Test::More import => [qw(is ok like unlike $TODO)]; 
    1212use Test::WWW::Mechanize qw(); 
    13 use Data::Dumper
     13use File::Temp qw(tempfile)
    1414 
    1515 
     
    126126} 
    127127 
     128=head2 $path = make_dummy_file($size_in_bytes, $binary); 
     129 
     130Makes a file filled with random numbers.  Returns the absolute path to the file. 
     131 
     132=cut 
     133 
     134push @EXPORT, 'make_dummy_file'; 
     135sub make_dummy_file { 
     136    my $desired_size = shift; 
     137    my $binary = shift || 0; 
     138    my $handle = File::Temp->new(UNLINK => 0); # Set to 0 to leave the file hanging around 
     139    #my $handle = File::Temp->new(UNLINK => 1); 
     140    my $name = $handle->filename(); 
     141 
     142    unless ($desired_size) { 
     143        close $handle; 
     144        return $name; 
     145    } 
     146    my $begin = "BEGIN MARKER\n"; 
     147    my $begin_length = length($begin); 
     148    my $end = "END MARKER\n"; 
     149    $desired_size = $desired_size - length($begin) - length($end); 
     150    print $handle $begin; 
     151    if ($binary) { 
     152        $desired_size--; # Needed because echo will add a newline before and after 
     153        close $handle; 
     154        system("/bin/dd if=/dev/urandom of=$name count=$desired_size bs=1 seek=$begin_length conv=fsync status=noxfer 2> /dev/null"); 
     155        system("/bin/echo '$end' >> $name"); 
     156    } else { 
     157        my $remaining = $desired_size; 
     158        while ($remaining >= 10240) { 
     159            print $handle ('X' x 10239) . "\n"; 
     160            $remaining -= 10240; 
     161        } 
     162        print $handle 'X' x $remaining; 
     163        print $handle $end; 
     164        close $handle; 
     165    } 
     166 
     167    return $name; 
     168} 
    128169 
    1291701;