Thread: pgAdmin 4 commit: Ensure we pick up the messages from the currentquery

pgAdmin 4 commit: Ensure we pick up the messages from the currentquery

From
Dave Page
Date:
Ensure we pick up the messages from the current query and not a previous one. Fixes #3094

Branch
------
master

Details
-------
https://git.postgresql.org/gitweb?p=pgadmin4.git;a=commitdiff;h=08b3ccc01a4d57e8ea3657f8882a53dcd1b99386
Author: Khushboo Vashi <khushboo.vashi@enterprisedb.com>

Modified Files
--------------
web/pgadmin/utils/driver/abstract.py          |  1 +
web/pgadmin/utils/driver/psycopg2/__init__.py | 64 +++++++++------------------
2 files changed, 21 insertions(+), 44 deletions(-)


Re: pgAdmin 4 commit: Ensure we pick up the messages from the current query

From
Murtuza Zabuawala
Date:
Hi Khushboo/Dave,

With given commit, I'm again seeing the issue raised in https://redmine.postgresql.org/issues/1523 :(




--
Regards,
Murtuza Zabuawala
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


On Mon, Feb 26, 2018 at 7:49 PM, Dave Page <dpage@pgadmin.org> wrote:
Ensure we pick up the messages from the current query and not a previous one. Fixes #3094

Branch
------
master

Details
-------
https://git.postgresql.org/gitweb?p=pgadmin4.git;a=commitdiff;h=08b3ccc01a4d57e8ea3657f8882a53dcd1b99386
Author: Khushboo Vashi <khushboo.vashi@enterprisedb.com>

Modified Files
--------------
web/pgadmin/utils/driver/abstract.py          |  1 +
web/pgadmin/utils/driver/psycopg2/__init__.py | 64 +++++++++------------------
2 files changed, 21 insertions(+), 44 deletions(-)


Re: pgAdmin 4 commit: Ensure we pick up the messages from the current query

From
Murtuza Zabuawala
Date:
Sent bit early, 

You can run 'VACUUM FULL VERBOSE' in query tool and verify the populated messages (pgAdmin3 vs. pgAdmin4). 


On Mon, Feb 26, 2018 at 9:48 PM, Murtuza Zabuawala <murtuza.zabuawala@enterprisedb.com> wrote:
Hi Khushboo/Dave,

With given commit, I'm again seeing the issue raised in https://redmine.postgresql.org/issues/1523 :(




--
Regards,
Murtuza Zabuawala
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


On Mon, Feb 26, 2018 at 7:49 PM, Dave Page <dpage@pgadmin.org> wrote:
Ensure we pick up the messages from the current query and not a previous one. Fixes #3094

Branch
------
master

Details
-------
https://git.postgresql.org/gitweb?p=pgadmin4.git;a=commitdiff;h=08b3ccc01a4d57e8ea3657f8882a53dcd1b99386
Author: Khushboo Vashi <khushboo.vashi@enterprisedb.com>

Modified Files
--------------
web/pgadmin/utils/driver/abstract.py          |  1 +
web/pgadmin/utils/driver/psycopg2/__init__.py | 64 +++++++++------------------
2 files changed, 21 insertions(+), 44 deletions(-)



Re: pgAdmin 4 commit: Ensure we pick up the messages from the current query

From
Dave Page
Date:
Argh, I ran some tests, but didn't spot any lost messages in the tests I ran. I'll revert the patch.

Khushboo;

Please look at the following:

- Fix the patch so it doesn't drop messages.
- Add regression tests to make sure it doesn't break in the future. This may require creating one or more functions the spew out a whole lot of notices, and then running a couple of queries and checking the output.
- Check the messages panel on the history tab. I just noticed it seems to only be showing an even smaller subset of the messages.

Thanks.

On Mon, Feb 26, 2018 at 4:23 PM, Murtuza Zabuawala <murtuza.zabuawala@enterprisedb.com> wrote:
Sent bit early, 

You can run 'VACUUM FULL VERBOSE' in query tool and verify the populated messages (pgAdmin3 vs. pgAdmin4). 


On Mon, Feb 26, 2018 at 9:48 PM, Murtuza Zabuawala <murtuza.zabuawala@enterprisedb.com> wrote:
Hi Khushboo/Dave,

With given commit, I'm again seeing the issue raised in https://redmine.postgresql.org/issues/1523 :(




--
Regards,
Murtuza Zabuawala
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


On Mon, Feb 26, 2018 at 7:49 PM, Dave Page <dpage@pgadmin.org> wrote:
Ensure we pick up the messages from the current query and not a previous one. Fixes #3094

Branch
------
master

Details
-------
https://git.postgresql.org/gitweb?p=pgadmin4.git;a=commitdiff;h=08b3ccc01a4d57e8ea3657f8882a53dcd1b99386
Author: Khushboo Vashi <khushboo.vashi@enterprisedb.com>

Modified Files
--------------
web/pgadmin/utils/driver/abstract.py          |  1 +
web/pgadmin/utils/driver/psycopg2/__init__.py | 64 +++++++++------------------
2 files changed, 21 insertions(+), 44 deletions(-)






--
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

Re: pgAdmin 4 commit: Ensure we pick up the messages from the current query

From
Murtuza Zabuawala
Date:
FYI, This is what I'm receiving(attachments) when I'm running vacuum full verbose on my PG10.
​​


On Mon, Feb 26, 2018 at 10:02 PM, Dave Page <dpage@pgadmin.org> wrote:
Argh, I ran some tests, but didn't spot any lost messages in the tests I ran. I'll revert the patch.

Khushboo;

Please look at the following:

- Fix the patch so it doesn't drop messages.
- Add regression tests to make sure it doesn't break in the future. This may require creating one or more functions the spew out a whole lot of notices, and then running a couple of queries and checking the output.
- Check the messages panel on the history tab. I just noticed it seems to only be showing an even smaller subset of the messages.

Thanks.

On Mon, Feb 26, 2018 at 4:23 PM, Murtuza Zabuawala <murtuza.zabuawala@enterprisedb.com> wrote:
Sent bit early, 

You can run 'VACUUM FULL VERBOSE' in query tool and verify the populated messages (pgAdmin3 vs. pgAdmin4). 


On Mon, Feb 26, 2018 at 9:48 PM, Murtuza Zabuawala <murtuza.zabuawala@enterprisedb.com> wrote:
Hi Khushboo/Dave,

With given commit, I'm again seeing the issue raised in https://redmine.postgresql.org/issues/1523 :(




--
Regards,
Murtuza Zabuawala
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


On Mon, Feb 26, 2018 at 7:49 PM, Dave Page <dpage@pgadmin.org> wrote:
Ensure we pick up the messages from the current query and not a previous one. Fixes #3094

Branch
------
master

Details
-------
https://git.postgresql.org/gitweb?p=pgadmin4.git;a=commitdiff;h=08b3ccc01a4d57e8ea3657f8882a53dcd1b99386
Author: Khushboo Vashi <khushboo.vashi@enterprisedb.com>

Modified Files
--------------
web/pgadmin/utils/driver/abstract.py          |  1 +
web/pgadmin/utils/driver/psycopg2/__init__.py | 64 +++++++++------------------
2 files changed, 21 insertions(+), 44 deletions(-)






--
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

Attachment

Re: pgAdmin 4 commit: Ensure we pick up the messages from the current query

From
Khushboo Vashi
Date:
On Mon, Feb 26, 2018 at 10:02 PM, Dave Page <dpage@pgadmin.org> wrote:
Argh, I ran some tests, but didn't spot any lost messages in the tests I ran. I'll revert the patch.

Khushboo;

Please look at the following:

