Skip to content

Commit

Permalink
Merge pull request #6853 from Fonger/4.x-ci-improve
Browse files Browse the repository at this point in the history
4.x ci improve
  • Loading branch information
vkarpov15 committed Aug 14, 2018
2 parents 0e0dba0 + 453f472 commit 0e8f016
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 41 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ before_script:
- tar -zxvf mongodb-linux-x86_64-2.6.11.tgz
- mkdir -p ./data/db/27017
- mkdir -p ./data/db/27000
- ./mongodb-linux-x86_64-2.6.11/bin/mongod --fork --nopreallocj --dbpath ./data/db/27017 --syslog --port 27017
- printf "\n--timeout 8000" >> ./test/mocha.opts
- ./mongodb-linux-x86_64-2.6.11/bin/mongod --fork --dbpath ./data/db/27017 --syslog --port 27017
- sleep 3
script:
- npm test
- npm run lint
Expand Down
9 changes: 5 additions & 4 deletions test/connection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var Schema = mongoose.Schema;
*/

describe('connections:', function() {
this.timeout(10000);
describe('useMongoClient/openUri (gh-5304)', function() {
it('with mongoose.connect()', function(done) {
var conn = mongoose.connect('mongodb://localhost:27017/mongoosetest', {
Expand Down Expand Up @@ -143,7 +144,7 @@ describe('connections:', function() {
}).
then(function() {
return new Promise(function(resolve) {
setTimeout(function() { resolve(); }, 50);
setTimeout(function() { resolve(); }, 100);
});
}).
then(function() {
Expand All @@ -157,7 +158,7 @@ describe('connections:', function() {
}).
then(function() {
return new Promise(function(resolve) {
setTimeout(function() { resolve(); }, 2000);
setTimeout(function() { resolve(); }, 4000);
});
}).
then(function() {
Expand Down Expand Up @@ -217,7 +218,7 @@ describe('connections:', function() {
}).
then(function() {
return new Promise(function(resolve) {
setTimeout(function() { resolve(); }, 400);
setTimeout(function() { resolve(); }, 4000);
});
}).
then(function() {
Expand Down Expand Up @@ -1082,7 +1083,7 @@ describe('connections:', function() {

describe('errors', function() {
it('event fires with one listener', function(done) {
this.timeout(1000);
this.timeout(1500);
var db = start({uri: 'mongodb://whatever23939.localhost/fakeeee?connectTimeoutMS=500', noErrorListener: 1});
db.on('error', function() {
// this callback has no params which triggered the bug #759
Expand Down
32 changes: 21 additions & 11 deletions test/document.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1376,6 +1376,8 @@ describe('document', function() {
});

it('validator should run only once per sub-doc gh-1743', function(done) {
this.timeout(process.env.TRAVIS ? 8000 : 4500);

var count = 0;
var db = start();

Expand Down Expand Up @@ -1410,18 +1412,21 @@ describe('document', function() {


it('validator should run in parallel', function(done) {
// we set the time out to be double that of the validator - 1 (so that running in serial will be greater than that)
this.timeout(1000);
var db = start();
var count = 0;
var startTime, endTime;

var SchemaWithValidator = new Schema({
preference: {
type: String,
required: true,
validate: function validator(value, done) {
count++;
setTimeout(done.bind(null, true), 500);
validate: {
validator: function validator(value, done) {
count++;
if (count === 1) startTime = Date.now();
else if (count === 4) endTime = Date.now();
setTimeout(done.bind(null, true), 150);
}
}
}
});
Expand All @@ -1442,6 +1447,7 @@ describe('document', function() {
m.save(function(err) {
assert.ifError(err);
assert.equal(count, 4);
assert(endTime - startTime < 150 * 4); // serial >= 150 * 4, parallel < 150 * 4
db.close(done);
});
});
Expand Down Expand Up @@ -2860,12 +2866,16 @@ describe('document', function() {

var MyModel = db.model('gh4014', schema);

MyModel.
where('geo').near({ center: [50, 50] }).
exec(function(error) {
assert.ifError(error);
done();
});
MyModel.on('index', function(err) {
assert.ifError(err);

MyModel.
where('geo').near({ center: [50, 50], spherical: true }).
exec(function(err) {
assert.ifError(err);
done();
});
});
});

it('skip validation if required returns false (gh-4094)', function(done) {
Expand Down
2 changes: 2 additions & 0 deletions test/gh-1408.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ var start = require('./common'),

describe('documents should not be converted to _id (gh-1408)', function() {
it('if an embedded doc', function(done) {
this.timeout(process.env.TRAVIS ? 8000 : 4500);

var db = start();

var PreferenceSchema = new Schema({
Expand Down
2 changes: 2 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ describe('mongoose module:', function() {
});

describe('disconnection of all connections', function() {
this.timeout(10000);

describe('no callback', function() {
it('works', function(done) {
var mong = new Mongoose(),
Expand Down
12 changes: 2 additions & 10 deletions test/model.aggregate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ var collection = 'aggregate_' + random();
mongoose.model('Aggregate', userSchema);

describe('model aggregate', function() {
this.timeout(process.env.TRAVIS ? 8000 : 4500);

var group = {$group: {_id: null, maxAge: {$max: '$age'}}};
var project = {$project: {maxAge: 1, _id: 0}};
var db, A, maxAge;
Expand Down Expand Up @@ -74,8 +76,6 @@ describe('model aggregate', function() {
});

it('when return promise', function(done) {
this.timeout(4000);

A.aggregate(group, project).then( function(res) {
assert.ok(res);
assert.equal(1, res.length);
Expand All @@ -86,8 +86,6 @@ describe('model aggregate', function() {
});

it('with arrays', function(done) {
this.timeout(4000);

A.aggregate([group, project], function(err, res) {
assert.ifError(err);
assert.ok(res);
Expand All @@ -99,8 +97,6 @@ describe('model aggregate', function() {
});

it('with Aggregate syntax', function(done) {
this.timeout(4000);

var promise = A.aggregate()
.group(group.$group)
.project(project.$project)
Expand All @@ -116,8 +112,6 @@ describe('model aggregate', function() {
});

it('with Aggregate syntax if callback not provided', function(done) {
this.timeout(4000);

var promise = A.aggregate()
.group(group.$group)
.project(project.$project)
Expand All @@ -143,8 +137,6 @@ describe('model aggregate', function() {
return done();
}

this.timeout(4000);

var outputCollection = 'aggregate_output_' + random();
A.aggregate()
.group(group.$group)
Expand Down
11 changes: 7 additions & 4 deletions test/model.create.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,23 @@ describe('model', function() {
});

it('creates in parallel', function(done) {
// we set the time out to be double that of the validator - 1 (so that running in serial will be greater than that)
this.timeout(1000);
var db = start(),
countPre = 0,
countPost = 0;

var SchemaWithPreSaveHook = new Schema({
preference: String
});

var startTime, endTime;
SchemaWithPreSaveHook.pre('save', true, function hook(next, done) {
setTimeout(function() {
countPre++;
if (countPre === 1) startTime = Date.now();
else if (countPre === 4) endTime = Date.now();
next();
done();
}, 500);
}, 100);
});
SchemaWithPreSaveHook.post('save', function() {
countPost++;
Expand All @@ -139,7 +141,8 @@ describe('model', function() {
assert.ok(doc4);
assert.equal(countPre, 4);
assert.equal(countPost, 4);
done();
assert.ok(endTime - startTime < 4 * 100); // serial: >= 4 * 100 parallel: < 4 * 100
db.close(done);
});
});

Expand Down
2 changes: 2 additions & 0 deletions test/model.geosearch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ describe('model', function() {
});

describe('geoSearch', function() {
this.timeout(process.env.TRAVIS ? 8000 : 4500);

it('works', function(done) {
var db = start();
var Geo = getModel(db);
Expand Down
2 changes: 2 additions & 0 deletions test/model.populate.setting.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ var posts = 'blogposts_' + random(),
*/

describe('model: populate:', function() {
this.timeout(process.env.TRAVIS ? 8000 : 4500);

describe('setting populated paths (gh-570)', function() {
var types = {
ObjectId: DocObjectId,
Expand Down
31 changes: 22 additions & 9 deletions test/model.populate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ var DocObjectId = mongoose.Types.ObjectId;
*/

describe('model: populate:', function() {
this.timeout(process.env.TRAVIS ? 8000 : 4500);

var User;
var Comment;
var BlogPost;
Expand Down Expand Up @@ -3271,16 +3273,27 @@ describe('model: populate:', function() {
slice('fans', [0, 5]).
populate('fans').
exec(function(err, blogposts) {
assert.ifError(error);
assert.ifError(err);

assert.equal(blogposts[0].title, 'Test 1');
assert.equal(blogposts[1].title, 'Test 2');
assert.ok(blogposts.length === 2);

assert.equal(blogposts[0].fans[0].name, 'Fan 1');
assert.equal(blogposts[0].fans[1].name, 'Fan 2');
var test1, test2;
if (blogposts[0].title === 'Test 1') {
test1 = blogposts[0];
test2 = blogposts[1];
} else {
test1 = blogposts[1];
test2 = blogposts[0];
}

assert.equal(blogposts[1].fans[0].name, 'Fan 2');
assert.equal(blogposts[1].fans[1].name, 'Fan 1');
assert.ok(test1.title === 'Test 1');
assert.ok(test2.title === 'Test 2');

assert.equal(test1.fans[0].name, 'Fan 1');
assert.equal(test1.fans[1].name, 'Fan 2');

assert.equal(test2.fans[0].name, 'Fan 2');
assert.equal(test2.fans[1].name, 'Fan 1');
done();
});
});
Expand Down Expand Up @@ -4605,8 +4618,8 @@ describe('model: populate:', function() {
}).
then(function(bs) {
assert.equal(bs.length, 2);
assert.equal(bs[0].a.name, 'a1');
assert.equal(bs[1].a.name, 'a2');
var names = bs.map(function(b) { return b.a.name; }).sort();
assert.deepEqual(names, ['a1', 'a2']);
done();
}).
catch(done);
Expand Down
4 changes: 2 additions & 2 deletions test/model.querying.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1820,9 +1820,9 @@ describe('model: querying:', function() {
});

it('with Dates', function(done) {
this.timeout(3000);
var db = start();

this.timeout(process.env.TRAVIS ? 8000 : 4500);
var SSchema = new Schema({d: Date});
var PSchema = new Schema({sub: [SSchema]});

Expand Down Expand Up @@ -2087,7 +2087,7 @@ describe('model: querying:', function() {
assert.equal(tests.length, 3);
});

var pending = 9;
var pending = 10;

function cb() {
if (--pending) {
Expand Down

0 comments on commit 0e8f016

Please sign in to comment.