This repository has been archived by the owner on Apr 5, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add mapsize and maxreaders tests again.
- Loading branch information
Showing
3 changed files
with
164 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
const test = require('tape') | ||
, lmdb = require('../') | ||
, testCommon = require('abstract-leveldown/testCommon') | ||
// 1MBish | ||
, bigBlob = require('crypto').randomBytes(1000000) | ||
//, bigBlob = Array.apply(null, Array(1024 * 100)).map(function () { return 'aaaaaaaaaa' }).join('') | ||
|
||
test('setUp common', testCommon.setUp) | ||
|
||
test('test default mapSize should bork', function (t) { | ||
var db = lmdb(testCommon.location()) | ||
, puts = 20 | ||
, fails = 0 | ||
, donePuts = 0 | ||
, done = function () { | ||
if (++donePuts == puts) { | ||
t.ok(fails > 8 && fails <= 11, 'got expected number of fails (' + fails + ')') | ||
db.close(testCommon.tearDown.bind(null, t)) | ||
} | ||
} | ||
db.open(function (err) { | ||
t.notOk(err, 'no error') | ||
|
||
for (var i = 0; i < puts; i++) { | ||
(function (i) { | ||
db.put(i, bigBlob, function (err) { | ||
err && fails++ | ||
done() | ||
}) | ||
}(i)) | ||
} | ||
}) | ||
}) | ||
|
||
test('test mapSize increase', function (t) { | ||
var db = lmdb(testCommon.location()) | ||
, puts = 20 | ||
, donePuts = 0 | ||
, done = function () { | ||
if (++donePuts == puts) | ||
db.close(testCommon.tearDown.bind(null, t)) | ||
} | ||
|
||
// 25MB | ||
db.open({ mapSize: 25 << 20 }, function (err) { | ||
t.notOk(err, 'no error') | ||
|
||
for (var i = 0; i < puts; i++) { | ||
(function (i) { | ||
db.put(i, bigBlob, function (err) { | ||
t.notOk(err, 'no error from large put #' + i) | ||
done() | ||
}) | ||
}(i)) | ||
} | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
const test = require('tape') | ||
, lmdb = require('../') | ||
, testCommon = require('abstract-leveldown/testCommon') | ||
|
||
test('setUp common', testCommon.setUp) | ||
|
||
test('test maxReaders increase', function (t) { | ||
var db = lmdb(testCommon.location()) | ||
// The default maxreaders is 126, so having that many active iterators | ||
// saturates all slots unless the max value is changed. | ||
, nConcurrentIterators = 126 | ||
, nDone = 0; | ||
|
||
var setupDone = function(iteratorCreationError) { | ||
if (++nDone == nConcurrentIterators) { | ||
t.notOk(iteratorCreationError, 'no iterator creation error') | ||
|
||
// Create one last iterator. This errors if the readers table is | ||
// full, succeeds otherwise | ||
var iter = db.iterator(); | ||
iter.next(function(err) { | ||
t.notOk(err, 'last concurrent reader was fine'); | ||
|
||
// Force exit; no cleanup | ||
// ---------------------- | ||
// | ||
// Doing this instead of a proper | ||
// | ||
// db.close(testCommon.tearDown.bind(null, t)) | ||
// | ||
// because it's impossible to close an iterator from within the | ||
// callback to its `next`-call, which is where all this gets | ||
// called from. | ||
// | ||
// This doesn't affect the test's validity, as the reader limit | ||
// is what counts here. | ||
// process.exit(0); | ||
t.end(); | ||
}) | ||
} | ||
} | ||
|
||
db.open({ maxReaders : 200 }, function (err) { | ||
t.notOk(err, 'no db open error') | ||
|
||
// Create saturating iterators and `next` once to make sure they're active | ||
// and hence occupying a reader slot. | ||
for (var i = 0; i < nConcurrentIterators; i++) { | ||
db.iterator().next(setupDone); | ||
} | ||
|
||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
const test = require('tape') | ||
, lmdb = require('../') | ||
, testCommon = require('abstract-leveldown/testCommon') | ||
|
||
test('setUp common', testCommon.setUp) | ||
|
||
test('test default maxReaders should bork', function (t) { | ||
var db = lmdb(testCommon.location()) | ||
// The default maxreaders is 126, so this should saturate all slots. | ||
, nConcurrentIterators = 126 | ||
, nDone = 0; | ||
|
||
var setupDone = function(iteratorCreationError) { | ||
if (++nDone == nConcurrentIterators) { | ||
t.notOk(iteratorCreationError, 'no iterator creation error') | ||
|
||
// Create one last iterator. This should fail because the readers | ||
// table is full. | ||
var iter = db.iterator(); | ||
iter.next(function(err) { | ||
var correctError = err && err.message | ||
=== 'MDB_READERS_FULL: Environment maxreaders limit reached'; | ||
t.ok(correctError, 'got read error from last concurrent reader'); | ||
|
||
// Force exit; no cleanup | ||
// ---------------------- | ||
// | ||
// Doing this instead of a proper | ||
// | ||
// db.close(testCommon.tearDown.bind(null, t)) | ||
// | ||
// because it's impossible to close an iterator from within the | ||
// callback to its `next`-call, which is where all this gets | ||
// called from. | ||
// | ||
// This doesn't affect the test's validity, as the reader limit | ||
// is what counts here. | ||
// process.exit(0); | ||
t.end(); | ||
}) | ||
} | ||
} | ||
|
||
db.open(function (err) { | ||
t.notOk(err, 'no db open error') | ||
|
||
// Create saturating iterators and `next` once to make sure they're active | ||
// and hence occupying a reader slot. | ||
for (var i = 0; i < nConcurrentIterators; i++) { | ||
db.iterator().next(setupDone); | ||
} | ||
|
||
}) | ||
}) |