Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: chrome/content/tests/synchronizer.js

Issue 29322737: Issue 284 - Unify initial delay for all downloads (Closed)
Patch Set: Created July 22, 2015, 12:54 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/content/tests/synchronizer.js
===================================================================
--- a/chrome/content/tests/synchronizer.js
+++ b/chrome/content/tests/synchronizer.js
@@ -54,33 +54,35 @@
subscription.expires = subscription.softExpiration = 0;
subscription.title = "";
subscription.homepage = null;
subscription.errors = 0;
subscription.downloadStatus = null;
subscription.requiredVersion = null;
}
+ let initialDelay = 1 / 60;
+
test("Downloads of one subscription", function()
{
let subscription = Subscription.fromURL("http://example.com/subscription");
FilterStorage.addSubscription(subscription);
let requests = [];
testRunner.registerHandler("/subscription", function(metadata)
{
requests.push([testRunner.getTimeOffset(), metadata.method, metadata.path]);
return [Cr.NS_OK, 200, "[Adblock]\n! ExPiREs: 1day\nfoo\nbar"];
});
testRunner.runScheduledTasks(50);
deepEqual(requests, [
- [0.1, "GET", "/subscription"],
- [24.1, "GET", "/subscription"],
- [48.1, "GET", "/subscription"],
+ [0 + initialDelay, "GET", "/subscription"],
+ [24 + initialDelay, "GET", "/subscription"],
+ [48 + initialDelay, "GET", "/subscription"],
], "Requests after 50 hours");
});
test("Downloads of two subscriptions", function()
{
let subscription1 = Subscription.fromURL("http://example.com/subscription1");
FilterStorage.addSubscription(subscription1);
@@ -97,22 +99,22 @@
return [Cr.NS_OK, 200, "[Adblock]\n! ExPiREs: 1day\nfoo\nbar"];
}
testRunner.registerHandler("/subscription1", handler);
testRunner.registerHandler("/subscription2", handler);
testRunner.runScheduledTasks(55);
deepEqual(requests, [
- [0.1, "GET", "/subscription1"],
- [2.1, "GET", "/subscription2"],
- [24.1, "GET", "/subscription1"],
- [26.1, "GET", "/subscription2"],
- [48.1, "GET", "/subscription1"],
- [50.1, "GET", "/subscription2"],
+ [0 + initialDelay, "GET", "/subscription1"],
+ [2 + initialDelay, "GET", "/subscription2"],
+ [24 + initialDelay, "GET", "/subscription1"],
+ [26 + initialDelay, "GET", "/subscription2"],
+ [48 + initialDelay, "GET", "/subscription1"],
+ [50 + initialDelay, "GET", "/subscription2"],
], "Requests after 55 hours");
});
test("Download result, various subscription headers", function()
{
let test;
let subscription = Subscription.fromURL("http://example.com/subscription");
FilterStorage.addSubscription(subscription);
@@ -185,73 +187,73 @@
requests.push(testRunner.getTimeOffset());
return [Cr.NS_OK, 200, "[Adblock]\nfoo\n!Expires: " + test.expiration + "\nbar"];
});
let tests = [
{
expiration: "default",
randomResult: 0.5,
- requests: [0.1, 5 * 24 + 0.1]
+ requests: [0 + initialDelay, 5 * 24 + initialDelay]
},
{
expiration: "1 hours", // Minimal expiration interval
randomResult: 0.5,
- requests: [0.1, 1.1, 2.1, 3.1]
+ requests: [0 + initialDelay, 1 + initialDelay, 2 + initialDelay, 3 + initialDelay]
},
{
expiration: "26 hours",
randomResult: 0.5,
- requests: [0.1, 26.1]
+ requests: [0 + initialDelay, 26 + initialDelay]
},
{
expiration: "2 days",
randomResult: 0.5,
- requests: [0.1, 48.1]
+ requests: [0 + initialDelay, 48 + initialDelay]
},
{
expiration: "20 days", // Too large, will be corrected
randomResult: 0.5,
- requests: [0.1, 14 * 24 + 0.1]
+ requests: [0 + initialDelay, 14 * 24 + initialDelay]
},
{
expiration: "35 hours",
randomResult: 0, // Changes interval by factor 0.8
- requests: [0.1, 28.1]
+ requests: [0 + initialDelay, 28 + initialDelay]
},
{
expiration: "35 hours",
randomResult: 1, // Changes interval by factor 1.2
- requests: [0.1, 42.1]
+ requests: [0 + initialDelay, 42 + initialDelay]
},
{
expiration: "35 hours",
randomResult: 0.25, // Changes interval by factor 0.9
- requests: [0.1, 32.1]
+ requests: [0 + initialDelay, 32 + initialDelay]
},
{
expiration: "40 hours",
randomResult: 0.5,
- skipAfter: 5.1,
+ skipAfter: 5 + initialDelay,
skip: 10, // Short break should not increase soft expiration
- requests: [0.1, 40.1]
+ requests: [0 + initialDelay, 40 + initialDelay]
},
{
expiration: "40 hours",
randomResult: 0.5,
- skipAfter: 5.1,
+ skipAfter: 5 + initialDelay,
skip: 30, // Long break should increase soft expiration
- requests: [0.1, 70.1]
+ requests: [0 + initialDelay, 70 + initialDelay]
},
{
expiration: "40 hours",
randomResult: 0.5,
- skipAfter: 5.1,
+ skipAfter: 5 + initialDelay,
skip: 80, // Hitting hard expiration, immediate download
- requests: [0.1, 85.1]
+ requests: [0 + initialDelay, 85 + initialDelay]
}
]
for (test of tests)
{
requests = [];
randomResult = test.randomResult;
resetSubscription(subscription);
@@ -350,17 +352,17 @@
{
requests.push(testRunner.getTimeOffset());
return [Cr.NS_OK, 200, "[Adblock]\nfoo\n! Expires: 8 hours\nbar"];
});
resetSubscription(subscription);
testRunner.runScheduledTasks(15);
equal(FilterStorage.subscriptions[0].url, "http://example.com/redirected", "Redirect followed");
- deepEqual(requests, [0.1, 8.1], "Resulting requests");
+ deepEqual(requests, [0 + initialDelay, 8 + initialDelay], "Resulting requests");
testRunner.registerHandler("/redirected", function(metadata)
{
return [Cr.NS_OK, 200, "[Adblock]\nfoo\n!Redirect: http://example.com/subscription\nbar"];
})
subscription = Subscription.fromURL("http://example.com/subscription");
resetSubscription(subscription);
@@ -385,64 +387,64 @@
let requests = [];
testRunner.registerHandler("/subscription", function(metadata)
{
requests.push(testRunner.getTimeOffset());
return [Cr.NS_OK, 404, ""];
});
testRunner.runScheduledTasks(100);
- deepEqual(requests, [0.1, 24.1, 48.1, 72.1, 96.1], "Continue trying if the fallback doesn't respond");
+ deepEqual(requests, [0 + initialDelay, 24 + initialDelay, 48 + initialDelay, 72 + initialDelay, 96 + initialDelay], "Continue trying if the fallback doesn't respond");
// Fallback giving "Gone" response
resetSubscription(subscription);
requests = [];
fallbackParams = null;
testRunner.registerHandler("/fallback", function(metadata)
{
fallbackParams = decodeURIComponent(metadata.queryString);
return [Cr.NS_OK, 200, "410 Gone"];
});
testRunner.runScheduledTasks(100);
- deepEqual(requests, [0.1, 24.1, 48.1], "Stop trying if the fallback responds with Gone");
+ deepEqual(requests, [0 + initialDelay, 24 + initialDelay, 48 + initialDelay], "Stop trying if the fallback responds with Gone");
equal(fallbackParams, "http://example.com/subscription&0&404", "Fallback arguments");
// Fallback redirecting to a missing file
subscription = Subscription.fromURL("http://example.com/subscription");
resetSubscription(subscription);
FilterStorage.removeSubscription(FilterStorage.subscriptions[0]);
FilterStorage.addSubscription(subscription);
requests = [];
testRunner.registerHandler("/fallback", function(metadata)
{
return [Cr.NS_OK, 200, "301 http://example.com/redirected"];
});
testRunner.runScheduledTasks(100);
equal(FilterStorage.subscriptions[0].url, "http://example.com/subscription", "Ignore invalid redirect from fallback");
- deepEqual(requests, [0.1, 24.1, 48.1, 72.1, 96.1], "Requests not affected by invalid redirect");
+ deepEqual(requests, [0 + initialDelay, 24 + initialDelay, 48 + initialDelay, 72 + initialDelay, 96 + initialDelay], "Requests not affected by invalid redirect");
// Fallback redirecting to an existing file
resetSubscription(subscription);
requests = [];
let redirectedRequests = [];
testRunner.registerHandler("/redirected", function(metadata)
{
redirectedRequests.push(testRunner.getTimeOffset());
return [Cr.NS_OK, 200, "[Adblock]\n!Expires: 1day\nfoo\nbar"];
});
testRunner.runScheduledTasks(100);
equal(FilterStorage.subscriptions[0].url, "http://example.com/redirected", "Valid redirect from fallback is followed");
- deepEqual(requests, [0.1, 24.1, 48.1], "Stop polling original URL after a valid redirect from fallback");
- deepEqual(redirectedRequests, [48.1, 72.1, 96.1], "Request new URL after a valid redirect from fallback");
+ deepEqual(requests, [0 + initialDelay, 24 + initialDelay, 48 + initialDelay], "Stop polling original URL after a valid redirect from fallback");
+ deepEqual(redirectedRequests, [48 + initialDelay, 72 + initialDelay, 96 + initialDelay], "Request new URL after a valid redirect from fallback");
// Checksum mismatch
testRunner.registerHandler("/subscription", function(metadata)
{
return [Cr.NS_OK, 200, "[Adblock]\n! Checksum: wrong\nfoo\nbar"];
});
@@ -483,40 +485,40 @@
{
return [Cr.NS_OK, 200, "[Adblock]\n! Expires: 2 hours\nfoo\nbar"];
});
let startTime = testRunner.currentTime;
testRunner.runScheduledTasks(2);
equal(subscription.downloadStatus, "synchronize_ok", "downloadStatus after successful download");
- equal(subscription.lastDownload * MILLIS_IN_SECOND, startTime + 0.1 * MILLIS_IN_HOUR, "lastDownload after successful download");
- equal(subscription.lastSuccess * MILLIS_IN_SECOND, startTime + 0.1 * MILLIS_IN_HOUR, "lastSuccess after successful download");
- equal(subscription.lastCheck * MILLIS_IN_SECOND, startTime + 1.1 * MILLIS_IN_HOUR, "lastCheck after successful download");
+ equal(subscription.lastDownload * MILLIS_IN_SECOND, startTime + initialDelay * MILLIS_IN_HOUR, "lastDownload after successful download");
+ equal(subscription.lastSuccess * MILLIS_IN_SECOND, startTime + initialDelay * MILLIS_IN_HOUR, "lastSuccess after successful download");
+ equal(subscription.lastCheck * MILLIS_IN_SECOND, startTime + (1 + initialDelay) * MILLIS_IN_HOUR, "lastCheck after successful download");
equal(subscription.errors, 0, "errors after successful download");
testRunner.registerHandler("/subscription", function(metadata)
{
return [Cr.NS_ERROR_FAILURE, 0, ""];
});
testRunner.runScheduledTasks(2);
equal(subscription.downloadStatus, "synchronize_connection_error", "downloadStatus after connection error");
- equal(subscription.lastDownload * MILLIS_IN_SECOND, startTime + 2.1 * MILLIS_IN_HOUR, "lastDownload after connection error");
- equal(subscription.lastSuccess * MILLIS_IN_SECOND, startTime + 0.1 * MILLIS_IN_HOUR, "lastSuccess after connection error");
- equal(subscription.lastCheck * MILLIS_IN_SECOND, startTime + 3.1 * MILLIS_IN_HOUR, "lastCheck after connection error");
+ equal(subscription.lastDownload * MILLIS_IN_SECOND, startTime + (2 + initialDelay) * MILLIS_IN_HOUR, "lastDownload after connection error");
+ equal(subscription.lastSuccess * MILLIS_IN_SECOND, startTime + initialDelay * MILLIS_IN_HOUR, "lastSuccess after connection error");
+ equal(subscription.lastCheck * MILLIS_IN_SECOND, startTime + (3 + initialDelay) * MILLIS_IN_HOUR, "lastCheck after connection error");
equal(subscription.errors, 1, "errors after connection error");
testRunner.registerHandler("/subscription", function(metadata)
{
return [Cr.NS_OK, 404, ""];
});
testRunner.runScheduledTasks(24);
equal(subscription.downloadStatus, "synchronize_connection_error", "downloadStatus after download error");
- equal(subscription.lastDownload * MILLIS_IN_SECOND, startTime + 26.1 * MILLIS_IN_HOUR, "lastDownload after download error");
- equal(subscription.lastSuccess * MILLIS_IN_SECOND, startTime + 0.1 * MILLIS_IN_HOUR, "lastSuccess after download error");
- equal(subscription.lastCheck * MILLIS_IN_SECOND, startTime + 27.1 * MILLIS_IN_HOUR, "lastCheck after download error");
+ equal(subscription.lastDownload * MILLIS_IN_SECOND, startTime + (26 + initialDelay) * MILLIS_IN_HOUR, "lastDownload after download error");
+ equal(subscription.lastSuccess * MILLIS_IN_SECOND, startTime + initialDelay * MILLIS_IN_HOUR, "lastSuccess after download error");
+ equal(subscription.lastCheck * MILLIS_IN_SECOND, startTime + (27 + initialDelay) * MILLIS_IN_HOUR, "lastCheck after download error");
equal(subscription.errors, 2, "errors after download error");
});
})();
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld