Skip to content

Commit

Permalink
Merge pull request #677 from mythmon/revert-storage-check
Browse files Browse the repository at this point in the history
Revert "Merge pull request #633 from andymikulski/433-addon-storage-durability"
  • Loading branch information
Osmose committed Apr 13, 2017
2 parents c260972 + fe56521 commit 08a649e
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 109 deletions.
7 changes: 1 addition & 6 deletions recipe-client-addon/lib/NormandyDriver.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const log = LogManager.getLogger("normandy-driver");
const actionLog = LogManager.getLogger("normandy-driver.actions");

this.NormandyDriver = function(sandboxManager) {

if (!sandboxManager) {
throw new Error("sandboxManager is required");
}
Expand Down Expand Up @@ -117,13 +116,9 @@ this.NormandyDriver = function(sandboxManager) {
return ret;
},

async createStorage(keyPrefix, skipDurabilityCheck) {
createStorage(keyPrefix) {
let storage;
try {
if (!skipDurabilityCheck) {
await Storage.checkDurability(sandbox);
}

storage = Storage.makeStorage(keyPrefix, sandbox);
} catch (e) {
log.error(e.stack);
Expand Down
3 changes: 0 additions & 3 deletions recipe-client-addon/lib/RecipeRunner.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ this.RecipeRunner = {
return;
}

const durabilityManager = new SandboxManager();
Storage.seedDurability(durabilityManager.sandbox);

if (prefs.getBoolPref("dev_mode")) {
// Run right now in dev mode
this.run();
Expand Down
32 changes: 0 additions & 32 deletions recipe-client-addon/lib/Storage.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ XPCOMUtils.defineLazyModuleGetter(this, "OS", "resource://gre/modules/osfile.jsm
this.EXPORTED_SYMBOLS = ["Storage"];

const log = LogManager.getLogger("storage");

let storePromise;

function loadStorage() {
Expand All @@ -30,37 +29,6 @@ function loadStorage() {
}

this.Storage = {
DURABILITY_NAMESPACE: "normandy_storageDurability",
DURABILITY_KEY: "durable",
isDurabilityInvalid(value) {
return typeof value === "undefined" || isNaN(value);
},
async seedDurability(sandbox) {
let globalDurabilityStore = this.makeStorage(this.DURABILITY_NAMESPACE, sandbox);
globalDurabilityStore = Cu.waiveXrays(globalDurabilityStore);

let durability = await globalDurabilityStore.getItem(this.DURABILITY_KEY);

if (this.isDurabilityInvalid(durability)) {
durability = 0;
}

globalDurabilityStore.setItem(this.DURABILITY_KEY, durability + 1);
},

async checkDurability(sandbox) {
let globalDurabilityStore = this.makeStorage(this.DURABILITY_NAMESPACE, sandbox);
globalDurabilityStore = Cu.waiveXrays(globalDurabilityStore);

const durability = await globalDurabilityStore.getItem(this.DURABILITY_KEY)
const isDurabilityInvalid = this.isDurabilityInvalid(durability) || durability < 2;

if(isDurabilityInvalid) {
throw new Error('Storage durability unconfirmed');
}
},


makeStorage(prefix, sandbox) {
if (!sandbox) {
throw new Error("No sandbox passed");
Expand Down
34 changes: 0 additions & 34 deletions recipe-client-addon/test/browser/browser_NormandyDriver.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,5 @@
"use strict";

Cu.import("resource://shield-recipe-client/lib/NormandyDriver.jsm", this);
Cu.import("resource://shield-recipe-client/lib/Storage.jsm", this);


// Storage durability checks occur when drivers create new Storage instances.
// This test determines if `skipDurabilityCheck` correctly ignores the
// store durability.
add_task(async function(){
const fakeSandbox = { Promise, Error };
const driver = new NormandyDriver({ sandbox: fakeSandbox });

const store = Storage.makeStorage(Storage.DURABILITY_NAMESPACE, fakeSandbox);
await store.setItem(Storage.DURABILITY_KEY, -1);
let hadError = false;

try {
// Create storage with the 'skipDurabilityCheck' flag set to true
await driver.createStorage('test', true);
} catch(e) {
hadError = true;
}
Assert.equal(hadError, false, 'skipDurabilityCheck should ignore bad storage durability');


await store.setItem(Storage.DURABILITY_KEY, -1);
try {
// Create storage with 'skipDurabilityCheck' disabled
await driver.createStorage('test', false);
} catch(e) {
Assert.equal(e.message, 'Storage durability unconfirmed',
'skipDurabilityCheck should throw an error for invalid storage durability');
}
});

add_task(withDriver(Assert, async function uuids(driver) {
// Test that it is a UUID
const uuid1 = driver.uuid();
Expand Down
35 changes: 1 addition & 34 deletions recipe-client-addon/test/browser/browser_Storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Cu.import("resource://shield-recipe-client/lib/Storage.jsm", this);

const fakeSandbox = { Promise, Error };
const fakeSandbox = {Promise};
const store1 = Storage.makeStorage("prefix1", fakeSandbox);
const store2 = Storage.makeStorage("prefix2", fakeSandbox);

Expand Down Expand Up @@ -44,36 +44,3 @@ add_task(async function() {
Assert.equal(await store1.getItem("removeTest"), null);
Assert.equal(await store2.getItem("removeTest"), null);
});

// Tests fail if durability is not seeded properly
add_task(async function() {
const store = Storage.makeStorage(Storage.DURABILITY_NAMESPACE, fakeSandbox);
await Storage.seedDurability(fakeSandbox);

// Properly seeded store should have a starting value of 1
Assert.equal(await store.getItem(Storage.DURABILITY_KEY), 1, "Storage durability is set to 1 on start");
});

// Tests fails if storage is does not appear to be durable.
add_task(async function() {
// Manually edit the storage durability values to be invalid
const store = Storage.makeStorage(Storage.DURABILITY_NAMESPACE, fakeSandbox);
await store.setItem(Storage.DURABILITY_KEY, -1);

// Ensure invalid values fail durability checks
try {
await Storage.checkDurability(fakeSandbox);
throw new Error('Did not throw error');
} catch (err) {
Assert.equal(err.message, 'Storage durability unconfirmed', "Storage durability fails for invalid values");
}

// Ensure NaN's fail durability checks
await store.setItem(Storage.DURABILITY_KEY, 'not a number');
try {
await Storage.checkDurability(fakeSandbox);
throw new Error('Did not throw error');
} catch (err) {
Assert.equal(err.message, 'Storage durability unconfirmed', "Storage durability fails for NaN values");
}
});

0 comments on commit 08a649e

Please sign in to comment.