-
Notifications
You must be signed in to change notification settings - Fork 2
/
scan_tests.php
123 lines (113 loc) · 4.03 KB
/
scan_tests.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
include './archive_common.php.inc';
$UTC = new DateTimeZone('UTC');
$now = time();
// State of the various crawls
UpdateCrawlState();
checkDone();
// See if the crawls are done
function checkDone() {
global $gMysqlServer;
global $gMysqlDb;
global $gMysqlUsername;
global $gMysqlPassword;
$db = mysqli_connect($gMysqlServer, $gMysqlUsername, $gMysqlPassword);
if (mysqli_select_db($db, $gMysqlDb)) {
$result = mysqli_query($db, "select * from crawls where finishedDateTime is NULL;");
if ($result !== false) {
$rowcount = mysqli_num_rows($result);
echo "$rowcount crawl(s) still running.\n";
if ($rowcount == 0) {
$crawls_file = __DIR__ . '/crawls.json';
if (file_exists($crawls_file)) {
$crawls = json_decode(file_get_contents($crawls_file), true);
if (isset($crawls) && is_array($crawls) && count($crawls) && !isset($crawls['done'])) {
echo "Marking crawls as done.\n";
$crawls['done'] = true;
file_put_contents($crawls_file, json_encode($crawls));
}
}
}
}
mysqli_close($db);
}
}
/**
* Update the state of the current crawl
*
*/
function UpdateCrawlState() {
$ret = false;
global $gMysqlServer;
global $gMysqlDb;
global $gMysqlUsername;
global $gMysqlPassword;
global $statusTables;
echo "Updating crawl status...\n";
$db = mysqli_connect($gMysqlServer, $gMysqlUsername, $gMysqlPassword);
if (mysqli_select_db($db, $gMysqlDb)) {
$crawl_names = array();
// Build a list of the crawl names by ID
$result = mysqli_query($db, "SELECT crawlid,label,location FROM crawls;");
if ($result !== false) {
while ($row = mysqli_fetch_assoc($result)) {
$id = $row['crawlid'];
$type = $row['location'];
if ($type == 'IE8')
$type = 'IE';
elseif ($type == 'iphone4')
$type = 'iOS';
elseif ($type == 'California:Chrome')
$type = 'chrome';
elseif ($type == 'California2:Chrome.3G')
$type = 'android';
$crawl_names[$id] = str_replace(' ', '_', $type) . '-' . str_replace(' ', '_', $row['label']);
}
}
// Get the status of all of the tests in all of the crawls
foreach ($statusTables as $table) {
$result = mysqli_query($db, "SELECT wptid,status,crawlid FROM $table WHERE status >= 4;");
if ($result !== false) {
$ret = true;
while ($row = mysqli_fetch_assoc($result)) {
$id = $row['wptid'];
$status = $row['status'];
$crawl = $row['crawlid'];
if (isset($id) && strlen($id)) {
// Mark the test itself directly
$test_path = './' . GetTestPath($id);
if ($status >= 4 && is_dir($test_path) && !file_exists("$test_path/.ha_complete")) {
// delete some test files that we don't need to keep
$files = array('1_debug.log', '1_devtools.json.gz', '1_trace.json.gz', '1_netlog_requests.json.gz');
foreach ($files as $file) {
if (file_exists("$test_path/$file")) {
unlink("$test_path/$file");
}
}
$name = 'UNKNOWN';
if (isset($crawl_names[$crawl])) {
$name = $crawl_names[$crawl];
file_put_contents("$test_path/.ha_crawl", $name);
}
if ($status == 4) {
file_put_contents("$test_path/.ha_success", '');
} else {
// We won't upload the HAR so make sure it gets marked as done
file_put_contents("$test_path/.ha_har", '');
}
file_put_contents("$test_path/.ha_complete", '');
echo "Marking test $id for crawl $name as complete\n";
}
}
}
}
}
mysqli_close($db);
}
if (!$ret) {
echo "\nFailed to query pending tests\n";
exit(1);
}
return $ret;
}
?>