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

Commit c21143a

Browse files
Added 3 tests and updated 1 test
1 parent 3754411 commit c21143a

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

test/cache_fs.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,19 @@ describe("Cache: FS", () => {
196196
assert(await fs.pathExists(file.path));
197197
});
198198

199+
it("should delete any files if the dryRun option is false", async () => {
200+
const opts = Object.assign({}, cacheOpts);
201+
opts.cleanupOptions = {
202+
expireTimeSpan: "P30D",
203+
maxCacheSize: 1
204+
};
205+
206+
await cache.init(opts);
207+
const file = await addFileToCache(moment().toDate());
208+
await cache.cleanup(false);
209+
assert(!await fs.pathExists(file.path));
210+
});
211+
199212
it("should remove versions from the reliability manager, when in high reliability mode", async () => {
200213
const opts = Object.assign({}, cacheOpts);
201214
opts.cleanupOptions = {

test/reliability_manager.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,14 @@ describe("ReliabilityManager", () => {
104104
});
105105

106106
describe("Known version, reliabilityFactor exceeds reliabilityThreshold", () => {
107-
let trx;
107+
let trx, trxSpy;
108108
before(async () => {
109109
const guid = randomBuffer(consts.GUID_SIZE);
110110
const hash = randomBuffer(consts.HASH_SIZE);
111111
await rm.processTransaction(new StablePutTransaction(guid, hash)); // once
112112
await rm.processTransaction(new StablePutTransaction(guid, hash)); // twice
113113
trx = new StablePutTransaction(guid, hash);
114+
trxSpy = sinon.spy(trx, "writeFilesToPath");
114115
assert(trx.isValid);
115116
await rm.processTransaction(trx); // three times (last time)
116117
});
@@ -125,6 +126,10 @@ describe("ReliabilityManager", () => {
125126
it("should invalidate the transaction to prevent changes to the version", () => {
126127
assert(!trx.isValid);
127128
});
129+
130+
it("should not tell the cache to write unreliable files", () => {
131+
assert(!trxSpy.called);
132+
});
128133
});
129134

130135
describe("Known version, inconsistent versionHash", () => {
@@ -150,10 +155,12 @@ describe("ReliabilityManager", () => {
150155
assert(!trx.isValid);
151156
});
152157

158+
// seperated this into 2 tests
153159
it("should tell the transaction to write unreliable files if saveUnreliableVersionArtifacts is true", async () => {
154160
assert(spy.called);
161+
});
155162

156-
// Test with saveUnreliableVersionArtifacts = false
163+
it("should not tell the transaction to write unreliable files if saveUnreliableVersionArtifacts is false", async () => {
157164
const myRm = new ReliabilityManager(db, tmp.tmpNameSync(), {reliabilityThreshold: 2, saveUnreliableVersionArtifacts: false});
158165
spy.resetHistory();
159166
await myRm.processTransaction(trx);

0 commit comments

Comments
 (0)