This is needed to avoid a "test race" and get it closer to a real unit
test.
When running it along with others it passes:
```
$ make test-unit
...
48 passing (54ms)
12 pending
```
(note it relies on the ordering produced by `find`)
when running it along with some other test that reads the config, it
works as well:
```
$ test/run_tests.sh test/unit/apikeyauth.test.js test/unit/error_handler.test.js
...
3 passing (9ms)
12 pending
```
but when run in isolation, it fails:
```
$ test/run_tests.sh test/unit/error_handler.test.js
...
0 passing (15ms)
3 failing
1) error-handler should return a header with errors:
TypeError: Cannot read property 'environment' of undefined
at errorMiddleware (app/middlewares/error.js:10:28)
at Context.<anonymous> (test/unit/error_handler.test.js:53:26)
2) error-handler JSONP should return a header with error statuscode:
TypeError: Cannot read property 'environment' of undefined
at errorMiddleware (app/middlewares/error.js:10:28)
at Context.<anonymous> (test/unit/error_handler.test.js:79:26)
3) error-handler should escape chars that broke logs regex:
TypeError: Cannot read property 'environment' of undefined
at errorMiddleware (app/middlewares/error.js:10:28)
at Context.<anonymous> (test/unit/error_handler.test.js:108:26)
```
In order to give the DB quota middleware a chance of getting executed,
increase the 1 ms timeout to 10 ms. This is short but enough, as the
quota mocks are constant functions.
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.
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).
pgbouncer does not support the `--client-min-messages` option. Actually
it fails connections if used like that with this somewhat cryptic
message:
```
psql: ERROR: Unsupported startup parameter: options
```
In order to be able to execute tests against pgbouncer port (which is
desirable IMO), we either need to remove that option (with little to no
impact) or change the lines above to choose the batch API port from the
config.
Mind that this affects just test setup.