- Fix the patch so it doesn't drop messages.
Fixed.
By default, the notice attribute of the connection object of psycopg 2 only stores 50 notices. Once it reaches to 50 it starts from 1 again.
To fix this I have changed the notice attribute from list to deque to append more messages. Currently I have kept the maximum limit at a time of the notice attribute is 100000 (in a single poll). 
- Add regression tests to make sure it doesn't break in the future. This may require creating one or more functions the spew out a whole lot of notices, and then running a couple of queries and checking the output.
Added. With this regression test, the current code is failing which has been taken care in this patch.
- Check the messages panel on the history tab. I just noticed it seems to only be showing an even smaller subset of the messages.
Tested and no issues found.
 
Thanks.

On Mon, Feb 26, 2018 at 4:23 PM, Murtuza Zabuawala <murtuza.zabuawala@enterprisedb.com> wrote:
Sent bit early, 

You can run 'VACUUM FULL VERBOSE' in query tool and verify the populated messages (pgAdmin3 vs. pgAdmin4). 


On Mon, Feb 26, 2018 at 9:48 PM, Murtuza Zabuawala <murtuza.zabuawala@enterprisedb.com> wrote:
Hi Khushboo/Dave,

With given commit, I'm again seeing the issue raised in https://redmine.postgresql.org/issues/1523 :(




--
Regards,
Murtuza Zabuawala
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


On Mon, Feb 26, 2018 at 7:49 PM, Dave Page <dpage@pgadmin.org> wrote:
Ensure we pick up the messages from the current query and not a previous one. Fixes #3094

Branch
------
master

Details
-------
https://git.postgresql.org/gitweb?p=pgadmin4.git;a=commitdiff;h=08b3ccc01a4d57e8ea3657f8882a53dcd1b99386
Author: Khushboo Vashi <khushboo.vashi@enterprisedb.com>

Modified Files
--------------
web/pgadmin/utils/driver/abstract.py          |  1 +
web/pgadmin/utils/driver/psycopg2/__init__.py | 64 +++++++++------------------
2 files changed, 21 insertions(+), 44 deletions(-)






--
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

Attachment

Re: pgAdmin 4 commit: Ensure we pick up the messages from the current query

From
Joao De Almeida Pereira
Date:
Hello Khushboo,
After reviewing the patch I have the gut feeling that we do not have enough test coverage on this issue, specially due to the intricate while loop and conditions around the polling.
I think that this deserve Unit tests around it, When I say Unit Test I am not talking about executing queries against the database, but do some stubbing of the database so that we can control the flow that we want.

It is a temptation to try to always do a Feature Test to test what we want because it is "easier" to write and ultimately it is what users see, but while 1 Feature Test runs we can run 200 Unit Tests that give us much more confidence that the code is doing what we expect it to do.

This being said, I run the tests on the CI Pipeline and all tests pass. Running pycodestyle fails due to some line sizes on the psycopg2/__init__py. I believe that it is not what you changed, but since you were changing the file it can be fixed it is just:

pgadmin/utils/driver/psycopg2/__init__.py:1276: [E501] line too long (81 > 79 characters)
pgadmin/utils/driver/psycopg2/__init__.py:1277: [E501] line too long (91 > 79 characters)
pgadmin/utils/driver/psycopg2/__init__.py:1282: [E501] line too long (81 > 79 characters)
pgadmin/utils/driver/psycopg2/__init__.py:1283: [E501] line too long (91 > 79 characters)
4       E501 line too long (81 > 79 characters)


Thanks
Joao


On Wed, Feb 28, 2018 at 6:49 AM Khushboo Vashi <khushboo.vashi@enterprisedb.com> wrote:
On Mon, Feb 26, 2018 at 10:02 PM, Dave Page <dpage@pgadmin.org> wrote:
Argh, I ran some tests, but didn't spot any lost messages in the tests I ran. I'll revert the patch.

Khushboo;

Please look at the following:

- Fix the patch so it doesn't drop messages.
Fixed.
By default, the notice attribute of the connection object of psycopg 2 only stores 50 notices. Once it reaches to 50 it starts from 1 again.
To fix this I have changed the notice attribute from list to deque to append more messages. Currently I have kept the maximum limit at a time of the notice attribute is 100000 (in a single poll). 
- Add regression tests to make sure it doesn't break in the future. This may require creating one or more functions the spew out a whole lot of notices, and then running a couple of queries and checking the output.
Added. With this regression test, the current code is failing which has been taken care in this patch.
- Check the messages panel on the history tab. I just noticed it seems to only be showing an even smaller subset of the messages.
Tested and no issues found.
 
Thanks.

On Mon, Feb 26, 2018 at 4:23 PM, Murtuza Zabuawala <murtuza.zabuawala@enterprisedb.com> wrote:
Sent bit early, 

You can run 'VACUUM FULL VERBOSE' in query tool and verify the populated messages (pgAdmin3 vs. pgAdmin4). 


On Mon, Feb 26, 2018 at 9:48 PM, Murtuza Zabuawala <murtuza.zabuawala@enterprisedb.com> wrote:
Hi Khushboo/Dave,

With given commit, I'm again seeing the issue raised in https://redmine.postgresql.org/issues/1523 :(




--
Regards,
Murtuza Zabuawala
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


On Mon, Feb 26, 2018 at 7:49 PM, Dave Page <dpage@pgadmin.org> wrote:
Ensure we pick up the messages from the current query and not a previous one. Fixes #3094

Branch
------
master

Details
-------
https://git.postgresql.org/gitweb?p=pgadmin4.git;a=commitdiff;h=08b3ccc01a4d57e8ea3657f8882a53dcd1b99386
Author: Khushboo Vashi <khushboo.vashi@enterprisedb.com>

Modified Files
--------------
web/pgadmin/utils/driver/abstract.py          |  1 +
web/pgadmin/utils/driver/psycopg2/__init__.py | 64 +++++++++------------------
2 files changed, 21 insertions(+), 44 deletions(-)






--
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

Re: pgAdmin 4 commit: Ensure we pick up the messages from the current query

From
Khushboo Vashi
Date:
Hi Joao,

Thanks for reviewing.

On Wed, Feb 28, 2018 at 8:55 PM, Joao De Almeida Pereira <jdealmeidapereira@pivotal.io> wrote:
Hello Khushboo,
After reviewing the patch I have the gut feeling that we do not have enough test coverage on this issue, specially due to the intricate while loop and conditions around the polling.
I think that this deserve Unit tests around it, When I say Unit Test I am not talking about executing queries against the database, but do some stubbing of the database so that we can control the flow that we want.
You are right. It needs more unit testing. I have checked below scenarios:
1. Returns 2 notices with data output
2. Returns 1000 notices with data output
3. No notices with data output 

By running above, I have checked, each time returned notices are accurate, no old notices are getting appended, it does not affect with the amount of messages (few, none or more).  Also, with the updated patch, I have made sure that all these queries run with the single transaction id (same connection).

So, please let me know if you think I can add more things to this.
  
It is a temptation to try to always do a Feature Test to test what we want because it is "easier" to write and ultimately it is what users see, but while 1 Feature Test runs we can run 200 Unit Tests that give us much more confidence that the code is doing what we expect it to do.

Right, so added regression tests instead of feature tests. 

This being said, I run the tests on the CI Pipeline and all tests pass. Running pycodestyle fails due to some line sizes on the psycopg2/__init__py. I believe that it is not what you changed, but since you were changing the file it can be fixed it is just:

pgadmin/utils/driver/psycopg2/__init__.py:1276: [E501] line too long (81 > 79 characters)
pgadmin/utils/driver/psycopg2/__init__.py:1277: [E501] line too long (91 > 79 characters)
pgadmin/utils/driver/psycopg2/__init__.py:1282: [E501] line too long (81 > 79 characters)
pgadmin/utils/driver/psycopg2/__init__.py:1283: [E501] line too long (91 > 79 characters)
4       E501 line too long (81 > 79 characters)

