-
Notifications
You must be signed in to change notification settings - Fork 256
/
Copy pathtest-find-tailable.js
37 lines (32 loc) · 1.1 KB
/
test-find-tailable.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
var test = require('./tape')
var mongojs = require('../index')
var db = mongojs('test', ['tailable'])
test('tailable find', function (t) {
db.tailable.drop(function () {
db.createCollection('tailable', { capped: true, size: 1024 }, function (err) {
t.error(err, 'no error in creating the collection')
var expected1 = { hello: 'world' }
var expected2 = { hello: 'matteo' }
var stream = db.tailable.find({}, {}, {
tailable: true,
timeout: false,
awaitData: true,
numberOfRetries: Number.MAX_VALUE
})
db.tailable.insert(expected1, function (err) {
t.error(err, 'no error in insert')
stream.once('data', function (obj) {
t.deepEqual(obj, expected1, 'fetched object match')
stream.once('data', function (obj) {
t.deepEqual(obj, expected2, 'fetched object match')
stream.destroy()
db.tailable.drop(t.end.bind(t))
})
db.tailable.insert(expected2, function (err) {
t.error(err, 'no error in insert')
})
})
})
})
})
})