class TestWhenThereAreMoreThreadsThanMaxThreads(TestSampler): @before def before(self): super().before() self.environment["max_threads"] = 1 self.subject = Sampler(environment=self.environment) def test_it_calls_the_get_stacks_method_with_a_subset_of_the_threads(self): self.subject.sample() allowed_results = [ mock.call( threads_to_sample=[("fake_thread_1", "fake_thread_frames_1")], excluded_threads=ANY, max_depth=ANY, ), mock.call( threads_to_sample=[("fake_thread_2", "fake_thread_frames_2")], excluded_threads=ANY, max_depth=ANY, ), ] assert (self.mock_get_stacks.call_args in allowed_results) def test_it_includes_the_number_of_threads_it_attempted_to_sample_and_how_many_in_total_were_seen_in_the_system( self): self.mock_get_stacks.result = [["dummy_stack_sample"]] result = self.subject.sample() assert (result.attempted_sample_threads_count == 1) assert (result.seen_threads_count == 2)
def test_it_calls_the_get_stacks_method_with_the_custom_excluded_threads_list( self): self.environment["excluded_threads"] = {"exclude_me"} sampler = Sampler(environment=self.environment) sampler.sample() self.mock_get_stacks.assert_called_once_with( threads_to_sample=ANY, excluded_threads={"exclude_me"}, max_depth=ANY)
def test_it_calls_the_get_stacks_method_with_the_current_threads_and_the_default_excluded_threads_and_default_max_depth( self): default_excluded_threads = set() default_max_depth = 1000 sampler = Sampler(environment=self.environment) sampler.sample() self.mock_get_stacks.assert_called_once_with( threads_to_sample=self._current_frames_reply.items(), excluded_threads=default_excluded_threads, max_depth=default_max_depth, )
def test_it_includes_the_number_of_threads_it_attempted_to_sample_and_how_many_in_total_were_seen_in_the_system( self): self.mock_get_stacks.result = [["dummy_stack_sample"]] sampler = Sampler(environment=self.environment) result = sampler.sample() assert (result.attempted_sample_threads_count == 2) assert (result.seen_threads_count == 2)
def test_it_calls_the_get_stacks_method_with_the_custom_max_stack_depth( self): AgentConfiguration.set(AgentConfiguration._get_new_config(configure_agent_response={ "agentParameters": { "SamplingIntervalInMilliseconds": "2700", "MinimumTimeForReportingInMilliseconds": "60000", "MaxStackDepth": "10" }, "periodInSeconds": 123 })) sampler = Sampler(environment=self.environment) sampler.sample() self.mock_get_stacks.assert_called_once_with( threads_to_sample=ANY, excluded_threads=ANY, max_depth=10, )