Fixed. Thanks for pointing out. 

Thanks
Joao


On Wed, Feb 28, 2018 at 6:49 AM Khushboo Vashi <khushboo.vashi@enterprisedb.com> wrote:
On Mon, Feb 26, 2018 at 10:02 PM, Dave Page <dpage@pgadmin.org> wrote:
Argh, I ran some tests, but didn't spot any lost messages in the tests I ran. I'll revert the patch.

Khushboo;

Please look at the following:

- Fix the patch so it doesn't drop messages.
Fixed.
By default, the notice attribute of the connection object of psycopg 2 only stores 50 notices. Once it reaches to 50 it starts from 1 again.
To fix this I have changed the notice attribute from list to deque to append more messages. Currently I have kept the maximum limit at a time of the notice attribute is 100000 (in a single poll). 
- Add regression tests to make sure it doesn't break in the future. This may require creating one or more functions the spew out a whole lot of notices, and then running a couple of queries and checking the output.
Added. With this regression test, the current code is failing which has been taken care in this patch.
- Check the messages panel on the history tab. I just noticed it seems to only be showing an even smaller subset of the messages.
Tested and no issues found.
 
Thanks.

On Mon, Feb 26, 2018 at 4:23 PM, Murtuza Zabuawala <murtuza.zabuawala@enterprisedb.com> wrote:
Sent bit early, 

You can run 'VACUUM FULL VERBOSE' in query tool and verify the populated messages (pgAdmin3 vs. pgAdmin4). 


On Mon, Feb 26, 2018 at 9:48 PM, Murtuza Zabuawala <murtuza.zabuawala@enterprisedb.com> wrote:
Hi Khushboo/Dave,

With given commit, I'm again seeing the issue raised in https://redmine.postgresql.org/issues/1523 :(




--
Regards,
Murtuza Zabuawala
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


On Mon, Feb 26, 2018 at 7:49 PM, Dave Page <dpage@pgadmin.org> wrote:
Ensure we pick up the messages from the current query and not a previous one. Fixes #3094

Branch
------
master

Details
-------
https://git.postgresql.org/gitweb?p=pgadmin4.git;a=commitdiff;h=08b3ccc01a4d57e8ea3657f8882a53dcd1b99386
Author: Khushboo Vashi <khushboo.vashi@enterprisedb.com>

Modified Files
--------------
web/pgadmin/utils/driver/abstract.py          |  1 +
web/pgadmin/utils/driver/psycopg2/__init__.py | 64 +++++++++------------------
2 files changed, 21 insertions(+), 44 deletions(-)






--
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

Attachment

Re: pgAdmin 4 commit: Ensure we pick up the messages from the current query

From
Joao De Almeida Pereira
Date:
Hello Khushboo,
The patch runs successfully in our CI with all tests passing.

I see the test that you created, and I do not understand why we need to create tests that do HTTP requests in order to check something that is executed against the database. What I was talking about in my previous email was having tests that tested the function by itself.

 

This is the Testing Pyramid, there are a bunch of different drawings of it and ways to explain it, but in broad stokes what is means is that we should have the majority of tests around a Unit (that are some disagreements in the community of what a Unit is) and a very small amount of Manual testing. What Unit usually means is piece of code, it can be a function, it can be a class or it can even be a module, but is something self contained. In pgAdmin's case the majority of our tests go around the Integration Layer because we are using HTTP requests in order to executing queries in the database, so basically we are doing tests end to end in the backend, and the cost time.

I do not want to held this patch back because of this, and I say this because I have minimal confidence with the tests that you created, that they would catch the majority of the problems, and hope that the majority of the code is exercised by it.

Nevertheless I would like to challenge all the Hackers to think about testing in a different way. The tests in our code are used to give us confidence that the work we did is working as expected, this also makes it much easier to refactor out bad patterns or very complicated ones into something simple. A signal that our code is more complicated then it should is when we need to test some behavior and we end up with a Stubbing Hell or we need to test it End 2 End because it is to hard to isolate the part we want to test. In the other hand we should not test all functions and every class, because we might be coupling our tests to much to the implementation and that will have the contrary effect, and we will not be able to refactor and simply our code.
Like everything in life there need to be a balance.

Thanks
Joao

On Thu, Mar 1, 2018 at 12:56 AM Khushboo Vashi <khushboo.vashi@enterprisedb.com> wrote:
Hi Joao,

Thanks for reviewing.

On Wed, Feb 28, 2018 at 8:55 PM, Joao De Almeida Pereira <jdealmeidapereira@pivotal.io> wrote:
Hello Khushboo,
After reviewing the patch I have the gut feeling that we do not have enough test coverage on this issue, specially due to the intricate while loop and conditions around the polling.
I think that this deserve Unit tests around it, When I say Unit Test I am not talking about executing queries against the database, but do some stubbing of the database so that we can control the flow that we want.
You are right. It needs more unit testing. I have checked below scenarios:
1. Returns 2 notices with data output
2. Returns 1000 notices with data output
3. No notices with data output 

By running above, I have checked, each time returned notices are accurate, no old notices are getting appended, it does not affect with the amount of messages (few, none or more).  Also, with the updated patch, I have made sure that all these queries run with the single transaction id (same connection).

So, please let me know if you think I can add more things to this.
  
It is a temptation to try to always do a Feature Test to test what we want because it is "easier" to write and ultimately it is what users see, but while 1 Feature Test runs we can run 200 Unit Tests that give us much more confidence that the code is doing what we expect it to do.

Right, so added regression tests instead of feature tests. 

This being said, I run the tests on the CI Pipeline and all tests pass. Running pycodestyle fails due to some line sizes on the psycopg2/__init__py. I believe that it is not what you changed, but since you were changing the file it can be fixed it is just:

pgadmin/utils/driver/psycopg2/__init__.py:1276: [E501] line too long (81 > 79 characters)
pgadmin/utils/driver/psycopg2/__init__.py:1277: [E501] line too long (91 > 79 characters)
pgadmin/utils/driver/psycopg2/__init__.py:1282: [E501] line too long (81 > 79 characters)
pgadmin/utils/driver/psycopg2/__init__.py:1283: [E501] line too long (91 > 79 characters)
4       E501 line too long (81 > 79 characters)

Fixed. Thanks for pointing out. 

Thanks
Joao


On Wed, Feb 28, 2018 at 6:49 AM Khushboo Vashi <khushboo.vashi@enterprisedb.com> wrote:
On Mon, Feb 26, 2018 at 10:02 PM, Dave Page <dpage@pgadmin.org> wrote:
Argh, I ran some tests, but didn't spot any lost messages in the tests I ran. I'll revert the patch.

Khushboo;

Please look at the following:

- Fix the patch so it doesn't drop messages.
Fixed.
By default, the notice attribute of the connection object of psycopg 2 only stores 50 notices. Once it reaches to 50 it starts from 1 again.
To fix this I have changed the notice attribute from list to deque to append more messages. Currently I have kept the maximum limit at a time of the notice attribute is 100000 (in a single poll). 
- Add regression tests to make sure it doesn't break in the future. This may require creating one or more functions the spew out a whole lot of notices, and then running a couple of queries and checking the output.
Added. With this regression test, the current code is failing which has been taken care in this patch.
- Check the messages panel on the history tab. I just noticed it seems to only be showing an even smaller subset of the messages.
Tested and no issues found.
 
Thanks.

On Mon, Feb 26, 2018 at 4:23 PM, Murtuza Zabuawala <murtuza.zabuawala@enterprisedb.com> wrote:
Sent bit early, 

You can run 'VACUUM FULL VERBOSE' in query tool and verify the populated messages (pgAdmin3 vs. pgAdmin4). 


