Bug 1453596 - [mochitest] Throw exception if path for server alive file doesn't exist.
MozReview-Commit-ID: AjjNbeOjTyr
--- a/testing/mochitest/server.js
+++ b/testing/mochitest/server.js
@@ -121,17 +121,17 @@ function runServer()
{
serverBasePath = __LOCATION__.parent;
server = createMochitestServer(serverBasePath);
//verify server address
//if a.b.c.d or 'localhost'
if (typeof(_SERVER_ADDR) != "undefined") {
if (_SERVER_ADDR == "localhost") {
- gServerAddress = _SERVER_ADDR;
+ gServerAddress = _SERVER_ADDR;
} else {
var quads = _SERVER_ADDR.split('.');
if (quads.length == 4) {
var invalid = false;
for (var i=0; i < 4; i++) {
if (quads[i] < 0 || quads[i] > 255)
invalid = true;
}
@@ -167,25 +167,27 @@ function runServer()
if (typeof(_PROFILE_PATH) == "undefined") {
serverAlive.initWithFile(serverBasePath);
serverAlive.append("mochitesttestingprofile");
} else {
serverAlive.initWithPath(_PROFILE_PATH);
}
- // If we're running outside of the test harness, there might
- // not be a test profile directory present
+ // Create a file to inform the harness that the server is ready
if (serverAlive.exists()) {
serverAlive.append("server_alive.txt");
foStream.init(serverAlive,
0x02 | 0x08 | 0x20, 436, 0); // write, create, truncate
var data = "It's alive!";
foStream.write(data, data.length);
foStream.close();
+ } else {
+ throw new Error("Failed to create server_alive.txt because " + serverAlive.path +
+ " could not be found.");
}
makeTags();
//
// The following is threading magic to spin an event loop -- this has to
// happen manually in xpcshell for the server to actually work.
//
@@ -299,17 +301,17 @@ function processLocations(server)
{
if (options.split(",").includes("primary"))
{
if (seenPrimary)
{
throw "Multiple primary locations in server-locations.txt, " +
"line " + lineno;
}
-
+
server.identity.setPrimary(scheme, host, port);
seenPrimary = true;
continue;
}
}
server.identity.add(scheme, host, port);
}
@@ -446,17 +448,17 @@ function isTest(filename, pattern)
return pattern.test(filename);
// File name is a URL style path to a test file, make sure that we check for
// tests that start with the appropriate prefix.
var testPrefix = typeof(_TEST_PREFIX) == "string" ? _TEST_PREFIX : "test_";
var testPattern = new RegExp("^" + testPrefix);
var pathPieces = filename.split('/');
-
+
return testPattern.test(pathPieces[pathPieces.length - 1]) &&
!filename.includes(".js") &&
!filename.includes(".css") &&
!/\^headers\^$/.test(filename);
}
/**
* Transform nested hashtables of paths to nested HTML lists.
@@ -466,17 +468,17 @@ function linksToListItems(links)
var response = "";
var children = "";
for (let link in links) {
const value = links[link];
var classVal = (!isTest(link) && !(value instanceof Object))
? "non-test invisible"
: "test";
if (value instanceof Object) {
- children = UL({class: "testdir"}, linksToListItems(value));
+ children = UL({class: "testdir"}, linksToListItems(value));
} else {
children = "";
}
var bug_title = link.match(/test_bug\S+/);
var bug_num = null;
if (bug_title != null) {
bug_num = bug_title[0].match(/\d+/);
@@ -751,10 +753,10 @@ function defaultDirHandler(metadata, res
try {
if (metadata.path.indexOf("/tests") != 0) {
regularListing(metadata, response);
} else {
testListing(metadata, response);
}
} catch (ex) {
response.write(ex);
- }
+ }
}