Skip to content

Commit

Permalink
Update tests and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
kmakiela committed Jul 1, 2020
1 parent a713302 commit 7101c40
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 37 deletions.
43 changes: 26 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -493,28 +493,37 @@ If you specify both **alert** and **data**, target device will receive both noti

### Healthcheck

MongoosePush exposes a `/healthcheck` endpoint, from which you can get information about the current status of all connections in a `JSON` format, grouped by connection pool. An example with 2 pools, one being connected to the service and the other one not, would look like this:
MongoosePush exposes a `/healthcheck` endpoint, from which you can get information about the current status of all connections in a `JSON` format, grouped by connection pool. Response structure is described in a following [RFC draft](https://tools.ietf.org/id/draft-inadarei-api-health-check-01.html). An example with 2 pools, one being connected to the service and the other one not, would look like this:

```json
[
{
"pool": "pool_name1",
"connection_status":
[
"connected",
"connected"
"description": "Health of MongoosePush connections to FCM and APNS services",
"details": {
"pool:pool1": [
{
"output": {
"connected": 5,
"disconnected": 0
},
"status": "pass",
"time": "2020-07-01T11:58:30.093318Z"
}
],
"pool:pool2": [
{
"output": {
"connected": 0,
"disconnected": 5
},
"status": "pass",
"time": "2020-07-01T11:58:30.102291Z"
}
]
},
{
"pool": "pool_name2",
"connection_status":
[
"disconnected",
"disconnected",
"disconnected"
]
},
"releaseID": "2.0.2",
"status": "pass",
"version": "2"
}
]
```
If all the connections are down the response status is `503` and in all the other cases it's `200`.

Expand Down
75 changes: 55 additions & 20 deletions test/unit/healthcheck_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,19 @@ defmodule MongoosePushWeb.HealthcheckTest do
end)

for {pool_name, worker_count} <- fcm_pools ++ apns_pools do
pool_info = %{
"pool" => Atom.to_string(pool_name),
"connection_status" => List.duplicate("connected", worker_count)
pool_connection_status = %{
"connected" => worker_count,
"disconnected" => 0
}

assert true == Enum.member?(pools, pool_info)
response =
pools
|> Map.fetch!("details")
|> Map.fetch!("pool:#{pool_name}")
|> List.first()
|> Map.fetch!("output")

assert response == pool_connection_status
end
end

Expand Down Expand Up @@ -73,21 +80,35 @@ defmodule MongoosePushWeb.HealthcheckTest do
end)

for {pool_name, worker_count} <- apns_pools do
pool_info = %{
"pool" => Atom.to_string(pool_name),
"connection_status" => List.duplicate("connected", worker_count)
pool_connection_status = %{
"connected" => worker_count,
"disconnected" => 0
}

assert true == Enum.member?(pools, pool_info)
response =
pools
|> Map.fetch!("details")
|> Map.fetch!("pool:#{pool_name}")
|> List.first()
|> Map.fetch!("output")

assert response == pool_connection_status
end

for {pool_name, worker_count} <- fcm_pools do
pool_info = %{
"pool" => Atom.to_string(pool_name),
"connection_status" => List.duplicate("disconnected", worker_count)
pool_connection_status = %{
"connected" => 0,
"disconnected" => worker_count
}

assert true == Enum.member?(pools, pool_info)
response =
pools
|> Map.fetch!("details")
|> Map.fetch!("pool:#{pool_name}")
|> List.first()
|> Map.fetch!("output")

assert response == pool_connection_status
end
end
end
Expand Down Expand Up @@ -138,21 +159,35 @@ defmodule MongoosePushWeb.HealthcheckTest do
end)

for {pool_name, worker_count} <- apns_pools do
pool_info = %{
"pool" => Atom.to_string(pool_name),
"connection_status" => List.duplicate("disconnected", worker_count)
pool_connection_status = %{
"connected" => 0,
"disconnected" => worker_count
}

assert true == Enum.member?(pools, pool_info)
response =
pools
|> Map.fetch!("details")
|> Map.fetch!("pool:#{pool_name}")
|> List.first()
|> Map.fetch!("output")

assert response == pool_connection_status
end

for {pool_name, worker_count} <- fcm_pools do
pool_info = %{
"pool" => Atom.to_string(pool_name),
"connection_status" => List.duplicate("disconnected", worker_count)
pool_connection_status = %{
"connected" => 0,
"disconnected" => worker_count
}

assert true == Enum.member?(pools, pool_info)
response =
pools
|> Map.fetch!("details")
|> Map.fetch!("pool:#{pool_name}")
|> List.first()
|> Map.fetch!("output")

assert response == pool_connection_status
end
end
end
Expand Down

0 comments on commit 7101c40

Please sign in to comment.