Skip to content

Conversation

gregdingle
Copy link
Contributor

I'm not familiar with the issue

 // pg-pool doesn't handle string config correctly 

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

@slnode
Copy link

slnode commented Oct 28, 2016

Can one of the admins verify this patch? To accept patch and trigger a build add comment ".ok\W+to\W+test."

@slnode
Copy link

slnode commented Oct 28, 2016

Can one of the admins verify this patch?

1 similar comment
@slnode
Copy link

slnode commented Oct 28, 2016

Can one of the admins verify this patch?

@superkhau superkhau self-assigned this Oct 28, 2016
this.constructor.super_.call(this, 'postgresql', settings);
this.clientConfig = settings;
if (settings.url) {
// pg-pool doesn't handle string config correctly
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@superkhau
Copy link
Contributor

Can you add a test to prevent regressions?

@gregdingle
Copy link
Contributor Author

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

On Nov 10, 2016, at 8:58 AM, Simon Ho notifications@github.com wrote:

Can you add a test to prevent regressions?


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub #186 (comment), or mute the thread https://github.com/notifications/unsubscribe-auth/AABwfWojr5p5RVSzsYSbh-tFXGp_gDXFks5q8s6VgaJpZM4KjnW6.

@superkhau
Copy link
Contributor

Feel free to create a new file in the test dir named postgresql.initialization.test.js, inside it should have a describe block like:

describe('initialization', function() { // start with failing test it('fails when'); it('passes when connection string is provided'); }); 
@gregdingle
Copy link
Contributor Author

gregdingle commented Nov 13, 2016

@superkhau I ran into an error trying to run the tests in the project.

Autocreate schema if not exists Connection fails: error: database "strongloop" does not exist It will be retried for the next request. 1) "before all" hook 

The docs say:

The tests in this repository are mainly integration tests, meaning you will need to run them using our preconfigured test server. 1. Ask a core developer for instructions on how to set up test server credentials on your machine 2. `npm test` 

Can you tell me how to set up the test environment? Or can you take care of postgresql.initialization.test.js?

@superkhau
Copy link
Contributor

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

@gregdingle
Copy link
Contributor Author

I added a test as requested to prevent a regression. Although I created a new file, postgresql.initialization.test.js , it only covers the initialization logic related to the bug fix.

@gregdingle
Copy link
Contributor Author

I'm not sure how to fix PR out of date, needs to be rebased . I rebased and re-pushed.

@superkhau
Copy link
Contributor

@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.

@superkhau
Copy link
Contributor

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. 👍

@gregdingle
Copy link
Contributor Author

gregdingle commented Nov 16, 2016

I rebased and re-pushed with the latest master: https://github.com/strongloop/loopback-connector-postgresql/pull/186/commits .

Copy link
Contributor

@superkhau superkhau left a 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');
Copy link
Contributor

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) {
Copy link
Contributor

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);
Copy link
Contributor

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();
});
}),
Copy link
Contributor

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.

Copy link
Contributor Author

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) {
Copy link
Contributor

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
Copy link
Contributor

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 
Copy link
Contributor

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 
Copy link
Contributor Author

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
Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Contributor

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 
Copy link
Contributor Author

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);
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See comment above.

Copy link
Contributor

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
Copy link
Contributor

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.

@gregdingle
Copy link
Contributor Author

Update coming.

Copy link
Contributor

@superkhau superkhau left a 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
Copy link
Contributor

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};
Copy link
Contributor

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);
Copy link
Contributor

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;
Copy link
Contributor

@superkhau superkhau Nov 18, 2016

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.

@slnode
Copy link

slnode commented Nov 18, 2016

Can one of the admins verify this patch?

@gregdingle
Copy link
Contributor Author

@superkhau I fixed the tests as requested. But I noticed in the process that initialize was not necessary, so I simplified the code.

@superkhau
Copy link
Contributor

@gregdingle Nice one on the simplification. 👍 LGTM -- gonna try to get CI to give us all greens and get it merged.

@gregdingle
Copy link
Contributor Author

@superkhau Is there anything more I need to do here?

@superkhau
Copy link
Contributor

@gregdingle Can you help rebase this PR? CI is failing and I'm trying to see if we can get green before landing.

@gregdingle
Copy link
Contributor Author

@superkhau I rebased and repushed.

@superkhau
Copy link
Contributor

superkhau commented Nov 30, 2016

@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>
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

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.

@ssh24
Copy link
Contributor

ssh24 commented Feb 14, 2017

@gregdingle Could you please sign the CLA to proceed with the merge?

@ssh24
Copy link
Contributor

ssh24 commented Feb 17, 2017

@gregdingle Could you please sign the CLA?

@rmg
Copy link
Contributor

rmg commented Feb 17, 2017

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.

@ssh24
Copy link
Contributor

ssh24 commented Feb 17, 2017

@rmg How is it passing on local windows with both node4 and node6 then?

@rmg
Copy link
Contributor

rmg commented Feb 17, 2017

@ssh24 because your local Windows environment has a DB user that matches your Windows username.

@rmg
Copy link
Contributor

rmg commented Feb 17, 2017

@ssh24 see #216 for the changes I had to make.

@superkhau
Copy link
Contributor

superkhau commented Feb 17, 2017

@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?

@kjdelisle kjdelisle modified the milestones: Sprint 30, Sprint 29 Feb 23, 2017
@kjdelisle kjdelisle removed the blocked label Feb 27, 2017
@ssh24
Copy link
Contributor

ssh24 commented Feb 27, 2017

@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.

@kjdelisle kjdelisle added the #wip label Feb 27, 2017
@gregdingle
Copy link
Contributor Author

@ssh24 @superkhau I merged in the fixes from #216. I did not squash the commits so you could see my work.

@ssh24
Copy link
Contributor

ssh24 commented Feb 28, 2017

@slnode test please

Copy link
Contributor

@ssh24 ssh24 left a 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.

@ssh24 ssh24 merged commit 6e33b93 into loopbackio:master Feb 28, 2017
@ssh24 ssh24 removed the #wip label Feb 28, 2017
@gregdingle
Copy link
Contributor Author

🥇 😄 👍

@superkhau
Copy link
Contributor

@gregdingle Thanks for the contribution. Great work and sorry for the delays. ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels