Skip to content

Commit 20fe722

Browse files
authored
Merge pull request #10 from mattpolzin/bugfix/7/hang-with-concurrent-tests
Bugfix/7/hang with concurrent tests
2 parents a21d6ee + 434022c commit 20fe722

21 files changed

+825
-185
lines changed

Dockerfile

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,15 @@ ENV ENVIRONMENT=$env
8585
# Postgres Database URL. Required.
8686
# ENV API_TEST_DATABASE_URL
8787

88+
# Redis URL. Required.
89+
# ENV API_TEST_REDIS_URL
90+
91+
# Jobs Queue runs in process. Optional. If false (or undefined),
92+
# a jobs process must be run separately.
93+
# ENV API_TEST_IN_PROCESS_QUEUES
94+
8895
##
89-
## Serve (default command)
96+
## serve (default command)
9097
##
9198

9299
# --env
@@ -97,3 +104,11 @@ ENV ENVIRONMENT=$env
97104

98105
ENTRYPOINT ["./Run"]
99106
CMD ["serve", "--env", "$ENVIRONMENT", "--hostname", "0.0.0.0", "--port", "80"]
107+
108+
##
109+
## queues
110+
##
111+
112+
# Use this command to run the queues service outside of the API server process.
113+
# This is the recommended way to run the Jobs Queue.
114+
# CMD ["queues"]

Package.resolved

Lines changed: 36 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ let package = Package(
1818
.package(url: "https://github.com/vapor/fluent-postgres-driver", from: "2.0.0-rc.2"),
1919
.package(url: "https://github.com/vapor/fluent", from: "4.0.0-rc.2.2"),
2020
.package(url: "https://github.com/vapor/fluent-kit", from: "1.0.0-rc.1.26"),
21+
.package(url: "https://github.com/vapor/queues-redis-driver", .branch("master")),
2122

2223
.package(url: "https://github.com/mattpolzin/VaporTypedRoutes", .upToNextMinor(from: "0.7.0")),
2324
.package(url: "https://github.com/mattpolzin/VaporOpenAPI", .upToNextMinor(from: "0.0.13")),
@@ -39,6 +40,7 @@ let package = Package(
3940
.product(name: "Vapor", package: "vapor"),
4041
.product(name: "Fluent", package: "fluent"),
4142
.product(name: "FluentPostgresDriver", package: "fluent-postgres-driver"),
43+
.product(name: "QueuesRedisDriver", package: "queues-redis-driver"),
4244
.product(name: "VaporTypedRoutes", package: "VaporTypedRoutes"),
4345
.product(name: "VaporOpenAPI", package: "VaporOpenAPI"),
4446

README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# JSON:API/OpenAPI Test Server
22
## Requirements
33
### Server
4-
The test server requires a Postgres database.
4+
The test server requires a Postgres database and Redis instace.
55

66
## Usage
77

@@ -73,16 +73,24 @@ docker run --rm --env 'API_TEST_IN_URL=https://website.com/api/documentation' -v
7373
You will find the dumped files at `./out/api_test_files.zip`.
7474

7575
### The Test Server
76-
You can run an API Test server that accepts requests to run tests at HTTP endpoints. This requires the same input file or URL environment variables explained in the above section but you also must provide a Postgres database for the server to use as its persistence layer. You specify this database using a Postgres URL in the `API_TEST_DATABASE_URL` environment variable.
76+
You can run an API Test server that accepts requests to run tests at HTTP endpoints. This requires the same input file or URL environment variables explained in the above section but you also must provide a Postgres database for the server to use as its persistence layer. You specify this database using a Postgres URL in the `API_TEST_DATABASE_URL` environment variable. A Redis instance is required to queue up the test runs. You specify the Redis URL in the `API_TEST_REDIS_URL` environment variable.
7777

7878
First you need to run the migrator against your Postgres database.
7979
```shell
80-
docker run --env 'API_TEST_IN_URL=https://website.com/api/documentation' --env 'API_TEST_DATABASE_URL=postgres://user:password@host:port/databasename' -p '8080:80' mattpolzin2/api-test-server migrate --yes
80+
docker run --env 'API_TEST_IN_URL=https://website.com/api/documentation' --env 'API_TEST_DATABASE_URL=postgres://user:password@host:port/databasename' --env 'API_TEST_REDIS_URL=redis://host:port' -p '8080:80' mattpolzin2/api-test-server migrate --yes
8181
```
8282

8383
Then you can start the server.
8484
```shell
85-
docker run --env 'API_TEST_IN_URL=https://website.com/api/documentation' --env 'API_TEST_DATABASE_URL=postgres://user:password@host:port/databasename' -p '8080:80' mattpolzin2/api-test-server
85+
docker run --env 'API_TEST_IN_URL=https://website.com/api/documentation' --env 'API_TEST_DATABASE_URL=postgres://user:password@host:port/databasename' --env 'API_TEST_REDIS_URL=redis://host:port' -p '8080:80' mattpolzin2/api-test-server
86+
```
87+
88+
#### Jobs Queue
89+
Testing is run in a jobs queue. That queue can be run in the same process as the API server if you specify `API_TEST_IN_PROCESS_QUEUES=true` as an environment variable but the recommendation is to run the jobs service as its own process.
90+
91+
You start the Jobs Queue using the same docker image as the serve but you specify the `queues` command.
92+
```shell
93+
docker run --env 'API_TEST_IN_URL=https://website.com/api/documentation' --env 'API_TEST_DATABASE_URL=postgres://user:password@host:port/databasename' --env 'API_TEST_REDIS_URL=redis://host:port' mattpolzin2/api-test-server queues
8694
```
8795

8896
**NOTE** We must explicitly expose the port to the host device. In this example, `http://localhost:8080` will point to the server which is listening on port `80` in the container.

0 commit comments

Comments
 (0)