- Notifications
You must be signed in to change notification settings - Fork 182
Fix bug where settings for pg-pool were dropped #186
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
Conversation
Can one of the admins verify this patch? To accept patch and trigger a build add comment ".ok\W+to\W+test." |
Can one of the admins verify this patch? |
1 similar comment
Can one of the admins verify this patch? |
this.constructor.super_.call(this, 'postgresql', settings); | ||
this.clientConfig = settings; | ||
if (settings.url) { | ||
// pg-pool doesn't handle string config correctly |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we delete this comment too? I assume pg pool is handling it correctly now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line 76? That is still accurate. Pg-pool expects a different key name than the pg module.
Can you add a test to prevent regressions? |
Sorry, it is not clear to me how to write such a test. Is this the correct place to add the test? https://github.com/strongloop/loopback-connector-postgresql/blob/master/test/postgresql.test.js https://github.com/strongloop/loopback-connector-postgresql/blob/master/test/postgresql.test.js
|
Feel free to create a new file in the test dir named
|
@superkhau I ran into an error trying to run the tests in the project.
The docs say:
Can you tell me how to set up the test environment? Or can you take care of |
You'll have to set up your own posgresql instance on your machine and inject the credential (setup varies depending on your OS -- ie. mac vs windows etc, you can google that one). As for the credentials, see this list of environment variables: https://github.com/strongloop/loopback-connector-postgresql/blob/master/test/init.js#L12 |
I added a test as requested to prevent a regression. Although I created a new file, |
I'm not sure how to fix |
@gregdingle Depending on how you forked, you can do something like: https://robots.thoughtbot.com/keeping-a-github-fork-updated. Basically your clone is not up to date with the latest master. |
Also, thanks for adding the test -- I will review it soon. So far it looks good with a few minor nitpicks to address after I do a more thorough review. 👍 |
I rebased and re-pushed with the latest master: https://github.com/strongloop/loopback-connector-postgresql/pull/186/commits . |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gregdingle Reviewed, I left a bunch of comments. Please ping me again when you submit the fixups.
| ||
var should = require('should'); | ||
var DataSource = require('loopback-datasource-juggler').DataSource; | ||
var postgresql = require('../lib/postgresql.js'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit -- move the should require statement under postgres to alpha sort requires.
var postgresql = require('../lib/postgresql.js'); | ||
| ||
describe('initialization', function() { | ||
it('should take pg-pool setting', function(done) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it('honours user-defined pg-pool settings'
it('should take pg-pool setting', function(done) { | ||
// settings can be empty because we do not actually need to connect | ||
var settings = {}; | ||
var dataSource = new DataSource(require('../'), settings); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add var connector = require('..');
to the top of the file.
and change this line to:
var dataSource = new DataSource(connector, settings);
pool._factory.max.should.equal(999); | ||
done(); | ||
}); | ||
}), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change ,
to ;
and add a blank line between the it
and the });
to separate out the tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. That was unintentional.
done(); | ||
}); | ||
}), | ||
it('should take url setting and pg-pool setting', function(done) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it('honours user-defined url settings'
// settings can be empty because we do not actually need to connect | ||
var settings = {}; | ||
var dataSource = new DataSource(require('../'), settings); | ||
dataSource.settings.max = 999; // non-default value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious as to whether the following works:
var settings = {max: 999}; var dataSource = new DataSource(connector, settings);
instead of:
// settings can be empty because we do not actually need to connect var settings = {}; var dataSource = new DataSource(connector, settings); dataSource.settings.max = 999; // non-default value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also verify the pool state before running the tests:
Something like:
pool._factory.max.should.not.equal(999); // or whatever the default is
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Verifying the pool state before running the test will require initializing with defaults. I chose 999 as a non-default value that is very unlikely to ever become the default––currently 10.
}); | ||
}), | ||
it('should take url setting and pg-pool setting', function(done) { | ||
// settings can be empty because we do not actually need to connect |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this comment was copy pasted from test above?
// settings can be empty because we do not actually need to connect | ||
var settings = {url: 'postgres://'}; | ||
var dataSource = new DataSource(require('../'), settings); | ||
dataSource.settings.max = 999; // non-default value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this setting for the test? We shouuld remove this setting since you're testing the url property specifically for this test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also think we should verify the state of the datasource before you run the tests:
Something like:
should.not.exist(datasource.connector.clientConfig) // or whatever the defaults are
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this setting for the test? We shouuld remove this setting since you're testing the url property specifically for this test.
The original bug occurred only in the condition that both url and a user setting was set. I agree those should be independent but they were not.
| ||
var pool = dataSource.connector.pg.pool; | ||
pool._factory.should.have.property('max'); | ||
pool._factory.max.should.equal(999); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the above 3 lines are irrelevant to this test since you already tested in the previous test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original bug occurred only in the condition that both url and a user setting was set. I agree those should be independent but they were not.
We should remove the 3 lines above and create another test for the case you described in this comment.
it('honours multiple user-defined pg-pool settings', ... do the tests for both conditions here
var dataSource = new DataSource(require('../'), settings); | ||
dataSource.settings.max = 999; // non-default value | ||
postgresql.initialize(dataSource, function() { | ||
// dataSource is mutated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can remove this comment too.
Update coming. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost there! ;) Thanks for all the fixups.
| ||
describe('initialization', function() { | ||
it('honours user-defined pg-pool settings', function(done) { | ||
var settings = {'max': 999}; // non-default value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
max key does not need single quotes
{max: 999}
}); | ||
| ||
it('honours user-defined url settings', function(done) { | ||
var settings = {url: 'postgres://', 'max': 999}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
max key does not need single quotes here too
| ||
var pool = dataSource.connector.pg.pool; | ||
pool._factory.should.have.property('max'); | ||
pool._factory.max.should.equal(999); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original bug occurred only in the condition that both url and a user setting was set. I agree those should be independent but they were not.
We should remove the 3 lines above and create another test for the case you described in this comment.
it('honours multiple user-defined pg-pool settings', ... do the tests for both conditions here
var settings = {'max': 999}; // non-default value | ||
var dataSource = new DataSource(connector, settings); | ||
postgresql.initialize(dataSource, function() { | ||
var pool = dataSource.connector.pg.pool; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we can't verify pool state, we can make sure pg was not set before your tests:
should.not.exist(dataSource.connector.pg);
to verify state before your pg pool tests.
Can one of the admins verify this patch? |
@superkhau I fixed the tests as requested. But I noticed in the process that |
@gregdingle Nice one on the simplification. 👍 LGTM -- gonna try to get CI to give us all greens and get it merged. |
@superkhau Is there anything more I need to do here? |
@gregdingle Can you help rebase this PR? CI is failing and I'm trying to see if we can get green before landing. |
@superkhau I rebased and repushed. |
@gregdingle The strange thing is your changes are failing on node 4.x and 6.x on windows, can you fix it? |
</thead> | ||
<tbody> | ||
<tbody> | ||
<tr> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need this change to go with the PR.
var clientConfig = dataSource.connector.clientConfig; | ||
clientConfig.connectionString.should.equal(settings.url); | ||
}); | ||
}); No newline at end of file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need a new line here. PR builder failing cause of that https://cis-jenkins.swg-devops.com/job/nb/job/loopback-connector-postgresql~master/label=x64%20&&%20linux%20&&%20nvm%20&&%20dbs,nodeVersion=6/100/consoleFull#-207526304206f8fc75-e0b9-479e-b471-e8fe633361ff
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, thanks to @dhmlau's commit.
@gregdingle Could you please sign the |
@gregdingle Could you please sign the CLA? |
The failures on Windows are due to the new tests clobbering some state that is shared with the other tests. The reason it is only causing a failure on Windows is because the connection defaults to using the OS username and on Windows the database server does not have that user. |
@rmg How is it passing on local windows with both node4 and node6 then? |
@ssh24 because your local Windows environment has a DB user that matches your Windows username. |
@rmg TY for looking into it. @gregdingle Would you like to make your changes based on @rmg's suggested fixes at #216 and rebase this branch while you're at it so we can land? |
@gregdingle Could you please rebase your code and fix your code according to this changes #216 ? Everything else looks good to me, only needs the test cases with those fixes. |
@ssh24 @superkhau I merged in the fixes from #216. I did not squash the commits so you could see my work. |
@slnode test please |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Waiting for CI to pass and it can be landed.
🥇 😄 👍 |
@gregdingle Thanks for the contribution. Great work and sorry for the delays. ;) |
I'm not familiar with the issue
but it seems like a bug to clear all other settings in this case.
I tested that an app would continue to connect with a connection url.
#185
@raymondfeng