[Pkg-javascript-commits] [node-leveldown] 152/492: test that open and close are idempotent
Andrew Kelley
andrewrk-guest at moszumanska.debian.org
Sun Jul 6 17:13:54 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 01bf962c5b552f8406f7b6a0590514047e2fbe62
Author: Dominic Tarr <dominic.tarr at gmail.com>
Date: Tue Jan 8 18:02:39 2013 +0700
test that open and close are idempotent
---
test/idempotent-test.js | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 48 insertions(+)
diff --git a/test/idempotent-test.js b/test/idempotent-test.js
new file mode 100644
index 0000000..39d7391
--- /dev/null
+++ b/test/idempotent-test.js
@@ -0,0 +1,48 @@
+/* Copyright (c) 2012 Rod Vagg <@rvagg> */
+
+var buster = require('buster')
+ , assert = buster.assert
+ , levelup = require('../lib/levelup.js')
+ , errors = require('../lib/errors.js')
+ , async = require('async')
+ , fs = require('fs')
+ , common = require('./common')
+
+buster.testCase('idempotent open & close', {
+ 'call open twice, should emit "open" once': function (done) {
+ var location = common.nextLocation()
+ var n = 0, m = 0
+ var db = levelup(location, { createIfMissing: true }, function (err, db) {
+ //callback should fire only once.
+ assert.equals(n++, 0)
+ if(n && m) close()
+ })
+
+ db.on('open', function () {
+ console.log('emit open')
+ assert.equals(m++, 0)
+ if(n && m) close()
+ })
+
+ db.open()
+
+ //this will only be called once.
+ function close () {
+ var closing = false
+ db.on('closing', function () {
+ closing = true
+ })
+ db.on('closed', function () {
+ assert.equals(closing, true)
+ done()
+ })
+
+ //close needs to be idempotent too.
+ db.close()
+
+ process.nextTick(function () {
+ db.close()
+ })
+ }
+ }
+})
--
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