Example #1
0
         } else {
             $ini = '';
         }
         $ini .= 'completed=' . gmdate('c') . "\r\n";
         file_put_contents($iniFile, $ini);
     }
 } else {
     $testInfo = GetTestInfo($id);
     if (!$testInfo || !array_key_exists('location', $testInfo)) {
         $testLock = LockTest($id);
         $testInfo = GetTestInfo($id);
         UnlockTest($testLock);
     }
     if ($testInfo && array_key_exists('location', $testInfo)) {
         $location = $testInfo['location'];
         $locKey = GetLocationKey($location);
         if (!strlen($locKey) || !strcmp($key, $locKey) || !strcmp($_SERVER['REMOTE_ADDR'], "127.0.0.1")) {
             $testErrorStr = '';
             if (array_key_exists('testerror', $_REQUEST) && strlen($_REQUEST['testerror'])) {
                 $testErrorStr = ', Test Error: "' . $_REQUEST['testerror'] . '"';
             }
             if (array_key_exists('error', $_REQUEST) && strlen($_REQUEST['error'])) {
                 $errorStr = ', Test Run Error: "' . $_REQUEST['error'] . '"';
             }
             logTestMsg($id, "Test Run Complete. Run: {$runNumber}, Cached: {$cacheWarmed}, Done: {$done}, Tester: {$tester}{$testErrorStr}{$errorStr}");
             $testLock = LockTest($id);
             $testInfo = GetTestInfo($id);
             // update the location time
             if (strlen($location)) {
                 if (!is_dir('./tmp')) {
                     mkdir('./tmp', 0777, true);
Example #2
0
/**
* Get an actual task to complete
* 
*/
function GetJob()
{
    $is_done = false;
    global $location;
    global $key;
    global $pc;
    global $ec2;
    global $tester;
    global $recover;
    global $is_json;
    global $dnsServers;
    $workDir = "./work/jobs/{$location}";
    $locKey = GetLocationKey($location);
    if (strpos($location, '..') == false && strpos($location, '\\') == false && strpos($location, '/') == false && (!strlen($locKey) || !strcmp($key, $locKey))) {
        if ($lock = LockLocation($location)) {
            $now = time();
            $testers = GetTesters($location, true);
            // make sure the tester isn't marked as offline (usually when shutting down EC2 instances)
            $testerCount = isset($testers['testers']) ? count($testers['testers']) : 0;
            $testerIndex = null;
            $offline = false;
            if ($testerCount) {
                if (strlen($ec2)) {
                    foreach ($testers['testers'] as $index => $testerInfo) {
                        if (isset($testerInfo['ec2']) && $testerInfo['ec2'] == $ec2 && isset($testerInfo['offline']) && $testerInfo['offline']) {
                            $offline = true;
                        }
                        break;
                    }
                }
                foreach ($testers['testers'] as $index => $testerInfo) {
                    if ($testerInfo['id'] == $tester) {
                        $testerIndex = $index;
                        break;
                    }
                }
            }
            if (!$offline) {
                $fileName = GetJobFile($workDir, $priority, $pc, $testerIndex, $testerCount);
                if (isset($fileName) && strlen($fileName)) {
                    $is_done = true;
                    $delete = true;
                    if ($is_json) {
                        header("Content-type: application/json");
                    } else {
                        header('Content-type: text/plain');
                    }
                    header("Cache-Control: no-cache, must-revalidate");
                    header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
                    // send the test info to the test agent
                    $testInfo = file_get_contents("{$workDir}/{$fileName}");
                    // extract the test ID from the job file
                    if (preg_match('/Test ID=([^\\r\\n]+)\\r/i', $testInfo, $matches)) {
                        $testId = trim($matches[1]);
                    }
                    if (isset($testId)) {
                        // figure out the path to the results
                        $testPath = './' . GetTestPath($testId);
                        // flag the test with the start time
                        $ini = file_get_contents("{$testPath}/testinfo.ini");
                        if (stripos($ini, 'startTime=') === false) {
                            $time = time();
                            $start = "[test]\r\nstartTime=" . gmdate("m/d/y G:i:s", $time);
                            $out = str_replace('[test]', $start, $ini);
                            file_put_contents("{$testPath}/testinfo.ini", $out);
                        }
                        $lock = LockTest($testId);
                        if ($lock) {
                            $testInfoJson = GetTestInfo($testId);
                            if ($testInfoJson) {
                                if (!array_key_exists('tester', $testInfoJson) || !strlen($testInfoJson['tester'])) {
                                    $testInfoJson['tester'] = $tester;
                                }
                                if (isset($dnsServers) && strlen($dnsServers)) {
                                    $testInfoJson['testerDNS'] = $dnsServers;
                                }
                                if (!array_key_exists('started', $testInfoJson) || !$testInfoJson['started']) {
                                    $testInfoJson['started'] = $time;
                                    logTestMsg($testId, "Starting test (initiated by tester {$tester})");
                                }
                                if (!array_key_exists('test_runs', $testInfoJson)) {
                                    $testInfoJson['test_runs'] = array();
                                }
                                for ($run = 1; $run <= $testInfoJson['runs']; $run++) {
                                    if (!array_key_exists($run, $testInfoJson['test_runs'])) {
                                        $testInfoJson['test_runs'][$run] = array('done' => false);
                                    }
                                }
                                $testInfoJson['id'] = $testId;
                                ProcessTestShard($testInfoJson, $testInfo, $delete);
                                SaveTestInfo($testId, $testInfoJson);
                            }
                            UnlockTest($lock);
                        }
                        file_put_contents("./tmp/last-test-{$location}-{$tester}.test", $testId);
                    }
                    if ($delete) {
                        unlink("{$workDir}/{$fileName}");
                    } else {
                        AddJobFileHead($workDir, $fileName, $priority, true);
                    }
                    if ($is_json) {
                        $testJson = array();
                        $script = '';
                        $isScript = false;
                        $lines = explode("\r\n", $testInfo);
                        foreach ($lines as $line) {
                            if (strlen(trim($line))) {
                                if ($isScript) {
                                    if (strlen($script)) {
                                        $script .= "\r\n";
                                    }
                                    $script .= $line;
                                } elseif (!strcasecmp($line, '[Script]')) {
                                    $isScript = true;
                                } else {
                                    $pos = strpos($line, '=');
                                    if ($pos !== false) {
                                        $key = trim(substr($line, 0, $pos));
                                        $value = trim(substr($line, $pos + 1));
                                        if (strlen($key) && strlen($value)) {
                                            if ($key == 'customMetric') {
                                                $pos = strpos($value, ':');
                                                if ($pos !== false) {
                                                    $metric = trim(substr($value, 0, $pos));
                                                    $code = base64_decode(substr($value, $pos + 1));
                                                    if ($code !== false && strlen($metric) && strlen($code)) {
                                                        if (!isset($testJson['customMetrics'])) {
                                                            $testJson['customMetrics'] = array();
                                                        }
                                                        $testJson['customMetrics'][$metric] = $code;
                                                    }
                                                }
                                            } elseif (is_numeric($value)) {
                                                $testJson[$key] = (int) $value;
                                            } else {
                                                $testJson[$key] = $value;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        if (strlen($script)) {
                            $testJson['script'] = $script;
                        }
                        echo json_encode($testJson);
                    } else {
                        echo $testInfo;
                    }
                    $ok = true;
                }
                // zero out the tracked page loads in case some got lost
                if (!$is_done && is_file("./tmp/{$location}.tests")) {
                    $tests = json_decode(file_get_contents("./tmp/{$location}.tests"), true);
                    if ($tests) {
                        $tests['tests'] = 0;
                        file_put_contents("./tmp/{$location}.tests", json_encode($tests));
                    }
                }
            }
            UnlockLocation($lock);
            // keep track of the last time this location reported in
            $testerInfo = array();
            $testerInfo['ip'] = $_SERVER['REMOTE_ADDR'];
            $testerInfo['pc'] = $pc;
            $testerInfo['ec2'] = $ec2;
            $testerInfo['ver'] = array_key_exists('version', $_GET) ? $_GET['version'] : $_GET['ver'];
            $testerInfo['freedisk'] = @$_GET['freedisk'];
            $testerInfo['ie'] = @$_GET['ie'];
            $testerInfo['dns'] = $dnsServers;
            $testerInfo['video'] = @$_GET['video'];
            $testerInfo['GPU'] = @$_GET['GPU'];
            $testerInfo['test'] = '';
            if (isset($testId)) {
                $testerInfo['test'] = $testId;
            }
            UpdateTester($location, $tester, $testerInfo);
        }
    }
    return $is_done;
}