On Mon, Feb 26, 2018 at 9:48 PM, Murtuza Zabuawala <murtuza.zabuawala@enterprisedb.com> wrote:
Hi Khushboo/Dave,

With given commit, I'm again seeing the issue raised in https://redmine.postgresql.org/issues/1523 :(




--
Regards,
Murtuza Zabuawala
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


On Mon, Feb 26, 2018 at 7:49 PM, Dave Page <dpage@pgadmin.org> wrote:
Ensure we pick up the messages from the current query and not a previous one. Fixes #3094

Branch
------
master

Details
-------
https://git.postgresql.org/gitweb?p=pgadmin4.git;a=commitdiff;h=08b3ccc01a4d57e8ea3657f8882a53dcd1b99386
Author: Khushboo Vashi <khushboo.vashi@enterprisedb.com>

Modified Files
--------------
web/pgadmin/utils/driver/abstract.py          |  1 +
web/pgadmin/utils/driver/psycopg2/__init__.py | 64 +++++++++------------------
2 files changed, 21 insertions(+), 44 deletions(-)






--
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
Could you rebase this please? It no longer applies.

Thanks.

On Thu, Mar 1, 2018 at 5:56 AM, Khushboo Vashi <khushboo.vashi@enterprisedb.com> wrote:
Hi Joao,

Thanks for reviewing.

On Wed, Feb 28, 2018 at 8:55 PM, Joao De Almeida Pereira <jdealmeidapereira@pivotal.io> wrote:
Hello Khushboo,
After reviewing the patch I have the gut feeling that we do not have enough test coverage on this issue, specially due to the intricate while loop and conditions around the polling.
I think that this deserve Unit tests around it, When I say Unit Test I am not talking about executing queries against the database, but do some stubbing of the database so that we can control the flow that we want.
You are right. It needs more unit testing. I have checked below scenarios:
1. Returns 2 notices with data output
2. Returns 1000 notices with data output
3. No notices with data output 

By running above, I have checked, each time returned notices are accurate, no old notices are getting appended, it does not affect with the amount of messages (few, none or more).  Also, with the updated patch, I have made sure that all these queries run with the single transaction id (same connection).

So, please let me know if you think I can add more things to this.
  
It is a temptation to try to always do a Feature Test to test what we want because it is "easier" to write and ultimately it is what users see, but while 1 Feature Test runs we can run 200 Unit Tests that give us much more confidence that the code is doing what we expect it to do.

Right, so added regression tests instead of feature tests. 

This being said, I run the tests on the CI Pipeline and all tests pass. Running pycodestyle fails due to some line sizes on the psycopg2/__init__py. I believe that it is not what you changed, but since you were changing the file it can be fixed it is just:

pgadmin/utils/driver/psycopg2/__init__.py:1276: [E501] line too long (81 > 79 characters)
pgadmin/utils/driver/psycopg2/__init__.py:1277: [E501] line too long (91 > 79 characters)
pgadmin/utils/driver/psycopg2/__init__.py:1282: [E501] line too long (81 > 79 characters)
pgadmin/utils/driver/psycopg2/__init__.py:1283: [E501] line too long (91 > 79 characters)
4       E501 line too long (81 > 79 characters)

Fixed. Thanks for pointing out. 

Thanks
Joao


On Wed, Feb 28, 2018 at 6:49 AM Khushboo Vashi <khushboo.vashi@enterprisedb.com> wrote:
On Mon, Feb 26, 2018 at 10:02 PM, Dave Page <dpage@pgadmin.org> wrote:
Argh, I ran some tests, but didn't spot any lost messages in the tests I ran. I'll revert the patch.

Khushboo;

Please look at the following:

- Fix the patch so it doesn't drop messages.
Fixed.
By default, the notice attribute of the connection object of psycopg 2 only stores 50 notices. Once it reaches to 50 it starts from 1 again.
To fix this I have changed the notice attribute from list to deque to append more messages. Currently I have kept the maximum limit at a time of the notice attribute is 100000 (in a single poll). 
- Add regression tests to make sure it doesn't break in the future. This may require creating one or more functions the spew out a whole lot of notices, and then running a couple of queries and checking the output.
Added. With this regression test, the current code is failing which has been taken care in this patch.
- Check the messages panel on the history tab. I just noticed it seems to only be showing an even smaller subset of the messages.
Tested and no issues found.
 
Thanks.

On Mon, Feb 26, 2018 at 4:23 PM, Murtuza Zabuawala <murtuza.zabuawala@enterprisedb.com> wrote:
Sent bit early, 

You can run 'VACUUM FULL VERBOSE' in query tool and verify the populated messages (pgAdmin3 vs. pgAdmin4). 


On Mon, Feb 26, 2018 at 9:48 PM, Murtuza Zabuawala <murtuza.zabuawala@enterprisedb.com> wrote:
Hi Khushboo/Dave,

With given commit, I'm again seeing the issue raised in https://redmine.postgresql.org/issues/1523 :(




--
Regards,
Murtuza Zabuawala
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


On Mon, Feb 26, 2018 at 7:49 PM, Dave Page <dpage@pgadmin.org> wrote:
Ensure we pick up the messages from the current query and not a previous one. Fixes #3094

Branch
------
master

Details
-------
https://git.postgresql.org/gitweb?p=pgadmin4.git;a=commitdiff;h=08b3ccc01a4d57e8ea3657f8882a53dcd1b99386
Author: Khushboo Vashi <khushboo.vashi@enterprisedb.com>

Modified Files
--------------
web/pgadmin/utils/driver/abstract.py          |  1 +
web/pgadmin/utils/driver/psycopg2/__init__.py | 64 +++++++++------------------
2 files changed, 21 insertions(+), 44 deletions(-)






--
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company




--
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


On Thu, Mar 1, 2018 at 3:21 PM, Joao De Almeida Pereira <jdealmeidapereira@pivotal.io> wrote:
Hello Khushboo,
The patch runs successfully in our CI with all tests passing.

I see the test that you created, and I do not understand why we need to create tests that do HTTP requests in order to check something that is executed against the database. What I was talking about in my previous email was having tests that tested the function by itself.

 

This is the Testing Pyramid, there are a bunch of different drawings of it and ways to explain it, but in broad stokes what is means is that we should have the majority of tests around a Unit (that are some disagreements in the community of what a Unit is) and a very small amount of Manual testing. What Unit usually means is piece of code, it can be a function, it can be a class or it can even be a module, but is something self contained. In pgAdmin's case the majority of our tests go around the Integration Layer because we are using HTTP requests in order to executing queries in the database, so basically we are doing tests end to end in the backend, and the cost time.

I do not want to held this patch back because of this, and I say this because I have minimal confidence with the tests that you created, that they would catch the majority of the problems, and hope that the majority of the code is exercised by it.

Nevertheless I would like to challenge all the Hackers to think about testing in a different way. The tests in our code are used to give us confidence that the work we did is working as expected, this also makes it much easier to refactor out bad patterns or very complicated ones into something simple. A signal that our code is more complicated then it should is when we need to test some behavior and we end up with a Stubbing Hell or we need to test it End 2 End because it is to hard to isolate the part we want to test. In the other hand we should not test all functions and every class, because we might be coupling our tests to much to the implementation and that will have the contrary effect, and we will not be able to refactor and simply our code.
Like everything in life there need to be a balance.

I think that is very good advice, and I would also like to encourage all the developers to think this way. However, I would also caution against underestimating the importance of our feature tests. It is obviously important to have confidence that our code is robust and functions correctly at the unit level, but that doesn't mean that it all works together as expected to provide the user functionality we desire. I think the feature tests are critical in this regard; they protect us against class of bug that might otherwise be missed without manual testing that we strive to eliminate entirely. For the EDBers on the team, think of the feature tests in terms of what we normally call integration testing; ensuring that not only do the individual pieces work as they should, but that they work together as they should. 

