Skip to content

Commit

Permalink
Merge pull request #1891 from WPO-Foundation/test-log-page-break
Browse files Browse the repository at this point in the history
fix(testlog): make test history more resilient
  • Loading branch information
jefflembeck authored May 25, 2022
2 parents 51a2561 + e14b54d commit 1488c1f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
16 changes: 11 additions & 5 deletions www/src/CPClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ class CPClient
public function __construct(string $host, array $options = [])
{
$auth_client_options = $options['auth_client_options'] ?? array();
$graphql_client_options = array();
$graphql_client_options = array(
'timeout' => 30,
'connect_timeout' => 30
);

$this->client_id = $auth_client_options['client_id'] ?? null;
$this->client_secret = $auth_client_options['client_secret'] ?? null;
Expand Down Expand Up @@ -510,12 +513,15 @@ public function getTestHistory(int $days = 1): array
'viewHours' => $view_hours
];

$test_history = [];
$response = $this->graphql_client->runQuery($gql, true, $variables);
$data = $response->getData()['wptTestHistory'];
foreach ($data as $record) {
$test_history[] = new TestRecord($record);
}
$test_history = array_map(function ($record): TestRecord {
try {
return new TestRecord($record);
} catch (\Exception $e) {
error_log($e->getMessage());
}
}, $data);
return $test_history;
}
}
7 changes: 4 additions & 3 deletions www/testlog.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

use WebPageTest\Util;

if ($admin || $privateInstall) {
$is_logged_in = Util::getSetting('cp_auth') && (!is_null($request_context->getClient()) && $request_context->getClient()->isAuthenticated());

if ($admin || $privateInstall || $is_logged_in) {
set_time_limit(0);
} else {
set_time_limit(60);
Expand All @@ -18,14 +20,13 @@
}

$test_history = [];
$is_logged_in = Util::getSetting('cp_auth') && (!is_null($request_context->getClient()) && $request_context->getClient()->isAuthenticated());
$days = (int)$_GET["days"];

if ($is_logged_in) {
$test_history = $request_context->getClient()->getTestHistory($days);
}

// Redirect logged-in users to the hosted test history if one is configured
// Redirect logged-in saml users to the hosted test history if one is configured
if (!$is_logged_in && (isset($USER_EMAIL) && Util::getSetting('history_url') && !isset($_REQUEST['local']))) {
header('Location: ' . Util::getSetting('history_url'));
exit;
Expand Down

0 comments on commit 1488c1f

Please sign in to comment.