From 017bcae5e7819949783d8a6698351cabf66804c3 Mon Sep 17 00:00:00 2001 From: Gordon Hall Date: Wed, 1 Feb 2017 13:19:21 -0500 Subject: [PATCH] add simple test to make sure that a range compaction does infact reduce the size of the database --- test/compact-range-test.js | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 test/compact-range-test.js diff --git a/test/compact-range-test.js b/test/compact-range-test.js new file mode 100644 index 00000000..a749a67e --- /dev/null +++ b/test/compact-range-test.js @@ -0,0 +1,37 @@ +const test = require('tape') + , testCommon = require('abstract-leveldown/testCommon') + , leveldown = require('../') + +var db + +test('setUp common', testCommon.setUp) + +test('setUp db', function (t) { + db = leveldown(testCommon.location()) + db.open(t.end.bind(t)) +}) + +test('test compactRange() frees disk space after key deletion', function (t) { + var key1 = '000000'; + var key2 = '000001'; + var val1 = Buffer(64).fill(1); + var val2 = Buffer(64).fill(1); + db.put(key1, val1, function() { + db.put(key2, val2, function() { + db.compactRange(key1, key2, function() { + db.approximateSize('0', 'z', function(err, sizeAfterPuts) { + db.del(key1, function() { + db.del(key2, function() { + db.compactRange(key1, key2, function() { + db.approximateSize('0', 'z', function(err, sizeAfterCompact) { + t.notEqual(sizeAfterCompact, sizeAfterPuts); + t.end(); + }); + }); + }); + }); + }); + }); + }); + }); +});