Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

521 test robustness pgbouncer #522

Merged
merged 7 commits into from
Jul 30, 2018
Merged

Conversation

rafatower
Copy link
Contributor

@rafatower rafatower commented Jul 19, 2018

This PR makes it possible to execute tests with and without pgbouncer.

This fixes the issue #521

Rafa de la Torre added 3 commits July 19, 2018 18:40
And using sh can make some things fail. E.g:

```
[[: not found
```
This sends a PAUSE and RESUME to pgbouncer (in case there's one) before
and after executing tests, to make sure new connections are established
in the tests.

This may be especially important when role or session settings are
modified in the DB (same happens in prod, BTW).
This is needed to make the setup a little bit more robust: when trying
to delete the test database, it won't be able if there are "idle
sessions" in the db (that is, connections from pgbouncer to the test
database).

Otherwise it fails when trying to create the database, because there's
already one with the same name.
@rafatower rafatower requested a review from dgaubert July 19, 2018 16:59
@rafatower
Copy link
Contributor Author

I understand that for this to be really more automated and useful, I'd need to tweak the travis build and docker image to make use of pgbouncer, another dependency, and that it might not be desirable.

No big deal and no strong opinion, it is simply that it helped me to run existing tests, taking into account subtle differences between direct vs pgbounced connections.

port: dbConfig.db_port
});

// We just chain a PAUSE followed by a RESUME
Copy link
Contributor

Choose a reason for hiding this comment

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

Ei, what is the objective of pause - resume?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

https://pgbouncer.github.io/usage.html#admin-console

PAUSE [db];
PgBouncer tries to disconnect from all servers, first waiting for all queries to complete. The command will not return before all queries are finished. To be used at the time of database restart.

RESUME [db];
Resume work from previous PAUSE or SUSPEND command.

Wait for all the running queries to finish and let the new ones reconnect. This way you pick the changed session parameters such as set statement_timeout. Sames happens in production, BTW, but there the connections are refreshed usually more often.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, thanks! :)

Copy link
Contributor

@dgaubert dgaubert left a comment

Choose a reason for hiding this comment

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

LGTM, just leave a couple of picky comments for the sake of clarity :)

Is this also happening in your environment for Windshaft-cartodb??


// We just chain a PAUSE followed by a RESUME
client.connect();
client.query('PAUSE', (err, res) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please, follow Node.js conventions:

client.query('PAUSE', (err, res) => {
  if (err) {
    return callback(err);
  }
  client.query('RESUME', (err, res) => ...);
}

If you inmediatly return after calling the callback, there is no need to wrap following sentences into a else statement.

port: dbConfig.db_port
});

// We just chain a PAUSE followed by a RESUME
Copy link
Contributor

Choose a reason for hiding this comment

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

What about // We just chain a PAUSE followed by a RESUME to reset internal pool connections of PgBouncer?

@rafatower
Copy link
Contributor Author

Is this also happening in your environment for Windshaft-cartodb?

Windshaft-cartodb is equally affected, but its tests don't need much of DB settings as those in SQL API:

[rtorre@fireflies Windshaft-cartodb (master)]$ git grep statement_timeout
test/support/sql/gadm4.sql:SET statement_timeout = 0;
test/support/sql/windshaft.test.sql:SET statement_timeout = 0;

Yet you can see some tests are indeed affected by this:

[rtorre@fireflies Windshaft-cartodb (master)]$ diff config/environments/test.js config/environments/test.js.example
106c106
<         port: 6432,
---
>         port: 5432,
116c116
<     ,mapnik_version: ''
---
>     ,mapnik_version: undefined
193c193
<               port: 6432,
---
>               port: 5432,

[rtorre@fireflies Windshaft-cartodb (master)]$ make check
...
  443 passing (31s)
  8 pending
  2 failing

  1) user database timeout limit dataview layergroup creation works but dataview request fails due to statement timeout:
     Uncaught Error: Invalid response status code.
     Expected: 429
     Got: 200
     Body: {"operation":"count","result":1,"nulls":0,"type":"formula"}
      at validateResponseStatus (test/support/assert.js:146:20)
      at validateResponse (test/support/assert.js:179:9)
      at Server.<anonymous> (test/support/assert.js:119:27)
      at emitCloseNT (net.js:1555:8)
      at _combinedTickCallback (internal/process/next_tick.js:71:11)
      at process._tickCallback (internal/process/next_tick.js:98:9)

  2)  "after each" hook for "layergroup creation works but dataview request fails due to statement timeout":

      AssertionError: uncaughtException:

Error: Invalid response status code.
     Expected: 429
     Got: 200
     Body: {"operation":"count","result":1,"nulls":0,"type":"formula"}
    at validateResponseStatus (test/support/assert.js:146:20)
    at validateResponse (test/support/assert.js:179:9)
    at Server.<anonymous> (test/support/assert.js:119:27)
    at emitCloseNT (net.js:1555:8)
    at _combinedTickCallback (internal/process/next_tick.js:71:11)
    at process._tickCallback (internal/process/next_tick.js:98:9)
      + expected - actual

      -1
      +0
      
      at Context.<anonymous> (test/support/test_helper.js:87:12)

(if I use the standard 5432 port, all of them pass).

Arguably, I'd be less concerned about Windshaft-cartodb than about the SQL API. In the end, the SQL API is all about interaction with the DB, and the direct connection vs pgbouncer is more than just an implementation detail.

Rafa de la Torre added 3 commits July 30, 2018 12:31
As suggested in review comment.
As suggested by jshint:
- Remove the unused `res` return value
- Add a semicolon at the end of the file
@rafatower
Copy link
Contributor Author

I covered your comments (that I always appreciate) and pleased jshint. Now time to merge. Thanks!

@rafatower rafatower merged commit bdb3b9f into master Jul 30, 2018
@rafatower rafatower deleted the 521-test-robustness-pgbouncer branch July 30, 2018 10:47
@simon-contreras-deel
Copy link
Contributor

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants