Skip to content
This repository was archived by the owner on Jan 9, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions test/cache_fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
11 changes: 9 additions & 2 deletions test/reliability_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
});
Expand All @@ -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", () => {
Expand All @@ -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);
Expand Down