Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #29271 from mcav/refactor-tests
Browse files Browse the repository at this point in the history
Bug 976850 - [email/backend] Refactor GELAM tests. r=asuth
  • Loading branch information
mcav committed Mar 31, 2015
2 parents 2fd8870 + cd69c93 commit f5e4d2f
Show file tree
Hide file tree
Showing 53 changed files with 2,047 additions and 5,195 deletions.
94 changes: 41 additions & 53 deletions apps/email/js/ext/accountcommon.js
Expand Up @@ -5,15 +5,15 @@
define(
[
'./a64',
'./slog',
'logic',
'./allback',
'require',
'module',
'exports'
],
function(
$a64,
slog,
logic,
allback,
require,
$module,
Expand Down Expand Up @@ -309,9 +309,9 @@ exports.fillConfigPlaceholders = fillConfigPlaceholders;
* },
* }
*/
function Autoconfigurator(_LOG) {
this._LOG = _LOG;
function Autoconfigurator() {
this.timeout = AUTOCONFIG_TIMEOUT_MS;
logic.defineScope(this, 'Autoconfigurator');
}
exports.Autoconfigurator = Autoconfigurator;
Autoconfigurator.prototype = {
Expand Down Expand Up @@ -352,14 +352,15 @@ Autoconfigurator.prototype = {
*/
_getXmlConfig: function getXmlConfig(url) {
return new Promise(function(resolve, reject) {
slog.log('autoconfig.xhr:start', { method: 'GET', url: url });

var scope = logic.subscope(this, { method: 'GET', url: url });
logic(scope, 'xhr:start');
var xhr = new XMLHttpRequest({mozSystem: true});
xhr.open('GET', url, true);
xhr.timeout = this.timeout;

xhr.onload = function() {
slog.log('autoconfig.xhr:end', { method: 'GET', url: url,
status: xhr.status });
logic(scope, 'xhr:end', { status: xhr.status });
if (xhr.status < 200 || xhr.status >= 300) {
reject('status' + xhr.status);
return;
Expand Down Expand Up @@ -391,14 +392,12 @@ Autoconfigurator.prototype = {
// to only assign that once until <http://bugzil.la/949722> is fixed.

xhr.ontimeout = function() {
slog.log('autoconfig.xhr:end', { method: 'GET', url: url,
status: 'timeout' });
logic(scope, 'xhr:end', { status: 'timeout' });
reject('timeout');
};

xhr.onerror = function() {
slog.log('autoconfig.xhr:end', { method: 'GET', url: url,
status: 'error' });
logic(scope, 'xhr:end', { status: 'error' });
reject('error');
};

Expand All @@ -409,8 +408,7 @@ Autoconfigurator.prototype = {
xhr.send();
}
catch(e) {
slog.log('autoconfig.xhr:end', { method: 'GET', url: url,
status: 'sync-error' });
logic(scope, 'xhr:end', { status: 'sync-error' });
reject('status404');
}
}.bind(this));
Expand All @@ -436,8 +434,8 @@ Autoconfigurator.prototype = {
*/
_checkAutodiscoverUrl: function(url) {
return new Promise(function(resolve, reject) {
slog.log('autoconfig.autodiscoverProbe:start',
{ method: 'POST', url: url });
var scope = logic.subscope(this, { method: 'POST', url: url });
logic(scope, 'autodiscoverProbe:start');
var xhr = new XMLHttpRequest({mozSystem: true});
xhr.open('POST', url, true);
xhr.timeout = this.timeout;
Expand All @@ -452,8 +450,7 @@ Autoconfigurator.prototype = {
}.bind(this);

xhr.onload = function() {
slog.log('autoconfig.autodiscoverProbe:end',
{ method: 'POST', url: url, status: xhr.status });
logic(scope, 'autodiscoverProbe:end', { status: xhr.status });
if (xhr.status === 401) {
victory();
return;
Expand All @@ -462,23 +459,20 @@ Autoconfigurator.prototype = {
};

xhr.ontimeout = function() {
slog.log('autoconfig.autodiscoverProbe:end',
{ method: 'POST', url: url, status: 'timeout' });
logic(scope, 'autodiscoverProbe:end', { status: 'timeout' });
reject('timeout');
};

xhr.onerror = function() {
slog.log('autoconfig.autodiscoverProbe:end',
{ method: 'POST', url: url, status: 'error' });
logic(scope, 'autodiscoverProbe:end', { status: 'error' });
reject('error');
};

try {
xhr.send(null);
}
catch(e) {
slog.log('autoconfig.autodiscoverProbe:end',
{ method: 'POST', url: url, status: 'sync-error' });
logic(scope, 'autodiscoverProbe:end', { status: 'sync-error' });
reject('status404');
}
}.bind(this));
Expand Down Expand Up @@ -536,7 +530,9 @@ Autoconfigurator.prototype = {
*/
_getMX: function getMX(domain) {
return new Promise(function(resolve, reject) {
slog.log('autoconfig.mxLookup:begin', { domain: domain });

var scope = logic.subscope(this, { domain: domain });
logic(scope, 'mxLookup:begin');
var xhr = new XMLHttpRequest({mozSystem: true});
xhr.open('GET', 'https://live.mozillamessaging.com/dns/mx/' +
encodeURIComponent(domain), true);
Expand All @@ -558,20 +554,17 @@ Autoconfigurator.prototype = {
}
}
}
slog.log('autoconfig.mxLookup:end',
{ domain: domain, 'raw': normStr, normalized: mxDomain,
reporting: reportDomain });
logic(scope, 'mxLookup:end',
{ 'raw': normStr, normalized: mxDomain, reporting: reportDomain });
resolve(reportDomain);
};

xhr.ontimeout = function() {
slog.log('autoconfig.mxLookup:end',
{ domain: domain, status: 'timeout' });
logic(scope, 'mxLookup:end', { status: 'timeout' });
reject('timeout');
};
xhr.onerror = function() {
slog.log('autoconfig.mxLookup:end',
{ domain: domain, status: 'error' });
logic(scope, 'mxLookup:end', { status: 'error' });
reject('error');
};

Expand Down Expand Up @@ -683,7 +676,8 @@ Autoconfigurator.prototype = {
var emailParts = emailAddress.split('@');
var emailLocalPart = emailParts[0], emailDomainPart = emailParts[1];
var domain = emailDomainPart.toLowerCase();
slog.log('autoconfig:begin', { domain: domain });
var scope = logic.subscope(this, { domain: domain });
logic(scope, 'autoconfig:begin');

// Call this when we find a usable config setting to perform appropriate
// normalization, logging, and promise resolution.
Expand All @@ -700,31 +694,25 @@ Autoconfigurator.prototype = {
} else {
result = 'no-config-info';
}
slog.log(
'autoconfig:end',
{
domain: domain, result: result, source: source,
configInfo: configInfo
});
logic(scope, 'autoconfig:end', {
result: result,
source: source,
configInfo: configInfo
});
resolve({ result: result, source: source, configInfo: configInfo });
}.bind(this);
// Call this if we can't find a configuration.
var failsafeFailure = function(err) {
slog.error(
'autoconfig:end',
{
domain: domain,
err: {
message: err && err.message,
stack: err && err.stack
}
});
logic(this, 'autoconfig:end', { err: {
message: err && err.message,
stack: err && err.stack
}});
resolve({ result: 'no-config-info', configInfo: null });
}.bind(this);

// Helper that turns a rejection into a null and outputs a log entry.
var coerceRejectionToNull = function(err) {
slog.log('autoconfig:coerceRejection', { err: err });
logic(scope, 'autoconfig:coerceRejection', { err: err });
return null;
}.bind(this);

Expand Down Expand Up @@ -834,12 +822,12 @@ Autoconfigurator.prototype = {
var config = results.configInfo;
requireConfigurator(config.type, function (mod) {
mod.configurator.tryToCreateAccount(universe, userDetails, config,
callback, this._LOG);
callback);
});
return;
}

slog.warn('autoconfig.legacyCreateFail', { result: results.result });
logic(this, 'legacyCreateFail', { result: results.result });
// need-oauth2 is not supported via this code-path; coerce to a config
// failure...
callback('no-config-info');
Expand Down Expand Up @@ -867,11 +855,11 @@ function recreateAccount(universe, oldVersion, accountInfo, callback) {
}
exports.recreateAccount = recreateAccount;

function tryToManuallyCreateAccount(universe, userDetails, domainInfo, callback,
_LOG) {
function tryToManuallyCreateAccount(universe, userDetails, domainInfo,
callback) {
requireConfigurator(domainInfo.type, function (mod) {
mod.configurator.tryToCreateAccount(universe, userDetails, domainInfo,
callback, _LOG);
callback);
});
}
exports.tryToManuallyCreateAccount = tryToManuallyCreateAccount;
Expand Down
26 changes: 19 additions & 7 deletions apps/email/js/ext/accountmixins.js
@@ -1,6 +1,7 @@
define(function(require, exports) {

var DisasterRecovery = require('./disaster-recovery');
var logic = require('logic');

/**
* The no-op operation for job operations that are not implemented.
Expand Down Expand Up @@ -106,15 +107,24 @@ exports.runOp = function runOp(op, mode, callback) {
}.bind(this);

DisasterRecovery.setCurrentAccountOp(this, op, jobCompletedCallback);
this._LOG.runOp_begin(mode, op.type, null, op);
// _LOG supports wrapping calls, but we want to be able to strip out all
// logging, and that wouldn't work.

// Legacy tests:
logic(this, 'runOp_begin', { mode: mode, type: op.type, op: op });
// New-style tests:
Object.defineProperty(op, '_logicAsyncEvent', {
configurable: true,
enumerable: false, // So that we don't try to JSONify it.
value: logic.startAsync(this, 'runOp', {
mode: mode, type: op.type, op: op
})
});

try {
method.call(this._jobDriver, op, jobCompletedCallback);
}
catch (ex) {
DisasterRecovery.clearCurrentAccountOp(this);
this._LOG.opError(mode, op.type, ex);
logic(this, 'opError', { mode: mode, type: op.type, ex: ex });
}
};

Expand Down Expand Up @@ -218,11 +228,12 @@ exports.normalizeFolderHierarchy = function() {
*/
exports.saveAccountState = function(reuseTrans, callback, reason) {
if (!this._alive) {
this._LOG.accountDeleted('saveAccountState');
logic(this, 'accountDeleted', { reason: 'saveAccountState' });
return null;
}

this._LOG.saveAccountState_begin(reason, null);
logic(this, 'saveAccountState_begin', { reason: reason,
folderSaveCount: null });

// Indicate save is active, in case something, like
// signaling the end of a sync, needs to run after
Expand All @@ -249,7 +260,8 @@ exports.saveAccountState = function(reuseTrans, callback, reason) {
this._deadFolderIds,
function stateSaved() {
this._saveAccountStateActive = false;
this._LOG.saveAccountState_end(reason, folderSaveCount);
logic(this, 'saveAccountState_end', { reason: reason,
folderSaveCount: folderSaveCount });

// NB: we used to log when the save completed, but it ended up being
// annoying to the unit tests since we don't block our actions on
Expand Down

0 comments on commit f5e4d2f

Please sign in to comment.