--
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

Re: pgAdmin 4 commit: Ensure we pick up the messages from the current query

From
Joao De Almeida Pereira
Date:
Hello Dave,

Very well said, I didn't intended to say that Feature Tests are not important, what I was saying is that when we can do faster and more thorough tests we should take it. All the tests that we do are important to ensure that the software we produce is of good quality.

Also the higher you go in the pyramid the more volatile the test are and more variables need to be taken into account when doing them.

Thanks
Joao

On Fri, Mar 2, 2018 at 8:31 AM Dave Page <dpage@pgadmin.org> wrote:
On Thu, Mar 1, 2018 at 3:21 PM, Joao De Almeida Pereira <jdealmeidapereira@pivotal.io> wrote:
Hello Khushboo,
The patch runs successfully in our CI with all tests passing.

I see the test that you created, and I do not understand why we need to create tests that do HTTP requests in order to check something that is executed against the database. What I was talking about in my previous email was having tests that tested the function by itself.

 

This is the Testing Pyramid, there are a bunch of different drawings of it and ways to explain it, but in broad stokes what is means is that we should have the majority of tests around a Unit (that are some disagreements in the community of what a Unit is) and a very small amount of Manual testing. What Unit usually means is piece of code, it can be a function, it can be a class or it can even be a module, but is something self contained. In pgAdmin's case the majority of our tests go around the Integration Layer because we are using HTTP requests in order to executing queries in the database, so basically we are doing tests end to end in the backend, and the cost time.

I do not want to held this patch back because of this, and I say this because I have minimal confidence with the tests that you created, that they would catch the majority of the problems, and hope that the majority of the code is exercised by it.

Nevertheless I would like to challenge all the Hackers to think about testing in a different way. The tests in our code are used to give us confidence that the work we did is working as expected, this also makes it much easier to refactor out bad patterns or very complicated ones into something simple. A signal that our code is more complicated then it should is when we need to test some behavior and we end up with a Stubbing Hell or we need to test it End 2 End because it is to hard to isolate the part we want to test. In the other hand we should not test all functions and every class, because we might be coupling our tests to much to the implementation and that will have the contrary effect, and we will not be able to refactor and simply our code.
Like everything in life there need to be a balance.

I think that is very good advice, and I would also like to encourage all the developers to think this way. However, I would also caution against underestimating the importance of our feature tests. It is obviously important to have confidence that our code is robust and functions correctly at the unit level, but that doesn't mean that it all works together as expected to provide the user functionality we desire. I think the feature tests are critical in this regard; they protect us against class of bug that might otherwise be missed without manual testing that we strive to eliminate entirely. For the EDBers on the team, think of the feature tests in terms of what we normally call integration testing; ensuring that not only do the individual pieces work as they should, but that they work together as they should. 

--
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

Re: pgAdmin 4 commit: Ensure we pick up the messages from the current query

From
Khushboo Vashi
Date:


On Fri, Mar 2, 2018 at 6:55 PM, Dave Page <dpage@pgadmin.org> wrote:
Could you rebase this please? It no longer applies.

Please find the attached updated patch. 
Thanks.

On Thu, Mar 1, 2018 at 5:56 AM, Khushboo Vashi <khushboo.vashi@enterprisedb.com> wrote:
Hi Joao,

Thanks for reviewing.

On Wed, Feb 28, 2018 at 8:55 PM, Joao De Almeida Pereira <jdealmeidapereira@pivotal.io> wrote:
Hello Khushboo,
After reviewing the patch I have the gut feeling that we do not have enough test coverage on this issue, specially due to the intricate while loop and conditions around the polling.
I think that this deserve Unit tests around it, When I say Unit Test I am not talking about executing queries against the database, but do some stubbing of the database so that we can control the flow that we want.
You are right. It needs more unit testing. I have checked below scenarios:
1. Returns 2 notices with data output
2. Returns 1000 notices with data output
3. No notices with data output 

By running above, I have checked, each time returned notices are accurate, no old notices are getting appended, it does not affect with the amount of messages (few, none or more).  Also, with the updated patch, I have made sure that all these queries run with the single transaction id (same connection).

So, please let me know if you think I can add more things to this.
  
It is a temptation to try to always do a Feature Test to test what we want because it is "easier" to write and ultimately it is what users see, but while 1 Feature Test runs we can run 200 Unit Tests that give us much more confidence that the code is doing what we expect it to do.

Right, so added regression tests instead of feature tests. 

This being said, I run the tests on the CI Pipeline and all tests pass. Running pycodestyle fails due to some line sizes on the psycopg2/__init__py. I believe that it is not what you changed, but since you were changing the file it can be fixed it is just:

pgadmin/utils/driver/psycopg2/__init__.py:1276: [E501] line too long (81 > 79 characters)
pgadmin/utils/driver/psycopg2/__init__.py:1277: [E501] line too long (91 > 79 characters)
pgadmin/utils/driver/psycopg2/__init__.py:1282: [E501] line too long (81 > 79 characters)
pgadmin/utils/driver/psycopg2/__init__.py:1283: [E501] line too long (91 > 79 characters)
4       E501 line too long (81 > 79 characters)

Fixed. Thanks for pointing out. 

Thanks
Joao


On Wed, Feb 28, 2018 at 6:49 AM Khushboo Vashi <khushboo.vashi@enterprisedb.com> wrote:
On Mon, Feb 26, 2018 at 10:02 PM, Dave Page <dpage@pgadmin.org> wrote:
Argh, I ran some tests, but didn't spot any lost messages in the tests I ran. I'll revert the patch.

Khushboo;

Please look at the following:

- Fix the patch so it doesn't drop messages.
Fixed.
By default, the notice attribute of the connection object of psycopg 2 only stores 50 notices. Once it reaches to 50 it starts from 1 again.
To fix this I have changed the notice attribute from list to deque to append more messages. Currently I have kept the maximum limit at a time of the notice attribute is 100000 (in a single poll). 
- Add regression tests to make sure it doesn't break in the future. This may require creating one or more functions the spew out a whole lot of notices, and then running a couple of queries and checking the output.
Added. With this regression test, the current code is failing which has been taken care in this patch.
- Check the messages panel on the history tab. I just noticed it seems to only be showing an even smaller subset of the messages.
Tested and no issues found.
 
Thanks.

On Mon, Feb 26, 2018 at 4:23 PM, Murtuza Zabuawala <murtuza.zabuawala@enterprisedb.com> wrote:
Sent bit early, 

You can run 'VACUUM FULL VERBOSE' in query tool and verify the populated messages (pgAdmin3 vs. pgAdmin4). 


On Mon, Feb 26, 2018 at 9:48 PM, Murtuza Zabuawala <murtuza.zabuawala@enterprisedb.com> wrote:
Hi Khushboo/Dave,

With given commit, I'm again seeing the issue raised in https://redmine.postgresql.org/issues/1523 :(




--
Regards,
Murtuza Zabuawala
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


On Mon, Feb 26, 2018 at 7:49 PM, Dave Page <dpage@pgadmin.org> wrote:
Ensure we pick up the messages from the current query and not a previous one. Fixes #3094

Branch
------
master

Details
-------
https://git.postgresql.org/gitweb?p=pgadmin4.git;a=commitdiff;h=08b3ccc01a4d57e8ea3657f8882a53dcd1b99386
Author: Khushboo Vashi <khushboo.vashi@enterprisedb.com>

Modified Files
--------------
web/pgadmin/utils/driver/abstract.py          |  1 +
web/pgadmin/utils/driver/psycopg2/__init__.py | 64 +++++++++------------------
2 files changed, 21 insertions(+), 44 deletions(-)






