-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6100 from ministryofjustice/ap-3768/improve-maint…
…enance-page AP-3768: Improve maintenance page
- Loading branch information
Showing
12 changed files
with
130 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
## Maintenance mode | ||
|
||
A conditional catchall routes exists in `routes.rb`. This directs all routes requested to the `pages#servicedown` controller and view. To activate the conditional route you must provide the app server with MAINTENANCE_MODE=true. When supplied via the helm values.yml files it must be supplied as a string "true". | ||
|
||
```bash | ||
# activate maintenance mode locally | ||
MAINTENANCE_MODE=true rails s | ||
``` | ||
|
||
You can deploy the app in maintenance mode for the hosted environments by setting it to enabled: "true" in the relevant values.yml files | ||
|
||
```yml | ||
# example values-uat.yaml | ||
maintenance_mode: | ||
enabled: "true" | ||
``` | ||
To apply via circleCI: | ||
- commit the above change and push to github | ||
- run through circleCI and deploy to the relevant environment | ||
- to take site out of maintenance you would have to commit the reverse and redeploy via circleCI |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe PagesController, clamav: true do | ||
context "when not in maintenance mode" do | ||
context "when provider signs in" do | ||
before do | ||
sign_in provider | ||
get root_path | ||
end | ||
|
||
let(:provider) { create(:provider) } | ||
|
||
it "renders root page as expected" do | ||
expect(response).to render_template("providers/start/index") | ||
end | ||
end | ||
end | ||
|
||
context "when in maintenance mode" do | ||
before do | ||
allow(Rails.application.config.x).to receive(:maintenance_mode).and_return(true) | ||
Rails.application.reload_routes! | ||
end | ||
|
||
after do | ||
allow(Rails.application.config.x).to receive(:maintenance_mode).and_return(false) | ||
Rails.application.reload_routes! | ||
end | ||
|
||
shared_examples "maintenance page" do | ||
it { expect(response).to have_http_status(:ok) } | ||
it { expect(response).to render_template("pages/servicedown") } | ||
it { expect(response.body).to include("Sorry, the service is unavailable") } | ||
end | ||
|
||
shared_examples "maintenance json" do | ||
it { expect(response).to have_http_status :service_unavailable } | ||
it { expect(response.body).to include({ error: "Service temporarily unavailable" }.to_json) } | ||
end | ||
|
||
context "when provider signs in" do | ||
before do | ||
sign_in provider | ||
get root_path | ||
end | ||
|
||
let(:provider) { create(:provider) } | ||
|
||
it_behaves_like "maintenance page" | ||
end | ||
|
||
context "when different formats requested" do | ||
context "with html" do | ||
before { get "/", params: { format: :html } } | ||
|
||
it_behaves_like "maintenance page" | ||
end | ||
|
||
context "with json" do | ||
before { get "/", params: { format: :json } } | ||
|
||
it_behaves_like "maintenance json" | ||
end | ||
|
||
context "with ajax" do | ||
before { get "/", xhr: true, params: { format: :js } } | ||
|
||
it_behaves_like "maintenance json" | ||
end | ||
|
||
context "when other format" do | ||
before { get "/", params: { format: :axd } } | ||
|
||
it { expect(response).to have_http_status :service_unavailable } | ||
it { expect(response.body).to include("Service temporarily unavailable") } | ||
end | ||
end | ||
|
||
context "when /ping request made" do | ||
before { get "/ping" } | ||
|
||
it { expect(response).to be_ok } | ||
end | ||
|
||
context "when /healthcheck request made" do | ||
before do | ||
allow(Sidekiq::ProcessSet).to receive(:new).and_return(instance_double(Sidekiq::ProcessSet, size: 1)) | ||
allow(Sidekiq::RetrySet).to receive(:new).and_return(instance_double(Sidekiq::RetrySet, size: 0)) | ||
allow(Sidekiq::DeadSet).to receive(:new).and_return(instance_double(Sidekiq::DeadSet, size: 0)) | ||
connection = instance_double(HTTPClient::Connection) | ||
allow(connection).to receive(:info).and_return(redis_version: "7.0.0") | ||
allow(Sidekiq).to receive(:redis).and_yield(connection) | ||
get "/healthcheck" | ||
end | ||
|
||
it { expect(response).to be_ok } | ||
end | ||
end | ||
end |