Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Commit

Permalink
Fix #2108, create FORCE_AB_TESTS to force-turn-on an A/B test in deve…
Browse files Browse the repository at this point in the history
…lopment
  • Loading branch information
ianb committed Jan 18, 2017
1 parent 7eb41ba commit 32df868
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
7 changes: 6 additions & 1 deletion addon/lib/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ function setVariablesFromServer(responseJson) {
// FIXME: should send Raven/Sentry messages in case of any error
try {
sentryPublicDSN = responseJson.sentryPublicDSN;
console.info("got sentry DSN response from server");
} catch (e) {
console.error("Error looking for the sentry DSN", e);
}
Expand All @@ -48,6 +47,12 @@ function setVariablesFromServer(responseJson) {
} catch (e) {
console.error("Error looking for the A/B tests", e);
}
let abTestsInfo = [];
for (let testName in abTests) {
abTestsInfo.push(`${testName}=${abTests[testName].value}`);
}
console.info(`Got server response: ${sentryPublicDSN ? 'got Sentry DSN' : 'no Sentry DSN'}`);
console.info(`Got server A/B tests: ${abTestsInfo.join('; ')}`);
}

exports.deleteEverything = function () {
Expand Down
11 changes: 8 additions & 3 deletions server/src/ab-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ class Test {
Object.assign(this, options);
}

updateTest(tests) {
updateTest(tests, forceValue) {
if (forceValue) {
tests[this.name] = this.testWithValue(forceValue);
}
if (tests[this.name] && tests[this.name].version >= this.version) {
return;
}
Expand Down Expand Up @@ -119,9 +122,11 @@ class Test {

}

exports.updateAbTests = function (tests) {
/** Update a user's abTests values.
The optional forceTests looks like {aTests: "forceValue"} */
exports.updateAbTests = function (tests, forceTests) {
for (let testName in allTests) {
allTests[testName].updateTest(tests);
allTests[testName].updateTest(tests, forceTests && forceTests[testName]);
}
for (let testName of deprecatedTests) {
if (testName in tests) {
Expand Down
7 changes: 7 additions & 0 deletions server/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,13 @@ var conf = convict({
default: false,
env: "DISABLE_CONTROLLER_TASKS",
arg: "disable-controller-tasks"
},
forceAbTests: {
doc: "Force AB tests, looks like 'testName=value testName2=value'",
format: String,
default: "",
env: "FORCE_AB_TESTS",
arg: "force-ab-tests"
}
});

Expand Down
19 changes: 17 additions & 2 deletions server/src/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,21 @@ function createNonce() {
return crypto.randomBytes(10).toString("hex");
}

/** Parses the FORCE_AB_TESTS config */
function getForceAbTests() {
let val = config.forceAbTests || "";
if (! val) {
return null;
}
let parts = val.split(/\s/g);
let result = {};
for (let part of parts) {
let equals = part.split("=");
result[equals[0]] = equals[1];
}
return result;
}

exports.checkLogin = function (deviceId, secret, addonVersion) {
return db.select(
`SELECT secret_hashed, ab_tests FROM devices WHERE id = $1`,
Expand All @@ -47,7 +62,7 @@ exports.checkLogin = function (deviceId, secret, addonVersion) {
if (rows[0].ab_tests) {
userAbTests = JSON.parse(rows[0].ab_tests);
}
userAbTests = abTests.updateAbTests(userAbTests);
userAbTests = abTests.updateAbTests(userAbTests, getForceAbTests());
if (hashMatches(rows[0].secret_hashed, secret)) {
db.update(
`UPDATE devices
Expand Down Expand Up @@ -78,7 +93,7 @@ exports.registerLogin = function (deviceId, data, canUpdate) {
VALUES ($1, $2, $3, $4)`,
[deviceId, createHash(data.secret), data.nickname || null, data.avatarurl || null]
).then((inserted) => {
let userAbTests = abTests.updateAbTests({});
let userAbTests = abTests.updateAbTests({}, getForceAbTests());
if (inserted) {
return userAbTests;
}
Expand Down

0 comments on commit 32df868

Please sign in to comment.