--
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company




--
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

Attachment

Re: pgAdmin 4 commit: Ensure we pick up the messages from the current query

From
Joao De Almeida Pereira
Date:
Hello Khushboo,
Looks like we are almost doen, just missing one PEP-8 issue:
→ pycodestyle --config=.pycodestyle pgadmin/tools
pgadmin/tools/sqleditor/tests/test_poll_query_tool.py:46: [E126] continuation line over-indented for hanging indent
1       E126 continuation line over-indented for hanging indent
1


The tests run successfully in our CI pipeline.

Thanks
Joao

On Sun, Mar 4, 2018 at 11:51 PM Khushboo Vashi <khushboo.vashi@enterprisedb.com> wrote:
On Fri, Mar 2, 2018 at 6:55 PM, Dave Page <dpage@pgadmin.org> wrote:
Could you rebase this please? It no longer applies.

Please find the attached updated patch. 
Thanks.

On Thu, Mar 1, 2018 at 5:56 AM, Khushboo Vashi <khushboo.vashi@enterprisedb.com> wrote:
Hi Joao,

Thanks for reviewing.

On Wed, Feb 28, 2018 at 8:55 PM, Joao De Almeida Pereira <jdealmeidapereira@pivotal.io> wrote:
Hello Khushboo,
After reviewing the patch I have the gut feeling that we do not have enough test coverage on this issue, specially due to the intricate while loop and conditions around the polling.
I think that this deserve Unit tests around it, When I say Unit Test I am not talking about executing queries against the database, but do some stubbing of the database so that we can control the flow that we want.
You are right. It needs more unit testing. I have checked below scenarios:
1. Returns 2 notices with data output
2. Returns 1000 notices with data output
3. No notices with data output 

By running above, I have checked, each time returned notices are accurate, no old notices are getting appended, it does not affect with the amount of messages (few, none or more).  Also, with the updated patch, I have made sure that all these queries run with the single transaction id (same connection).

So, please let me know if you think I can add more things to this.
  
It is a temptation to try to always do a Feature Test to test what we want because it is "easier" to write and ultimately it is what users see, but while 1 Feature Test runs we can run 200 Unit Tests that give us much more confidence that the code is doing what we expect it to do.

Right, so added regression tests instead of feature tests. 

This being said, I run the tests on the CI Pipeline and all tests pass. Running pycodestyle fails due to some line sizes on the psycopg2/__init__py. I believe that it is not what you changed, but since you were changing the file it can be fixed it is just:

pgadmin/utils/driver/psycopg2/__init__.py:1276: [E501] line too long (81 > 79 characters)
pgadmin/utils/driver/psycopg2/__init__.py:1277: [E501] line too long (91 > 79 characters)
pgadmin/utils/driver/psycopg2/__init__.py:1282: [E501] line too long (81 > 79 characters)
pgadmin/utils/driver/psycopg2/__init__.py:1283: [E501] line too long (91 > 79 characters)
4       E501 line too long (81 > 79 characters)

Fixed. Thanks for pointing out. 

Thanks
Joao


On Wed, Feb 28, 2018 at 6:49 AM Khushboo Vashi <khushboo.vashi@enterprisedb.com> wrote:
On Mon, Feb 26, 2018 at 10:02 PM, Dave Page <dpage@pgadmin.org> wrote:
Argh, I ran some tests, but didn't spot any lost messages in the tests I ran. I'll revert the patch.

Khushboo;

Please look at the following:

- Fix the patch so it doesn't drop messages.
Fixed.
By default, the notice attribute of the connection object of psycopg 2 only stores 50 notices. Once it reaches to 50 it starts from 1 again.
To fix this I have changed the notice attribute from list to deque to append more messages. Currently I have kept the maximum limit at a time of the notice attribute is 100000 (in a single poll). 
- Add regression tests to make sure it doesn't break in the future. This may require creating one or more functions the spew out a whole lot of notices, and then running a couple of queries and checking the output.
Added. With this regression test, the current code is failing which has been taken care in this patch.
- Check the messages panel on the history tab. I just noticed it seems to only be showing an even smaller subset of the messages.
Tested and no issues found.
 
Thanks.

On Mon, Feb 26, 2018 at 4:23 PM, Murtuza Zabuawala <murtuza.zabuawala@enterprisedb.com> wrote:
Sent bit early, 

You can run 'VACUUM FULL VERBOSE' in query tool and verify the populated messages (pgAdmin3 vs. pgAdmin4). 


On Mon, Feb 26, 2018 at 9:48 PM, Murtuza Zabuawala <murtuza.zabuawala@enterprisedb.com> wrote:
Hi Khushboo/Dave,

With given commit, I'm again seeing the issue raised in https://redmine.postgresql.org/issues/1523 :(




--
Regards,
Murtuza Zabuawala
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


On Mon, Feb 26, 2018 at 7:49 PM, Dave Page <dpage@pgadmin.org> wrote:
Ensure we pick up the messages from the current query and not a previous one. Fixes #3094

Branch
------
master

Details
-------
https://git.postgresql.org/gitweb?p=pgadmin4.git;a=commitdiff;h=08b3ccc01a4d57e8ea3657f8882a53dcd1b99386
Author: Khushboo Vashi <khushboo.vashi@enterprisedb.com>

Modified Files
--------------
web/pgadmin/utils/driver/abstract.py          |  1 +
web/pgadmin/utils/driver/psycopg2/__init__.py | 64 +++++++++------------------
2 files changed, 21 insertions(+), 44 deletions(-)






--
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company




--
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

Re: pgAdmin 4 commit: Ensure we pick up the messages from the current query

From
Khushboo Vashi
Date:


On Mon, Mar 5, 2018 at 8:42 PM, Joao De Almeida Pereira <jdealmeidapereira@pivotal.io> wrote:
Hello Khushboo,
Looks like we are almost doen, just missing one PEP-8 issue:
→ pycodestyle --config=.pycodestyle pgadmin/tools
pgadmin/tools/sqleditor/tests/test_poll_query_tool.py:46: [E126] continuation line over-indented for hanging indent
1       E126 continuation line over-indented for hanging indent
1


Thanks Joao. 
Please find the attached updated patch. 
The tests run successfully in our CI pipeline.

Thanks
Joao

Thanks,
Khushboo 
On Sun, Mar 4, 2018 at 11:51 PM Khushboo Vashi <khushboo.vashi@enterprisedb.com> wrote:
On Fri, Mar 2, 2018 at 6:55 PM, Dave Page <dpage@pgadmin.org> wrote:
Could you rebase this please? It no longer applies.

Please find the attached updated patch. 
Thanks.

On Thu, Mar 1, 2018 at 5:56 AM, Khushboo Vashi <khushboo.vashi@enterprisedb.com> wrote:
Hi Joao,

Thanks for reviewing.

On Wed, Feb 28, 2018 at 8:55 PM, Joao De Almeida Pereira <jdealmeidapereira@pivotal.io> wrote:
Hello Khushboo,
After reviewing the patch I have the gut feeling that we do not have enough test coverage on this issue, specially due to the intricate while loop and conditions around the polling.
I think that this deserve Unit tests around it, When I say Unit Test I am not talking about executing queries against the database, but do some stubbing of the database so that we can control the flow that we want.
You are right. It needs more unit testing. I have checked below scenarios:
1. Returns 2 notices with data output
2. Returns 1000 notices with data output
3. No notices with data output 

By running above, I have checked, each time returned notices are accurate, no old notices are getting appended, it does not affect with the amount of messages (few, none or more).  Also, with the updated patch, I have made sure that all these queries run with the single transaction id (same connection).

So, please let me know if you think I can add more things to this.
  
