[Pkg-javascript-commits] [node-leveldown] 123/492: improved compression test

Andrew Kelley andrewrk-guest at moszumanska.debian.org
Sun Jul 6 17:13:51 UTC 2014


This is an automated email from the git hooks/post-receive script.

andrewrk-guest pushed a commit to annotated tag rocksdb-0.10.1
in repository node-leveldown.

commit 20583d67bc00629d859f321ca0f24810edbecf43
Author: Rod Vagg <rod at vagg.org>
Date:   Sun Dec 16 20:44:09 2012 +1100

    improved compression test
---
 test/compression-test.js | 37 +++++++++++++++++++++++++------------
 1 file changed, 25 insertions(+), 12 deletions(-)

diff --git a/test/compression-test.js b/test/compression-test.js
index 5fcb141..5ee87f5 100644
--- a/test/compression-test.js
+++ b/test/compression-test.js
@@ -4,18 +4,19 @@ var buster     = require('buster')
   , assert     = buster.assert
   , async      = require('async')
   , du         = require('du')
-  , delayed    = require('delayed').delayed
+  , delayed    = require('delayed')
+  , levelup    = require('../')
   , common     = require('./common')
 
   , compressableData = new Buffer(Array.apply(null, Array(1024 * 100)).map(function () { return 'aaaaaaaaaa' }).join(''))
   , multiples = 10
   , dataSize = compressableData.length * multiples
 
-  , verify = function(compressed, db, done) {
-      du(db._location, function (err, size) {
-        refute(err)
+  , verify = function (location, compression, done) {
+      du(location, function (err, size) {
+        if (err) return refute(err)
         //console.log(Math.round((size / dataSize) * 100) + '% compression ratio (', size, 'b vs', dataSize, 'b)')
-        if (compressed)
+        if (compression)
           assert(size < dataSize, 'on-disk size (' + size + ') is less than data size (' + dataSize + ')')
         else
           assert(size >= dataSize, 'on-disk size (' + size + ') is greater than data size (' + dataSize + ')')
@@ -23,8 +24,20 @@ var buster     = require('buster')
       })
     }
 
-  , verifyCompressed = verify.bind(null, true)
-  , verifyNotCompressed = verify.bind(null, false)
+    // close, open, close again.. 'compaction' is also performed on open()s
+  , cycle = function (db, compression, callback) {
+      var location = db._location
+      db.close(function (err) {
+        if (err) return refute(err)
+        levelup(location, { errorIfExists: false, compression: compression }, function (err, db) {
+          if (err) return refute(err)
+          db.close(function (err) {
+            if (err) return refute(err)
+            callback()
+          })
+        })
+      })
+    }
 
 buster.testCase('Compression', {
     'setUp': common.readStreamSetUp
@@ -40,12 +53,12 @@ buster.testCase('Compression', {
           , function (args, callback) {
               db.put.apply(db, args.concat([callback]))
             }
-          , delayed(verifyCompressed.bind(null, db, done), 0.1)
+          , cycle.bind(null, db, true, delayed.delayed(verify.bind(null, db._location, true, done), 0.01))
         )
       })
     }
 
-  , 'test data is not compressed with compression=true on open() (db.put())': function (done) {
+  , 'test data is not compressed with compression=false on open() (db.put())': function (done) {
       this.openTestDatabase({ createIfMissing: true, errorIfExists: true, compression: false }, function (db) {
         async.forEach(
             Array.apply(null, Array(multiples)).map(function (e, i) {
@@ -54,18 +67,18 @@ buster.testCase('Compression', {
           , function (args, callback) {
               db.put.apply(db, args.concat([callback]))
             }
-          , delayed(verifyNotCompressed.bind(null, db, done), 0.1)
+          , cycle.bind(null, db, false, delayed.delayed(verify.bind(null, db._location, false, done), 0.01))
         )
       })
     }
 
-  , '//test data is compressed by default (db.batch())': function (done) {
+  , 'test data is compressed by default (db.batch())': function (done) {
       this.openTestDatabase(function (db) {
         db.batch(
             Array.apply(null, Array(multiples)).map(function (e, i) {
               return { type: 'put', key: i, value: compressableData }
             })
-          , delayed(verifyCompressed.bind(null, db, done), 0.1)
+          , cycle.bind(null, db, false, delayed.delayed(verify.bind(null, db._location, false, done), 0.01))
         )
       })
     }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-leveldown.git



More information about the Pkg-javascript-commits mailing list