[Pkg-javascript-commits] [node-leveldown] 93/492: added snapshot test case that I forgot to add...

Andrew Kelley andrewrk-guest at moszumanska.debian.org
Sun Jul 6 17:13:48 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 01b01b086e4e6de9cedf552cd995261616179f9c
Author: Rod Vagg <rod at vagg.org>
Date:   Thu Dec 13 19:53:19 2012 +1100

    added snapshot test case that I forgot to add...
---
 test/snapshot-test.js | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 63 insertions(+)

diff --git a/test/snapshot-test.js b/test/snapshot-test.js
new file mode 100644
index 0000000..1df88e8
--- /dev/null
+++ b/test/snapshot-test.js
@@ -0,0 +1,63 @@
+/* Copyright (c) 2012 Rod Vagg <@rvagg> */
+
+var buster     = require('buster')
+  , assert     = buster.assert
+  , delayed    = require('delayed')
+  , common     = require('./common')
+  , SlowStream = require('slow-stream')
+
+buster.testCase('Snapshots', {
+    'setUp': common.readStreamSetUp
+
+  , 'tearDown': common.commonTearDown
+
+  , 'test ReadStream implicit snapshot': function (done) {
+      this.openTestDatabase(function (db) {
+
+        // 1) Store 100 random numbers stored in the database
+        db.batch(this.sourceData.slice(), function (err) {
+          refute(err)
+
+          // 2) Create an iterator on the current data, pipe it through a SlowStream
+          //    to make *sure* that we're going to be reading it for longer than it
+          //    takes to overwrite the data in there.
+
+          var rs = db.readStream()
+          assert.isFalse(rs.writable)
+          assert.isTrue(rs.readable)
+          rs = rs.pipe(new SlowStream({ maxWriteInterval: 5 }))
+          this.readySpy()
+          rs.on('data' , this.dataSpy)
+          rs.on('end'  , this.endSpy)
+          rs.on('end', function () {
+            rs.readable = false
+            rs.writable = false
+          })
+
+          rs.on('close', delayed.delayed(this.verify.bind(this, rs, done), 0.05))
+
+          process.nextTick(function () {
+
+            // 3) Concoct and write new random data over the top of existing items.
+            //    If we're not using a snapshot then then we'd expect the test
+            //    to fail because it'll pick up these new values rather than the
+            //    old ones.
+            var newData = []
+            for (var i = 0; i < 100; i++) {
+              var k = (i < 10 ? '0' : '') + i
+              newData.push({
+                  type  : 'put'
+                , key   : k
+                , value : Math.random()
+              })
+            }
+            // using sync:true here to ensure it's written fully to disk
+            db.batch(newData.slice(), { sync: true }, function (err) {
+              refute(err)
+              // we'll return here faster than it takes the readStream to complete
+            })
+          }.bind(this))
+        }.bind(this))
+      }.bind(this))
+    }
+})
\ No newline at end of file

-- 
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