#!/usr/bin/env perl
#testreq: personal
##**************************************************************
##
## Copyright (C) 1990-2007, Condor Team, Computer Sciences Department,
## University of Wisconsin-Madison, WI.
## 
## Licensed under the Apache License, Version 2.0 (the "License"); you
## may not use this file except in compliance with the License.  You may
## obtain a copy of the License at
## 
##    http://www.apache.org/licenses/LICENSE-2.0
## 
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
##
##**************************************************************


use CondorTest;
use File::Path;
use Check::SimpleJob;

$testname = "job_filexfer_sandbox-empty_van";

# How many seconds after the job terminates are we willing to wait to
# see if the directory is removed before we give up and consider it a
# failure? 
$dir_timeout = 20;

umask 0;

my $success = sub {
};

$OutputTest = sub
{
    my %info = @_;
    my $sandbox_dir;

    -z $info{"error"} ||
    die "$testname: FAILURE (STDERR contains data)\n";

    $output = $info{"output"};
    open( OUTPUT, "<$output" ) || die "Can't open $output: $!\n";
    while( <OUTPUT> ) {
        if( /sandbox: (.+)/ ) {
            $sandbox_dir = $1;
        } else {
            die "$testname: FAILURE (bad output to STDOUT)\n";
        }
    }
    $sandbox_dir || die "$testname: FAILURE (no sandbox dir in STDOUT)\n";

    for( $i=0; $i < $dir_timeout; $i++ ) {
	if( -d $sandbox_dir ) {
	    sleep( 1 );
	} else {
	    exit(0);
	}
    }
    die "$testname: FAILURE: $sandbox_dir still exists after " . $i . 
	" seconds\n";
};


SimpleJob::RunCheck(
    runthis=>"job_filexfer_sandbox-empty_van.pl",
    should_transfer_files=>"YES",
    when_to_transfer_output=>"ON_EXIT",
    on_success=>$success,
);

CondorTest::EndTest();
print scalar localtime() . "\n";

if( $result != 0 )
{
    exit(1);
}

CondorTest::debug("$testname SUCCESS\n",1);
exit(0);
