Bug 1151666 - fix intermittent orange by reducing verified timer intervals and always using mock storage. r=zaach

This commit is contained in:
Mark Hammond 2015-04-14 10:35:48 +10:00
parent afd136410b
commit 7aa7209cc7
2 changed files with 31 additions and 20 deletions

View File

@ -579,6 +579,11 @@ FxAccountsInternal.prototype = {
*/
version: DATA_FORMAT_VERSION,
// The timeout (in ms) we use to poll for a verified mail for the first 2 mins.
VERIFICATION_POLL_TIMEOUT_INITIAL: 5000, // 5 seconds
// And how often we poll after the first 2 mins.
VERIFICATION_POLL_TIMEOUT_SUBSEQUENT: 15000, // 15 seconds.
_fxAccountsClient: null,
get fxAccountsClient() {
@ -1128,7 +1133,8 @@ FxAccountsInternal.prototype = {
}
if (timeoutMs === undefined) {
let currentMinute = Math.ceil(ageMs / 60000);
timeoutMs = 1000 * (currentMinute <= 2 ? 5 : 15);
timeoutMs = currentMinute <= 2 ? this.VERIFICATION_POLL_TIMEOUT_INITIAL
: this.VERIFICATION_POLL_TIMEOUT_SUBSEQUENT;
}
log.debug("polling with timeout = " + timeoutMs);
this.currentTimer = setTimeout(() => {

View File

@ -25,7 +25,8 @@ let log = Log.repository.getLogger("Services.FxAccounts.test");
log.level = Log.Level.Debug;
// See verbose logging from FxAccounts.jsm
Services.prefs.setCharPref("identity.fxaccounts.loglevel", "DEBUG");
Services.prefs.setCharPref("identity.fxaccounts.loglevel", "Trace");
Log.repository.getLogger("FirefoxAccounts").level = Log.Level.Trace;
// The oauth server is mocked, but set these prefs to pass param checks
Services.prefs.setCharPref("identity.fxaccounts.remote.oauth.uri", "https://example.com/v1");
@ -60,15 +61,10 @@ function MockFxAccountsClient() {
// user account has been verified
this.recoveryEmailStatus = function (sessionToken) {
// simulate a call to /recovery_email/status
let deferred = Promise.defer();
let response = {
return Promise.resolve({
email: this._email,
verified: this._verified
};
deferred.resolve(response);
return deferred.promise;
});
};
this.accountStatus = function(uid) {
@ -132,6 +128,8 @@ MockStorage.prototype = Object.freeze({
*/
function MockFxAccounts() {
return new FxAccounts({
VERIFICATION_POLL_TIMEOUT_INITIAL: 100, // 100ms
_getCertificateSigned_calls: [],
_d_signCertificate: Promise.defer(),
_now_is: new Date(),
@ -177,10 +175,12 @@ add_test(function test_non_https_remote_server_uri() {
});
add_task(function test_get_signed_in_user_initially_unset() {
// This test, unlike the rest, uses an un-mocked FxAccounts instance.
// However, we still need to pass an object to the constructor to
// force it to expose "internal", so we can test the disk storage.
let account = new FxAccounts({onlySetInternal: true})
// This test, unlike many of the the rest, uses a (largely) un-mocked
// FxAccounts instance.
// We do mock the storage to keep the test fast on b2g.
let account = new FxAccounts({
signedInUserStorage: new MockStorage(),
});
let credentials = {
email: "foo@example.com",
uid: "1234@lcip.org",
@ -190,6 +190,8 @@ add_task(function test_get_signed_in_user_initially_unset() {
kB: "cafe",
verified: true
};
// and a sad hack to ensure the mocked storage is used for the initial reads.
account.internal.currentAccountState.signedInUserStorage = account.internal.signedInUserStorage;
let result = yield account.getSignedInUser();
do_check_eq(result, null);
@ -218,12 +220,14 @@ add_task(function test_get_signed_in_user_initially_unset() {
do_check_eq(result, null);
});
add_task(function test_getCertificate() {
add_task(function* test_getCertificate() {
_("getCertificate()");
// This test, unlike the rest, uses an un-mocked FxAccounts instance.
// However, we still need to pass an object to the constructor to
// force it to expose "internal".
let fxa = new FxAccounts({onlySetInternal: true});
// This test, unlike many of the the rest, uses a (largely) un-mocked
// FxAccounts instance.
// We do mock the storage to keep the test fast on b2g.
let fxa = new FxAccounts({
signedInUserStorage: new MockStorage(),
});
let credentials = {
email: "foo@example.com",
uid: "1234@lcip.org",
@ -233,6 +237,8 @@ add_task(function test_getCertificate() {
kB: "cafe",
verified: true
};
// and a sad hack to ensure the mocked storage is used for the initial reads.
fxa.internal.currentAccountState.signedInUserStorage = fxa.internal.signedInUserStorage;
yield fxa.setSignedInUser(credentials);
// Test that an expired cert throws if we're offline.
@ -242,7 +248,7 @@ add_task(function test_getCertificate() {
let offline = Services.io.offline;
Services.io.offline = true;
// This call would break from missing parameters ...
fxa.internal.currentAccountState.getCertificate().then(
yield fxa.internal.currentAccountState.getCertificate().then(
result => {
Services.io.offline = offline;
do_throw("Unexpected success");
@ -253,7 +259,6 @@ add_task(function test_getCertificate() {
do_check_eq(err, "Error: OFFLINE");
}
);
_("----- DONE ----\n");
});