-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #194 from mcollina/tailable
Added back tailable cursor support.
- Loading branch information
Showing
3 changed files
with
58 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
var test = require('./tape'); | ||
var mongojs = require('../index'); | ||
var db = mongojs('test', ['tailable']); | ||
|
||
test('tailable find', function(t) { | ||
db.tailable.drop(function(err) { | ||
db.createCollection('tailable', {capped: true, size: 1024}, function(err) { | ||
t.notOk(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: -1 | ||
}); | ||
|
||
db.tailable.insert(expected1, function(err) { | ||
t.notOk(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.notOk(err, 'no error in insert'); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |