Skip to content

Commit a4a97a0

Browse files
authored
📚 Add "why" + "usage" to readme (reservix#2)
1 parent 6f5013e commit a4a97a0

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

LICENCE LICENSE

File renamed without changes.

README.md

+38
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,32 @@
11
# docker-await-postgres
22

3+
[![buid][ci-badge]][ci] [![buid][coverage-badge]][coverage] [![version][version-badge]][package] [![MIT License][license-badge]][license]
4+
5+
> Start `postgres` docker container and wait until it is truly ready.
6+
7+
This module is heavily inspired by [`ava-fixture-docker-db`](https://github.com/cdaringe/ava-fixture-docker-db).
8+
But unlike the mentioned module, it is
9+
10+
- test runner agnostic
11+
- will wait until _postges_ is "truly" ready to accepts connections.
12+
13+
Especially, the later will help when writing integration tests.
14+
15+
## Why
16+
17+
The official [_postgres_](https://hub.docker.com/_/postgres) container loads and executes SQL scripts to create an initial
18+
table layout when the container is started, followed by a reboot of the _postgres_ server. This is a welcome feature and
19+
a best practice when using docker to host your database. Sadly, it makes it harder to use the image when writing integration
20+
tests for your database.
21+
22+
Usually, tests run fast and don't wait the µ-seconds until the _postgres_ server has rebooted. This causes tests to randomly break and
23+
connection errors, because the _postgres_ server will just kill all connections when it is rebooting.
24+
25+
Using the Docker API (via `dockerode` or similar) will only tell you if the container is ready, but not if services inside the container are ready
26+
(you can read more about this here: [docker-library/postgres/#146](https://github.com/docker-library/postgres/issues/146)).
27+
28+
`docker-await-postgres` will read the server logs and long poll until the _postgres_ server is trulry ready. So that tests only run when
29+
the server is trurly ready to accept connections.
330
Start `postgres` docker container and wait until it is truly ready.
431

532
This module is based on on [`ava-fixture-docker-db`](https://github.com/cdaringe/ava-fixture-docker-db).
@@ -40,3 +67,14 @@ await client.end();
4067
// Stop the container
4168
await stop();
4269
```
70+
71+
<!-- LINKS -->
72+
73+
[ci]: https://travis-ci.org/Reservix/docker-await-postgres
74+
[ci-badge]: https://img.shields.io/travis/Reservix/docker-await-postgres.svg?style=flat-square
75+
[coverage]: https://codecov.io/gh/Reservix/docker-await-postgres
76+
[coverage-badge]: https://img.shields.io/codecov/c/github/Reservix/docker-await-postgres.svg?style=flat-square
77+
[license]: https://github.com/Reservix/docker-await-postgres/blob/master/LICENSE
78+
[license-badge]: https://img.shields.io/npm/l/docker-await-postgres.svg?style=flat-square
79+
[package]: https://www.npmjs.com/package/docker-await-postgres
80+
[version-badge]: https://img.shields.io/npm/v/docker-await-postgres.svg?style=flat-square

0 commit comments

Comments
 (0)