Skip to content

Commit 9930373

Browse files
authored
Combine sampler tests into single file. (#147)
* Combine sampler tests into single file. * Pin external_botocore dependency on rsa for py27. * Pin external_boto3 dependency on rsa for py27.
1 parent 9e40e78 commit 9930373

File tree

4 files changed

+56
-86
lines changed

4 files changed

+56
-86
lines changed

tests/agent_unittests/test_cpu_sampler.py

Lines changed: 0 additions & 41 deletions
This file was deleted.

tests/agent_unittests/test_memory_metrics.py

Lines changed: 0 additions & 37 deletions
This file was deleted.

tests/agent_unittests/test_gc_metrics.py renamed to tests/agent_unittests/test_sampler_metrics.py

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,46 @@
2121

2222
from newrelic.core.config import global_settings
2323
from newrelic.packages import six
24+
from newrelic.samplers.cpu_usage import cpu_usage_data_source
2425
from newrelic.samplers.gc_data import garbage_collector_data_source
26+
from newrelic.samplers.memory_usage import memory_usage_data_source
2527

2628
settings = global_settings()
2729

2830

2931
@pytest.fixture
30-
def data_source():
32+
def gc_data_source():
3133
sampler = garbage_collector_data_source(settings=())["factory"](environ=())
3234
sampler.start()
3335
yield sampler
3436
sampler.stop()
3537

3638

39+
@pytest.fixture
40+
def cpu_data_source():
41+
sampler = cpu_usage_data_source(settings=())["factory"](environ=())
42+
sampler.start()
43+
yield sampler
44+
sampler.stop()
45+
46+
47+
@pytest.fixture
48+
def memory_data_source():
49+
sampler = memory_usage_data_source(settings=())["factory"](environ=())
50+
yield sampler
51+
52+
3753
PID = os.getpid()
3854

3955
if six.PY2:
40-
EXPECTED_METRICS = (
56+
EXPECTED_GC_METRICS = (
4157
"GC/objects/%d/all" % PID,
4258
"GC/objects/%d/generation/0" % PID,
4359
"GC/objects/%d/generation/1" % PID,
4460
"GC/objects/%d/generation/2" % PID,
4561
)
4662
else:
47-
EXPECTED_METRICS = (
63+
EXPECTED_GC_METRICS = (
4864
"GC/objects/%d/all" % PID,
4965
"GC/objects/%d/generation/0" % PID,
5066
"GC/objects/%d/generation/1" % PID,
@@ -75,7 +91,7 @@ def data_source():
7591
raises=AssertionError,
7692
)
7793
@pytest.mark.parametrize("top_object_count_limit", (1, 0))
78-
def test_gc_metrics_collection(data_source, top_object_count_limit):
94+
def test_gc_metrics_collection(gc_data_source, top_object_count_limit):
7995
@override_generic_settings(
8096
settings,
8197
{
@@ -85,9 +101,9 @@ def test_gc_metrics_collection(data_source, top_object_count_limit):
85101
)
86102
def _test():
87103
gc.collect()
88-
metrics_table = set(m[0] for m in (data_source() or ()))
104+
metrics_table = set(m[0] for m in (gc_data_source() or ()))
89105

90-
for metric in EXPECTED_METRICS:
106+
for metric in EXPECTED_GC_METRICS:
91107
assert metric in metrics_table
92108

93109
# Verify object count by type metrics are recorded
@@ -109,9 +125,39 @@ def _test():
109125
reason="GC Metrics are always disabled on PyPy",
110126
)
111127
@pytest.mark.parametrize("enabled", (True, False))
112-
def test_gc_metrics_config(data_source, enabled):
128+
def test_gc_metrics_config(gc_data_source, enabled):
113129
@override_generic_settings(settings, {"gc_profiler.enabled": enabled})
114130
def _test():
115-
assert data_source.enabled == enabled
131+
assert gc_data_source.enabled == enabled
116132

117133
_test()
134+
135+
136+
EXPECTED_CPU_METRICS = (
137+
"CPU/User Time",
138+
"CPU/User/Utilization",
139+
"CPU/System Time",
140+
"CPU/System/Utilization",
141+
"CPU/Total Time",
142+
"CPU/Total/Utilization",
143+
)
144+
145+
146+
def test_cpu_metrics_collection(cpu_data_source):
147+
metrics_table = set(m[0] for m in (cpu_data_source() or ()))
148+
149+
for metric in EXPECTED_CPU_METRICS:
150+
assert metric in metrics_table
151+
152+
153+
EXPECTED_MEMORY_METRICS = (
154+
"Memory/Physical/%d" % PID,
155+
"Memory/Physical/Utilization/%d" % PID,
156+
)
157+
158+
159+
def test_memory_metrics_collection(memory_data_source):
160+
metrics_table = set(m[0] for m in (memory_data_source() or ()))
161+
162+
for metric in EXPECTED_MEMORY_METRICS:
163+
assert metric in metrics_table

tox.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,10 @@ deps =
189189
datastore_umemcache: umemcache<1.7
190190
external_boto3-boto01: boto3<2.0
191191
external_boto3-boto01: moto
192+
external_boto3-py27: rsa<4.7.1
192193
external_botocore: botocore
193194
external_botocore: moto[awslambda,ec2,iam]
195+
external_botocore-py27: rsa<4.7.1
194196
external_feedparser-feedparser05: feedparser<6
195197
external_feedparser-feedparser06: feedparser<7
196198
external_httplib2: httplib2<1.0

0 commit comments

Comments
 (0)