Skip to content

Commit

Permalink
test(change-streams): use generated port numbers for mock server
Browse files Browse the repository at this point in the history
This test would occaisionally flake out due to the use of a port
number hard coded in a number of other tests. If we instead use
the default behavior of the mock server, and generate the port
number, we can avoid this in the future.
  • Loading branch information
mbroadst committed Dec 24, 2017
1 parent 0a8b6d4 commit ad6f67c
Showing 1 changed file with 32 additions and 32 deletions.
64 changes: 32 additions & 32 deletions test/functional/change_stream_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1328,7 +1328,7 @@ describe('Change Streams', function() {
};

co(function*() {
primaryServer = yield mock.createServer(32000, 'localhost');
primaryServer = yield mock.createServer();

var counter = 0;
primaryServer.setMessageHandler(request => {
Expand All @@ -1341,8 +1341,8 @@ describe('Change Streams', function() {
{
ismaster: true,
secondary: false,
me: 'localhost:32000',
primary: 'localhost:32000',
me: primaryServer.uri(),
primary: primaryServer.uri(),
tags: { loc: 'ny' }
},
defaultFields
Expand Down Expand Up @@ -1402,46 +1402,46 @@ describe('Change Streams', function() {
request.reply({ ok: 1 });
}
});
});

MongoClient.connect(
'mongodb://localhost:32000/',
{
socketTimeoutMS: 500,
validateOptions: true
},
function(err, client) {
assert.ifError(err);
MongoClient.connect(
`mongodb://${primaryServer.uri()}/`,
{
socketTimeoutMS: 500,
validateOptions: true
},
function(err, client) {
assert.ifError(err);

var fs = require('fs');
var theDatabase = client.db('integration_tests5');
var theCollection = theDatabase.collection('MongoNetworkErrorTestPromises');
var thisChangeStream = theCollection.watch(pipeline);
var fs = require('fs');
var theDatabase = client.db('integration_tests5');
var theCollection = theDatabase.collection('MongoNetworkErrorTestPromises');
var thisChangeStream = theCollection.watch(pipeline);

var filename = '/tmp/_nodemongodbnative_resumepipe.txt';
var outStream = fs.createWriteStream(filename);
var filename = '/tmp/_nodemongodbnative_resumepipe.txt';
var outStream = fs.createWriteStream(filename);

thisChangeStream.stream({ transform: JSON.stringify }).pipe(outStream);
thisChangeStream.stream({ transform: JSON.stringify }).pipe(outStream);

// Listen for changes to the file
var watcher = fs.watch(filename, function(eventType) {
assert.equal(eventType, 'change');
// Listen for changes to the file
var watcher = fs.watch(filename, function(eventType) {
assert.equal(eventType, 'change');

var fileContents = fs.readFileSync(filename, 'utf8');
var fileContents = fs.readFileSync(filename, 'utf8');

var parsedFileContents = JSON.parse(fileContents);
assert.equal(parsedFileContents.fullDocument.a, 1);
var parsedFileContents = JSON.parse(fileContents);
assert.equal(parsedFileContents.fullDocument.a, 1);

watcher.close();
watcher.close();

thisChangeStream.close(function(err) {
assert.ifError(err);
thisChangeStream.close(function(err) {
assert.ifError(err);

mock.cleanup(primaryServer, () => done());
mock.cleanup(primaryServer, () => done());
});
});
});
}
);
}
);
});
}
});

Expand Down

0 comments on commit ad6f67c

Please sign in to comment.