def test_empty_transport_disables_send(): client = TempStoreClient(service_name="x", transport_class=None, metrics_interval="0ms") assert len(client.config.errors) == 1 assert "TRANSPORT_CLASS" in client.config.errors assert client.config.disable_send client.close()
def test_config_by_environment(): with mock.patch.dict("os.environ", {"ELASTIC_APM_SERVICE_NAME": "envapp", "ELASTIC_APM_SECRET_TOKEN": "envtoken"}): client = TempStoreClient(metrics_interval="0ms") assert client.config.service_name == "envapp" assert client.config.secret_token == "envtoken" assert client.config.disable_send is False with mock.patch.dict("os.environ", {"ELASTIC_APM_DISABLE_SEND": "true"}): client = TempStoreClient(metrics_interval="0ms") assert client.config.disable_send is True client.close()
def test_client_doesnt_start_collector_thread_in_master_process(is_master_process, mock_start_collect_timer): # when in the master process, the client should not start worker threads is_master_process.return_value = True before = mock_start_collect_timer.call_count client = TempStoreClient(server_url="http://example.com", service_name="app_name", secret_token="secret") assert mock_start_collect_timer.call_count == before client.close() before = mock_start_collect_timer.call_count is_master_process.return_value = False client = TempStoreClient(server_url="http://example.com", service_name="app_name", secret_token="secret") assert mock_start_collect_timer.call_count == before + 1 client.close()
def test_config_non_string_types(): """ tests if we can handle non string types as configuration, e.g. Value types from django-configuration """ class MyValue(object): def __init__(self, content): self.content = content def __str__(self): return str(self.content) def __repr__(self): return repr(self.content) client = TempStoreClient( server_url="localhost", service_name=MyValue("bar"), secret_token=MyValue("bay"), metrics_interval="0ms" ) assert isinstance(client.config.secret_token, compat.string_types) assert isinstance(client.config.service_name, compat.string_types) client.close()