Test environment stability improvements #703

Merged
zachgoll merged 10 commits from zachgoll/test-stability-improvements into main 2024-05-03 01:18:19 +08:00
zachgoll commented 2024-05-03 00:29:07 +08:00 (Migrated from github.com)

Overview

This is the second part of a series of PRs aimed to stabilize our dependencies and test suite so we're not getting unpredictable failures that have been happening as of late.

There will be 1-2 more PRs to finish this off, but wanted to open this in small increments for documentation purposes.

App Mode

As part of this PR, I have moved the config for self hosting directly into the environment configs under the key app_mode, which can either be self_hosted or managed.

Rails.configuration.app_mode.self_hosted? # true | false

Good Job config

By default, GoodJob offers different execution modes based on the Rails environment (i.e. prod defaults to :external, dev to :async, test to :inline), so I've consolidated the config into application.rb.

Prior, we didn't have anything set in test, so it was defaulting to the Rails :async adapter (rather than the GoodJob :inline adapter as expected).

Test environment, overriding ENV in tests

Since the Maybe app will need to be tested under both "self hosted" mode and "managed" mode, I've introduced a first class helper to facilitate this:

test "something only relevant to self hosting mode" do
  with_self_hosting do 
    # Assertions
  end
end

Additionally, I've moved dotenv-rails out of the :test group to be more explicit with the test environment and added another helper (leveraging the climate_control gem) to explicitly override environment variables for individual tests:

test "something with ENV override(s)" do
  with_env_overrides SOME_ENV: "some value", ANOTHER_VAR: "another value" do
    # Assertions
  end
end
## Overview This is the second part of a series of PRs aimed to stabilize our dependencies and test suite so we're not getting unpredictable failures that have been happening as of late. There will be 1-2 more PRs to finish this off, but wanted to open this in small increments for documentation purposes. ## App Mode As part of this PR, I have moved the config for self hosting directly into the environment configs under the key `app_mode`, which can either be `self_hosted` or `managed`. ```rb Rails.configuration.app_mode.self_hosted? # true | false ``` ## Good Job config By default, GoodJob offers different execution modes based on the Rails environment (i.e. prod defaults to `:external`, dev to `:async`, test to `:inline`), so I've consolidated the config into `application.rb`. Prior, we didn't have anything set in test, so it was defaulting to the Rails `:async` adapter (rather than the GoodJob `:inline` adapter as expected). ## Test environment, overriding ENV in tests Since the Maybe app will need to be tested under both "self hosted" mode and "managed" mode, I've introduced a first class helper to facilitate this: ```rb test "something only relevant to self hosting mode" do with_self_hosting do # Assertions end end ``` Additionally, I've moved `dotenv-rails` out of the `:test` group to be more explicit with the test environment and added another helper (leveraging the `climate_control` gem) to explicitly override environment variables for individual tests: ```rb test "something with ENV override(s)" do with_env_overrides SOME_ENV: "some value", ANOTHER_VAR: "another value" do # Assertions end end ```
zachgoll (Migrated from github.com) reviewed 2024-05-03 00:30:33 +08:00
zachgoll (Migrated from github.com) commented 2024-05-03 00:30:33 +08:00

Unrelated cleanup here that I missed in #702

Unrelated cleanup here that I missed in #702
zachgoll (Migrated from github.com) reviewed 2024-05-03 00:36:10 +08:00
zachgoll (Migrated from github.com) commented 2024-05-03 00:36:09 +08:00

Will be simplified and re-introduced in follow-up PR.

Will be simplified and re-introduced in follow-up PR.
Sign in to join this conversation.