-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
123 additions
and
30 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
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
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
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
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 |
---|---|---|
@@ -1,5 +1,16 @@ | ||
exports.collect = async function (stream) { | ||
const all = [] | ||
for await (const data of stream) all.push(data) | ||
return all | ||
const HyperDB = require('../../') | ||
const tmp = require('test-tmp') | ||
|
||
exports.rocks = async function (t, def, opts) { | ||
if (!HyperDB.isDefinition(def)) return exports.rocks(t, require('../fixtures/generated'), def) | ||
|
||
const db = HyperDB.rocksdb(await tmp(t), def, opts) | ||
const engine = db.engine | ||
|
||
// just to help catch leaks | ||
t.teardown(function () { | ||
if (!engine.closed) throw new Error('Test has a leak, engine did not close') | ||
}) | ||
|
||
return db | ||
} |
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,47 @@ | ||
const test = require('brittle') | ||
const { rocks } = require('./helpers') | ||
|
||
test('basic snapshot', async function (t) { | ||
const db = await rocks(t) | ||
|
||
const empty = db.snapshot() | ||
|
||
t.alike(await empty.find('@db/members').toArray(), []) | ||
|
||
await db.insert('@db/members', { id: 'someone', age: 40 }) | ||
|
||
t.alike(await empty.find('@db/members').toArray(), []) | ||
t.alike(await db.find('@db/members').toArray(), [{ id: 'someone', age: 40 }]) | ||
|
||
await db.flush() | ||
|
||
t.is(db.updated, false) | ||
|
||
t.alike(await empty.find('@db/members').toArray(), []) | ||
t.alike(await db.find('@db/members').toArray(), [{ id: 'someone', age: 40 }]) | ||
|
||
const snap = db.snapshot() | ||
|
||
await db.insert('@db/members', { id: 'someone', age: 41 }) | ||
|
||
t.alike(await empty.find('@db/members').toArray(), []) | ||
t.alike(await db.find('@db/members').toArray(), [{ id: 'someone', age: 41 }]) | ||
t.alike(await snap.find('@db/members').toArray(), [{ id: 'someone', age: 40 }]) | ||
|
||
await db.flush() | ||
|
||
t.alike(await empty.find('@db/members').toArray(), []) | ||
t.alike(await db.find('@db/members').toArray(), [{ id: 'someone', age: 41 }]) | ||
t.alike(await snap.find('@db/members').toArray(), [{ id: 'someone', age: 40 }]) | ||
|
||
await empty.close() | ||
|
||
t.alike(await db.find('@db/members').toArray(), [{ id: 'someone', age: 41 }]) | ||
t.alike(await snap.find('@db/members').toArray(), [{ id: 'someone', age: 40 }]) | ||
|
||
await db.close() | ||
|
||
t.alike(await snap.find('@db/members').toArray(), [{ id: 'someone', age: 40 }]) | ||
|
||
await snap.close() | ||
}) |