From c21143aef23d1d9dedafc6a9aca377e308527a19 Mon Sep 17 00:00:00 2001 From: Stephanie Engel Date: Mon, 5 Aug 2019 13:17:25 -0500 Subject: [PATCH] Added 3 tests and updated 1 test --- test/cache_fs.js | 13 +++++++++++++ test/reliability_manager.js | 11 +++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/test/cache_fs.js b/test/cache_fs.js index 839deaf..07c704c 100644 --- a/test/cache_fs.js +++ b/test/cache_fs.js @@ -196,6 +196,19 @@ describe("Cache: FS", () => { assert(await fs.pathExists(file.path)); }); + it("should delete any files if the dryRun option is false", async () => { + const opts = Object.assign({}, cacheOpts); + opts.cleanupOptions = { + expireTimeSpan: "P30D", + maxCacheSize: 1 + }; + + await cache.init(opts); + const file = await addFileToCache(moment().toDate()); + await cache.cleanup(false); + assert(!await fs.pathExists(file.path)); + }); + it("should remove versions from the reliability manager, when in high reliability mode", async () => { const opts = Object.assign({}, cacheOpts); opts.cleanupOptions = { diff --git a/test/reliability_manager.js b/test/reliability_manager.js index 87399e2..37eda4e 100644 --- a/test/reliability_manager.js +++ b/test/reliability_manager.js @@ -104,13 +104,14 @@ describe("ReliabilityManager", () => { }); describe("Known version, reliabilityFactor exceeds reliabilityThreshold", () => { - let trx; + let trx, trxSpy; before(async () => { const guid = randomBuffer(consts.GUID_SIZE); const hash = randomBuffer(consts.HASH_SIZE); await rm.processTransaction(new StablePutTransaction(guid, hash)); // once await rm.processTransaction(new StablePutTransaction(guid, hash)); // twice trx = new StablePutTransaction(guid, hash); + trxSpy = sinon.spy(trx, "writeFilesToPath"); assert(trx.isValid); await rm.processTransaction(trx); // three times (last time) }); @@ -125,6 +126,10 @@ describe("ReliabilityManager", () => { it("should invalidate the transaction to prevent changes to the version", () => { assert(!trx.isValid); }); + + it("should not tell the cache to write unreliable files", () => { + assert(!trxSpy.called); + }); }); describe("Known version, inconsistent versionHash", () => { @@ -150,10 +155,12 @@ describe("ReliabilityManager", () => { assert(!trx.isValid); }); + // seperated this into 2 tests it("should tell the transaction to write unreliable files if saveUnreliableVersionArtifacts is true", async () => { assert(spy.called); + }); - // Test with saveUnreliableVersionArtifacts = false + it("should not tell the transaction to write unreliable files if saveUnreliableVersionArtifacts is false", async () => { const myRm = new ReliabilityManager(db, tmp.tmpNameSync(), {reliabilityThreshold: 2, saveUnreliableVersionArtifacts: false}); spy.resetHistory(); await myRm.processTransaction(trx);