It is a temptation to try to always do a Feature Test to test what we want because it is "easier" to write and ultimately it is what users see, but while 1 Feature Test runs we can run 200 Unit Tests that give us much more confidence that the code is doing what we expect it to do.

Right, so added regression tests instead of feature tests. 

This being said, I run the tests on the CI Pipeline and all tests pass. Running pycodestyle fails due to some line sizes on the psycopg2/__init__py. I believe that it is not what you changed, but since you were changing the file it can be fixed it is just:

pgadmin/utils/driver/psycopg2/__init__.py:1276: [E501] line too long (81 > 79 characters)
pgadmin/utils/driver/psycopg2/__init__.py:1277: [E501] line too long (91 > 79 characters)
pgadmin/utils/driver/psycopg2/__init__.py:1282: [E501] line too long (81 > 79 characters)
pgadmin/utils/driver/psycopg2/__init__.py:1283: [E501] line too long (91 > 79 characters)
4       E501 line too long (81 > 79 characters)

Fixed. Thanks for pointing out. 

Thanks
Joao


On Wed, Feb 28, 2018 at 6:49 AM Khushboo Vashi <khushboo.vashi@enterprisedb.com> wrote:
On Mon, Feb 26, 2018 at 10:02 PM, Dave Page <dpage@pgadmin.org> wrote:
Argh, I ran some tests, but didn't spot any lost messages in the tests I ran. I'll revert the patch.

Khushboo;

Please look at the following:

- Fix the patch so it doesn't drop messages.
Fixed.
By default, the notice attribute of the connection object of psycopg 2 only stores 50 notices. Once it reaches to 50 it starts from 1 again.
To fix this I have changed the notice attribute from list to deque to append more messages. Currently I have kept the maximum limit at a time of the notice attribute is 100000 (in a single poll). 
- Add regression tests to make sure it doesn't break in the future. This may require creating one or more functions the spew out a whole lot of notices, and then running a couple of queries and checking the output.
Added. With this regression test, the current code is failing which has been taken care in this patch.
- Check the messages panel on the history tab. I just noticed it seems to only be showing an even smaller subset of the messages.
Tested and no issues found.
 
Thanks.

On Mon, Feb 26, 2018 at 4:23 PM, Murtuza Zabuawala <murtuza.zabuawala@enterprisedb.com> wrote:
Sent bit early, 

You can run 'VACUUM FULL VERBOSE' in query tool and verify the populated messages (pgAdmin3 vs. pgAdmin4). 


On Mon, Feb 26, 2018 at 9:48 PM, Murtuza Zabuawala <murtuza.zabuawala@enterprisedb.com> wrote:
Hi Khushboo/Dave,

With given commit, I'm again seeing the issue raised in https://redmine.postgresql.org/issues/1523 :(




--
Regards,
Murtuza Zabuawala
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


On Mon, Feb 26, 2018 at 7:49 PM, Dave Page <dpage@pgadmin.org> wrote:
Ensure we pick up the messages from the current query and not a previous one. Fixes #3094

Branch
------
master

Details
-------
https://git.postgresql.org/gitweb?p=pgadmin4.git;a=commitdiff;h=08b3ccc01a4d57e8ea3657f8882a53dcd1b99386
Author: Khushboo Vashi <khushboo.vashi@enterprisedb.com>

Modified Files
--------------
web/pgadmin/utils/driver/abstract.py          |  1 +
web/pgadmin/utils/driver/psycopg2/__init__.py | 64 +++++++++------------------
2 files changed, 21 insertions(+), 44 deletions(-)






--
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company




--
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

Attachment

Re: pgAdmin 4 commit: Ensure we pick up the messages from the current query

From
Joao De Almeida Pereira
Date:
Hello Khushboo,
Thanks for the changes here. Now everything looks good, and the tests all pass.

Thanks
Joao

On Tue, Mar 6, 2018 at 5:09 AM Khushboo Vashi <khushboo.vashi@enterprisedb.com> wrote:
On Mon, Mar 5, 2018 at 8:42 PM, Joao De Almeida Pereira <jdealmeidapereira@pivotal.io> wrote:
Hello Khushboo,
Looks like we are almost doen, just missing one PEP-8 issue:
→ pycodestyle --config=.pycodestyle pgadmin/tools
pgadmin/tools/sqleditor/tests/test_poll_query_tool.py:46: [E126] continuation line over-indented for hanging indent
1       E126 continuation line over-indented for hanging indent
1


Thanks Joao. 
Please find the attached updated patch. 
The tests run successfully in our CI pipeline.

Thanks
Joao

Thanks,
Khushboo 
On Sun, Mar 4, 2018 at 11:51 PM Khushboo Vashi <khushboo.vashi@enterprisedb.com> wrote:
On Fri, Mar 2, 2018 at 6:55 PM, Dave Page <dpage@pgadmin.org> wrote:
Could you rebase this please? It no longer applies.

Please find the attached updated patch. 
Thanks.

On Thu, Mar 1, 2018 at 5:56 AM, Khushboo Vashi <khushboo.vashi@enterprisedb.com> wrote:
Hi Joao,

Thanks for reviewing.

On Wed, Feb 28, 2018 at 8:55 PM, Joao De Almeida Pereira <jdealmeidapereira@pivotal.io> wrote:
Hello Khushboo,
After reviewing the patch I have the gut feeling that we do not have enough test coverage on this issue, specially due to the intricate while loop and conditions around the polling.
I think that this deserve Unit tests around it, When I say Unit Test I am not talking about executing queries against the database, but do some stubbing of the database so that we can control the flow that we want.
You are right. It needs more unit testing. I have checked below scenarios:
1. Returns 2 notices with data output
2. Returns 1000 notices with data output
3. No notices with data output 

By running above, I have checked, each time returned notices are accurate, no old notices are getting appended, it does not affect with the amount of messages (few, none or more).  Also, with the updated patch, I have made sure that all these queries run with the single transaction id (same connection).

So, please let me know if you think I can add more things to this.
  
It is a temptation to try to always do a Feature Test to test what we want because it is "easier" to write and ultimately it is what users see, but while 1 Feature Test runs we can run 200 Unit Tests that give us much more confidence that the code is doing what we expect it to do.

Right, so added regression tests instead of feature tests. 

This being said, I run the tests on the CI Pipeline and all tests pass. Running pycodestyle fails due to some line sizes on the psycopg2/__init__py. I believe that it is not what you changed, but since you were changing the file it can be fixed it is just:

pgadmin/utils/driver/psycopg2/__init__.py:1276: [E501] line too long (81 > 79 characters)
pgadmin/utils/driver/psycopg2/__init__.py:1277: [E501] line too long (91 > 79 characters)
pgadmin/utils/driver/psycopg2/__init__.py:1282: [E501] line too long (81 > 79 characters)
pgadmin/utils/driver/psycopg2/__init__.py:1283: [E501] line too long (91 > 79 characters)
4       E501 line too long (81 > 79 characters)

Fixed. Thanks for pointing out. 

Thanks
Joao


On Wed, Feb 28, 2018 at 6:49 AM Khushboo Vashi <khushboo.vashi@enterprisedb.com> wrote:
On Mon, Feb 26, 2018 at 10:02 PM, Dave Page <dpage@pgadmin.org> wrote:
Argh, I ran some tests, but didn't spot any lost messages in the tests I ran. I'll revert the patch.

Khushboo;

Please look at the following:

- Fix the patch so it doesn't drop messages.
Fixed.
By default, the notice attribute of the connection object of psycopg 2 only stores 50 notices. Once it reaches to 50 it starts from 1 again.
To fix this I have changed the notice attribute from list to deque to append more messages. Currently I have kept the maximum limit at a time of the notice attribute is 100000 (in a single poll). 
- Add regression tests to make sure it doesn't break in the future. This may require creating one or more functions the spew out a whole lot of notices, and then running a couple of queries and checking the output.
Added. With this regression test, the current code is failing which has been taken care in this patch.
- Check the messages panel on the history tab. I just noticed it seems to only be showing an even smaller subset of the messages.
Tested and no issues found.
 
