Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions test/functional/change_stream.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const assert = require('assert');
const { Transform } = require('stream');
const { MongoError, MongoNetworkError } = require('../../lib/error');
const { setupDatabase, withTempDb, delay } = require('./shared');
const { delay, setupDatabase, withClient, withDb } = require('./shared');
const co = require('co');
const mock = require('mongodb-mock-server');
const chai = require('chai');
Expand Down Expand Up @@ -2601,32 +2601,31 @@ describe('Change Streams', function() {
describe('tryNext', function() {
it('should return null on single iteration of empty cursor', {
metadata: { requires: { topology: 'replicaset', mongodb: '>=3.6' } },
test: function() {
return withTempDb(
test: withClient(
withDb(
'testTryNext',
{ w: 'majority' },
this.configuration.newClient(),
db => done => {
(db, done) => {
const changeStream = db.collection('test').watch();
tryNext(changeStream, (err, doc) => {
expect(err).to.not.exist;
expect(doc).to.not.exist;

changeStream.close(done);
});
}
);
}
},
true
)
)
});

it('should iterate a change stream until first empty batch', {
metadata: { requires: { topology: 'replicaset', mongodb: '>=3.6' } },
test: function() {
return withTempDb(
test: withClient(
withDb(
'testTryNext',
{ w: 'majority' },
this.configuration.newClient(),
db => done => {
(db, done) => {
const collection = db.collection('test');
const changeStream = collection.watch();
waitForStarted(changeStream, () => {
Expand Down Expand Up @@ -2655,9 +2654,10 @@ describe('Change Streams', function() {
});
});
});
}
);
}
},
true
)
)
});
});

Expand Down
13 changes: 6 additions & 7 deletions test/functional/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
var test = require('./shared').assert;
var setupDatabase = require('./shared').setupDatabase;
const expect = require('chai').expect;
const withClient = require('./shared').withClient;
const withMonitoredClient = require('./shared').withMonitoredClient;
const shared = require('./shared');
const { withClient, withDb, withMonitoredClient } = shared;

describe('Indexes', function() {
before(function() {
Expand Down Expand Up @@ -1208,9 +1208,8 @@ describe('Indexes', function() {
function throwErrorTest(testCommand) {
return {
metadata: { requires: { mongodb: '<4.4' } },
test: function() {
return withClient(this.configuration.newClient(), client => done => {
const db = client.db('test');
test: withClient(
withDb('test', (db, done) => {
const collection = db.collection('commitQuorum');
testCommand(db, collection, (err, result) => {
expect(err).to.exist;
Expand All @@ -1220,8 +1219,8 @@ describe('Indexes', function() {
expect(result).to.not.exist;
done();
});
});
}
})
)
};
}
it(
Expand Down
146 changes: 67 additions & 79 deletions test/functional/logger.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
var expect = require('chai').expect;
var connectToDb = require('./shared').connectToDb;
const expect = require('chai').expect;
const { withClient, withDb } = require('./shared');
const Logger = require('../../lib/logger');

describe('Logger', function() {
Expand Down Expand Up @@ -54,29 +54,24 @@ describe('Logger', function() {
it('should not fail with undefined id', {
metadata: { requires: { topology: ['single'] } },

test: function(done) {
var self = this;

test: function() {
// set a custom logger per http://mongodb.github.io/node-mongodb-native/2.0/tutorials/logging/
Logger.setCurrentLogger(function() {});
Logger.setLevel('debug');

connectToDb('mongodb://localhost:27017/test', self.configuration.db, function(
err,
db,
client
) {
expect(err).to.not.exist;

// perform any operation that gets logged
db.collection('foo').findOne({}, function(err) {
expect(err).to.not.exist;
return withClient(
Comment thread
mbroadst marked this conversation as resolved.
Outdated
this.configuration.newClient('mongodb://localhost:27017/test'),
withDb(this.configuration.db, (db, done) => {
// perform any operation that gets logged
db.collection('foo').findOne({}, function(err) {
expect(err).to.not.exist;

// Clean up
Logger.reset();
client.close(done);
});
});
// Clean up
Logger.reset();
done();
});
})
);
}
});

Expand All @@ -86,43 +81,38 @@ describe('Logger', function() {
it('should correctly log cursor', {
metadata: { requires: { topology: ['single'] } },

test: function(done) {
var self = this;

connectToDb('mongodb://localhost:27017/test', self.configuration.db, function(
err,
db,
client
) {
expect(err).to.not.exist;

// Status
var logged = false;

// Set the current logger
Logger.setCurrentLogger(function(msg, context) {
expect(msg).to.exist;
expect(context.type).to.equal('debug');
expect(context.className).to.equal('Cursor');
logged = true;
});

// Set the filter
Logger.setLevel('debug');
Logger.filter('class', ['Cursor']);
test: function() {
return withClient(
this.configuration.newClient('mongodb://localhost:27017/test'),
withDb(this.configuration.db, (db, done) => {
// Status
var logged = false;

// Set the current logger
Logger.setCurrentLogger(function(msg, context) {
expect(msg).to.exist;
expect(context.type).to.equal('debug');
expect(context.className).to.equal('Cursor');
logged = true;
});

// perform any operation that gets logged
db.collection('logging')
.find()
.toArray(function(err) {
expect(err).to.not.exist;
expect(logged).to.be.true;
// Set the filter
Logger.setLevel('debug');
Logger.filter('class', ['Cursor']);

// Clean up
Logger.reset();
client.close(done);
});
});
// perform any operation that gets logged
db.collection('logging')
.find()
.toArray(function(err) {
expect(err).to.not.exist;
expect(logged).to.be.true;

// Clean up
Logger.reset();
done();
});
})
);
}
});

Expand All @@ -132,34 +122,32 @@ describe('Logger', function() {
it('should pass the logLevel down through the options', {
metadata: { requires: { topology: ['single'] } },

test: function(done) {
var self = this;

test: function() {
Logger.filter('class', ['Cursor']);
var logged = false;

connectToDb(
'mongodb://localhost:27017/test',
self.configuration.db,
{
loggerLevel: 'debug',
logger: function() {
logged = true;
return withClient(
this.configuration.newClient('mongodb://localhost:27017/test'),
withDb(
this.configuration.db,
{
loggerLevel: 'debug',
logger: function() {
logged = true;
}
},
(db, done) => {
// perform any operation that gets logged
db.collection('foo').findOne({}, function(err) {
expect(err).to.not.exist;
expect(logged).to.be.true;

// Clean up
Logger.reset();
done();
});
}
},
function(err, db, client) {
expect(err).to.not.exist;

// perform any operation that gets logged
db.collection('foo').findOne({}, function(err) {
expect(err).to.not.exist;
expect(logged).to.be.true;

// Clean up
Logger.reset();
client.close(done);
});
}
)
);
}
});
Expand Down
Loading