2002-11-15 00:28:55 +00:00
#! /usr/local/bin/php
< ? php
//This tests the persistent file transfers for download and upload. It interrupts them in the middle and makes sure that the filesize never decreases along interrupted transfers.
include_once ( " test.inc " );
set_time_limit ( 10000000000 );
$project = new Project ;
$user = new User ();
$host = new Host ( $user );
$app = new App ( " upper_case " );
$app_version = new App_Version ( $app );
$project -> add_user ( $user );
$project -> add_app ( $app );
$project -> add_app_version ( $app_version );
$project -> install (); // must install projects before adding to hosts
$host -> log_flags = " log_flags.xml " ;
$host -> add_project ( $project );
$host -> install ();
echo " adding work \n " ;
$work = new Work ( $app );
$work -> wu_template = " uc_wu " ;
$work -> result_template = " uc_result " ;
2002-12-05 19:13:06 +00:00
$work -> redundancy = 2 ;
2002-11-15 00:28:55 +00:00
array_push ( $work -> input_files , " input " );
$work -> install ( $project );
$project -> start_feeder ();
//get the path for checking download
2003-06-11 22:11:32 +00:00
$source_dir = SRC_DIR ;
2002-11-15 00:28:55 +00:00
$enc_url = strtr ( $project -> master_url , " / " , " _ " );
$enc_url = substr ( $enc_url , 7 , strlen ( $enc_url ));
$path = " $host->host_dir /projects/ $enc_url /upper_case " ;
print " \n the path for checking download is : " . $path ;
$pid = $host -> run_asynch ( " -exit_when_idle -limit_transfer_rate 2048 " );
2003-06-11 22:11:32 +00:00
$client_pid = $host -> get_new_client_pid ( null );
2002-11-15 00:28:55 +00:00
assert ( $pid != - 1 );
$first = 0 ;
$file_size = 0 ;
//Check download
2002-11-22 22:10:13 +00:00
2002-11-15 00:28:55 +00:00
while ( 1 )
{
2003-06-11 22:11:32 +00:00
2002-11-15 00:28:55 +00:00
if ( file_exists ( $path ))
{
$temp = filesize ( $path );
if ( $temp < $file_size )
{
echo " \n filesize dropped, problem downloading \n " ;
echo " temp is $temp , file_size is $file_size\n " ;
break ;
}
2003-06-11 22:11:32 +00:00
2002-11-15 00:28:55 +00:00
else if ( $temp > $file_size )
{
print " \n filesize increased, it is : " . $temp ;
if (( $temp > 40000 ) && ( $first == 0 ))
{
print " \n stopping and rerunning the client " ;
2002-11-22 22:10:13 +00:00
echo " \n now killing client_pid : $client_pid " ;
$host -> kill ( $client_pid , null );
2002-11-15 00:28:55 +00:00
$host -> run_asynch ( " -exit_when_idle -limit_transfer_rate 2048 " );
2002-11-22 22:10:13 +00:00
$client_pid = $host -> get_new_client_pid ( $client_pid );
echo " \n Now executing : $client_pid " ;
2002-11-15 00:28:55 +00:00
$first ++ ;
}
2003-06-11 22:11:32 +00:00
2002-11-15 00:28:55 +00:00
}
2003-06-11 22:11:32 +00:00
$file_size = $temp ;
2002-11-15 00:28:55 +00:00
if ( $file_size == filesize ( " $source_dir /apps/upper_case " ))
{
echo " \n download test succeeded " ;
break ;
}
}
}
2003-06-11 22:11:32 +00:00
2002-11-15 00:28:55 +00:00
$file_size = 0 ;
$path = " $project->project_dir /upload/uc_wu_0_0 " ;
$first = 0 ;
print " \n upload path is: " . $path ;
echo " \n Now checking upload " ;
while ( 1 )
{
// echo "\n checking upload";
2003-06-11 22:11:32 +00:00
2002-11-15 00:28:55 +00:00
if ( file_exists ( $path ))
{
2003-06-11 22:11:32 +00:00
2002-11-15 00:28:55 +00:00
// echo "\nfile exists is download";
$temp = filesize ( $path );
if ( $temp < $file_size )
{
echo " \n filesize dropped, problem uploading \n " ;
echo " temp is $temp , file_size if $file_size\n " ;
break ;
}
if ( $temp > $file_size )
{
print " \n filesize increased, it is : " . $temp ;
if (( $temp > 20000 ) && ( $first == 0 ))
{
print " \n stopping and rerunning the client " ;
2002-11-22 22:10:13 +00:00
print " \n killing $client_pid " ;
$host -> kill ( $client_pid , null );
2002-11-15 00:28:55 +00:00
$host -> run_asynch ( " -exit_when_idle -limit_transfer_rate 2048 " );
2002-11-22 22:10:13 +00:00
$client_pid = $host -> get_new_client_pid ( $client_pid );
echo " \n new client_pid is $client_pid " ;
2002-11-15 00:28:55 +00:00
$first ++ ;
}
2003-06-11 22:11:32 +00:00
}
2002-11-15 00:28:55 +00:00
$file_size = $temp ;
if ( $file_size == filesize ( " $source_dir /test/uc_correct_output " ))
{
print " \n all of the files has been uploaded " ;
print " \n stopping and rerunning the client " ;
2002-11-22 22:10:13 +00:00
$host -> kill ( $client_pid , null );
2002-11-15 00:28:55 +00:00
$host -> run ( " -exit_when_idle " );
break ;
}
}
}
$project -> stop ();
2003-06-11 23:09:11 +00:00
$result -> server_state = RESULT_SERVER_STATE_OVER ;
2002-11-15 00:28:55 +00:00
$result -> stderr_out = " APP: upper_case: starting, argc 1 " ;
$result -> exit_status = 0 ;
$project -> check_results ( 2 , $result );
$project -> compare_file ( " uc_wu_0_0 " , " uc_correct_output " );
$project -> compare_file ( " uc_wu_1_0 " , " uc_correct_output " );
?>