Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test setup of autoupgrade/autoupdate #202

Merged
merged 1 commit into from
Apr 9, 2019
Merged
Changes from all 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
6 changes: 4 additions & 2 deletions test/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,14 @@ global.getDataSource = global.getSchema = function(customConfig) {
var originalConnector = _.clone(db.connector);
var overrideConnector = {};

db.once('connected', function() {
originalConnector.cloudant = db.connector.cloudant;
});

overrideConnector.automigrate = function(models, cb) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If listen on the connected event before defining the automigrate and autoupdate for the overrideConnector, then if (db.connected) should be always true, which means we can simplify the code as

overrideConnector.automigrate = function(models, cb) {
  return originalConnector.automigrate(models, cb);
}

overrideConnector.autopdate = function(models, cb) {
  return originalConnector.autoupdate(models, cb);
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If listen on the connected event before defining the automigrate and autoupdate for the overrideConnector

I don't think that's the case. In my understanding, automigrate/autoupdate methods are overwritten at the very beginning, when setting up the datasource, before the datasource has a chance to open the network connection.

if (db.connected) return originalConnector.automigrate(models, cb);
else {
db.once('connected', function() {
originalConnector.cloudant = db.connector.cloudant;
originalConnector.automigrate(models, cb);
});
};
Expand All @@ -63,7 +66,6 @@ global.getDataSource = global.getSchema = function(customConfig) {
if (db.connected) return originalConnector.autoupdate(models, cb);
else {
db.once('connected', function() {
originalConnector.cloudant = db.connector.cloudant;
originalConnector.autoupdate(models, cb);
});
};
Expand Down