Thanks.

On Mon, Feb 26, 2018 at 4:23 PM, Murtuza Zabuawala <murtuza.zabuawala@enterprisedb.com> wrote:
Sent bit early, 

You can run 'VACUUM FULL VERBOSE' in query tool and verify the populated messages (pgAdmin3 vs. pgAdmin4). 


On Mon, Feb 26, 2018 at 9:48 PM, Murtuza Zabuawala <murtuza.zabuawala@enterprisedb.com> wrote:
Hi Khushboo/Dave,

With given commit, I'm again seeing the issue raised in https://redmine.postgresql.org/issues/1523 :(




--
Regards,
Murtuza Zabuawala
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


On Mon, Feb 26, 2018 at 7:49 PM, Dave Page <dpage@pgadmin.org> wrote:
Ensure we pick up the messages from the current query and not a previous one. Fixes #3094

Branch
------
master

Details
-------
https://git.postgresql.org/gitweb?p=pgadmin4.git;a=commitdiff;h=08b3ccc01a4d57e8ea3657f8882a53dcd1b99386
Author: Khushboo Vashi <khushboo.vashi@enterprisedb.com>

Modified Files
--------------
web/pgadmin/utils/driver/abstract.py          |  1 +
web/pgadmin/utils/driver/psycopg2/__init__.py | 64 +++++++++------------------
2 files changed, 21 insertions(+), 44 deletions(-)






--
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company




--
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
Thanks - patch applied.

On Tue, Mar 6, 2018 at 2:57 PM, Joao De Almeida Pereira <jdealmeidapereira@pivotal.io> wrote:
Hello Khushboo,
Thanks for the changes here. Now everything looks good, and the tests all pass.

Thanks
Joao

On Tue, Mar 6, 2018 at 5:09 AM Khushboo Vashi <khushboo.vashi@enterprisedb.com> wrote:
On Mon, Mar 5, 2018 at 8:42 PM, Joao De Almeida Pereira <jdealmeidapereira@pivotal.io> wrote:
Hello Khushboo,
Looks like we are almost doen, just missing one PEP-8 issue:
→ pycodestyle --config=.pycodestyle pgadmin/tools
pgadmin/tools/sqleditor/tests/test_poll_query_tool.py:46: [E126] continuation line over-indented for hanging indent
1       E126 continuation line over-indented for hanging indent
1


Thanks Joao. 
Please find the attached updated patch. 
The tests run successfully in our CI pipeline.

Thanks
Joao

Thanks,
Khushboo 
On Sun, Mar 4, 2018 at 11:51 PM Khushboo Vashi <khushboo.vashi@enterprisedb.com> wrote:
On Fri, Mar 2, 2018 at 6:55 PM, Dave Page <dpage@pgadmin.org> wrote:
Could you rebase this please? It no longer applies.

Please find the attached updated patch. 
Thanks.

On Thu, Mar 1, 2018 at 5:56 AM, Khushboo Vashi <khushboo.vashi@enterprisedb.com> wrote:
Hi Joao,

Thanks for reviewing.

On Wed, Feb 28, 2018 at 8:55 PM, Joao De Almeida Pereira <jdealmeidapereira@pivotal.io> wrote:
Hello Khushboo,
After reviewing the patch I have the gut feeling that we do not have enough test coverage on this issue, specially due to the intricate while loop and conditions around the polling.
I think that this deserve Unit tests around it, When I say Unit Test I am not talking about executing queries against the database, but do some stubbing of the database so that we can control the flow that we want.
You are right. It needs more unit testing. I have checked below scenarios:
1. Returns 2 notices with data output
2. Returns 1000 notices with data output
3. No notices with data output 

By running above, I have checked, each time returned notices are accurate, no old notices are getting appended, it does not affect with the amount of messages (few, none or more).  Also, with the updated patch, I have made sure that all these queries run with the single transaction id (same connection).

So, please let me know if you think I can add more things to this.
  
It is a temptation to try to always do a Feature Test to test what we want because it is "easier" to write and ultimately it is what users see, but while 1 Feature Test runs we can run 200 Unit Tests that give us much more confidence that the code is doing what we expect it to do.

Right, so added regression tests instead of feature tests. 

This being said, I run the tests on the CI Pipeline and all tests pass. Running pycodestyle fails due to some line sizes on the psycopg2/__init__py. I believe that it is not what you changed, but since you were changing the file it can be fixed it is just:

pgadmin/utils/driver/psycopg2/__init__.py:1276: [E501] line too long (81 > 79 characters)
pgadmin/utils/driver/psycopg2/__init__.py:1277: [E501] line too long (91 > 79 characters)
pgadmin/utils/driver/psycopg2/__init__.py:1282: [E501] line too long (81 > 79 characters)
pgadmin/utils/driver/psycopg2/__init__.py:1283: [E501] line too long (91 > 79 characters)
4       E501 line too long (81 > 79 characters)

Fixed. Thanks for pointing out. 

Thanks
Joao


On Wed, Feb 28, 2018 at 6:49 AM Khushboo Vashi <khushboo.vashi@enterprisedb.com> wrote:
On Mon, Feb 26, 2018 at 10:02 PM, Dave Page <dpage@pgadmin.org> wrote:
Argh, I ran some tests, but didn't spot any lost messages in the tests I ran. I'll revert the patch.

Khushboo;

Please look at the following:

- Fix the patch so it doesn't drop messages.
Fixed.
By default, the notice attribute of the connection object of psycopg 2 only stores 50 notices. Once it reaches to 50 it starts from 1 again.
To fix this I have changed the notice attribute from list to deque to append more messages. Currently I have kept the maximum limit at a time of the notice attribute is 100000 (in a single poll). 
- Add regression tests to make sure it doesn't break in the future. This may require creating one or more functions the spew out a whole lot of notices, and then running a couple of queries and checking the output.
Added. With this regression test, the current code is failing which has been taken care in this patch.
- Check the messages panel on the history tab. I just noticed it seems to only be showing an even smaller subset of the messages.
Tested and no issues found.
 
Thanks.

On Mon, Feb 26, 2018 at 4:23 PM, Murtuza Zabuawala <murtuza.zabuawala@enterprisedb.com> wrote:
Sent bit early, 

You can run 'VACUUM FULL VERBOSE' in query tool and verify the populated messages (pgAdmin3 vs. pgAdmin4). 


On Mon, Feb 26, 2018 at 9:48 PM, Murtuza Zabuawala <murtuza.zabuawala@enterprisedb.com> wrote:
Hi Khushboo/Dave,

With given commit, I'm again seeing the issue raised in https://redmine.postgresql.org/issues/1523 :(




--
Regards,
Murtuza Zabuawala
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


On Mon, Feb 26, 2018 at 7:49 PM, Dave Page <dpage@pgadmin.org> wrote:
Ensure we pick up the messages from the current query and not a previous one. Fixes #3094

Branch
------
master

Details
-------
https://git.postgresql.org/gitweb?p=pgadmin4.git;a=commitdiff;h=08b3ccc01a4d57e8ea3657f8882a53dcd1b99386
Author: Khushboo Vashi <khushboo.vashi@enterprisedb.com>

Modified Files
--------------
web/pgadmin/utils/driver/abstract.py          |  1 +
web/pgadmin/utils/driver/psycopg2/__init__.py | 64 +++++++++------------------
2 files changed, 21 insertions(+), 44 deletions(-)






--
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company




--
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company



--
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company