View Source SplitClient.Sandbox (SplitClient v0.3.0)

Handles the orchestration of keeping treatment data isolated between concurrently running tests.

It assumes that the SplitClient calls from your Application code are running in the same process as the test. If they are not, you will have to explicitally allow some other child process to access the treatments data or make the test async: false

Link to this section Summary

Functions

Associate a process that is making SplitClient calls with a specific test's isolated Treatment data

Returns a specification to start this module under a supervisor.

Populate the test environment with split information that your application code depends on.

Change how treatment data is looked up based on whether the test is async: false or async: true

Associate a test process with a new data source server that will be isolated from all other tests

Teardown logic when a test is done

Link to this section Functions

Link to this function

allow(name \\ __MODULE__, test_pid, pid)

View Source

Associate a process that is making SplitClient calls with a specific test's isolated Treatment data

examples

Examples

iex>SplitClient.Sandbox.allow(self(), Process.whereis(:foo))
:ok

Returns a specification to start this module under a supervisor.

See Supervisor.

@spec create_splits(splits :: [map()]) :: :ok

Populate the test environment with split information that your application code depends on.

Your splits should come as a list of maps. Each map should have one key for the split_name which has as its value a map with the treatment information.

create_splits/1 must be run after SplitClient.Testing.setup_split_client/1

[
  %{
    "my_feature" => %{
      treatment: "on",
      keys: "mock_user_id",
      traffic_type: "customer"
    }
  },
  %{
    "my_feature" => %{
      treatment: "off",
      traffic_type: "customer"
    }
  }
]
Link to this function

get_all_treatments(keys, opts \\ [])

View Source
@spec get_all_treatments(keys :: [map()], options :: keyword()) :: map()
Link to this function

get_treatment(key, split_name, opts \\ [])

View Source
@spec get_treatment(key :: String.t(), split_name :: String.t(), options :: keyword()) ::
  SplitClient.Treatment.t()
Link to this function

get_treatments(key, split_names, opts \\ [])

View Source
@spec get_treatments(
  key :: String.t(),
  split_names :: [String.t()],
  options :: keyword()
) :: map()
Link to this function

set_async_mode(name \\ __MODULE__, async?)

View Source

Change how treatment data is looked up based on whether the test is async: false or async: true

Link to this function

setup_test_treatments(name \\ __MODULE__, test_pid, data_source_pid)

View Source

Associate a test process with a new data source server that will be isolated from all other tests

Link to this function

teardown_test_treatments(name \\ __MODULE__, test_pid)

View Source

Teardown logic when a test is done