Merge pull request #77 from sayrer/master

Concurrent browsers sending results asynchronously
This commit is contained in:
Chris Jones 2011-06-24 16:22:08 -07:00
commit 6d0ab5fca6
2 changed files with 48 additions and 21 deletions

View File

@ -69,9 +69,10 @@ class State:
eqLog = None
class Result:
def __init__(self, snapshot, failure):
def __init__(self, snapshot, failure, page):
self.snapshot = snapshot
self.failure = failure
self.page = page
class TestServer(SocketServer.TCPServer):
allow_reuse_address = True
@ -122,10 +123,20 @@ class PDFTestHandler(BaseHTTPRequestHandler):
result = json.loads(self.rfile.read(numBytes))
browser, id, failure, round, page, snapshot = result['browser'], result['id'], result['failure'], result['round'], result['page'], result['snapshot']
taskResults = State.taskResults[browser][id]
taskResults[round].append(Result(snapshot, failure))
assert len(taskResults[round]) == page
taskResults[round].append(Result(snapshot, failure, page))
if result['taskDone']:
def isTaskDone():
numPages = result["numPages"]
rounds = State.manifest[id]["rounds"]
for round in range(0,rounds):
if len(taskResults[round]) < numPages:
return False
return True
if isTaskDone():
# sort the results since they sometimes come in out of order
for results in taskResults:
results.sort(key=lambda result: result.page)
check(State.manifest[id], taskResults, browser)
# Please oh please GC this ...
del State.taskResults[browser][id]

View File

@ -139,31 +139,41 @@ function snapshotCurrentPage(gfx) {
}
}
currentTask.taskDone = (currentTask.pageNum == pdfDoc.numPages
&& (1 + currentTask.round) == currentTask.rounds);
sendTaskResult(canvas.toDataURL("image/png"));
log("done"+ (failure ? " (failed!)" : "") +"\n");
// Set up the next request
backoff = (inFlightRequests > 0) ? inFlightRequests * 10 : 0;
setTimeout(function() {
++currentTask.pageNum, nextPage();
},
backoff
);
}
function done() {
log("Done!\n");
setTimeout(function() {
function quitApp() {
log("Done!");
document.body.innerHTML = "Tests are finished. <h1>CLOSE ME!</h1>";
if (window.SpecialPowers)
SpecialPowers.quitApplication();
else
window.close();
},
100
);
}
function done() {
if (inFlightRequests > 0) {
document.getElementById("inFlightCount").innerHTML = inFlightRequests;
setTimeout(done, 100);
} else {
setTimeout(quitApp, 100);
}
}
var inFlightRequests = 0;
function sendTaskResult(snapshot) {
var result = { browser: browser,
id: currentTask.id,
taskDone: currentTask.taskDone,
numPages: pdfDoc.numPages,
failure: failure,
file: currentTask.file,
round: currentTask.round,
@ -172,9 +182,14 @@ function sendTaskResult(snapshot) {
var r = new XMLHttpRequest();
// (The POST URI is ignored atm.)
r.open("POST", "/submit_task_results", false);
r.open("POST", "/submit_task_results", true);
r.setRequestHeader("Content-Type", "application/json");
// XXX async
r.onreadystatechange = function(e) {
if (r.readyState == 4) {
inFlightRequests--;
}
}
document.getElementById("inFlightCount").innerHTML = inFlightRequests++;
r.send(JSON.stringify(result));
}
@ -194,7 +209,8 @@ function log(str) {
</head>
<body onload="load();">
<pre id="stdout"></pre>
<pre style="width:800; height:800; overflow: scroll;"id="stdout"></pre>
<p>Inflight requests: <span id="inFlightCount"></span></p>
</body>
</html>