Skip to content

Commit

Permalink
Added test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulhacker committed Oct 14, 2023
1 parent 5301162 commit 1ce58db
Showing 1 changed file with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ def test_system_metrics_instrument(self):
for scope_metrics in resource_metrics.scope_metrics:
for metric in scope_metrics.metrics:
metric_names.append(metric.name)
self.assertEqual(len(metric_names), 21)

observer_names = [
"system.cpu.time",
Expand All @@ -117,12 +116,17 @@ def test_system_metrics_instrument(self):
"system.thread_count",
f"process.runtime.{self.implementation}.memory",
f"process.runtime.{self.implementation}.cpu_time",
f"process.runtime.{self.implementation}.gc_count",
f"process.runtime.{self.implementation}.thread_count",
f"process.runtime.{self.implementation}.context_switches",
f"process.runtime.{self.implementation}.cpu.utilization",
]

if self.implementation == "pypy":
self.assertEqual(len(metric_names), 20)
else:
self.assertEqual(len(metric_names), 21)
observer_names.append(f"process.runtime.{self.implementation}.gc_count",)

for observer in metric_names:
self.assertIn(observer, observer_names)
observer_names.remove(observer)
Expand All @@ -131,12 +135,14 @@ def test_runtime_metrics_instrument(self):
runtime_config = {
"process.runtime.memory": ["rss", "vms"],
"process.runtime.cpu.time": ["user", "system"],
"process.runtime.gc_count": None,
"process.runtime.thread_count": None,
"process.runtime.cpu.utilization": None,
"process.runtime.context_switches": ["involuntary", "voluntary"],
}

if self.implementation != "pypy":
runtime_config["process.runtime.gc_count"] = None

reader = InMemoryMetricReader()
meter_provider = MeterProvider(metric_readers=[reader])
runtime_metrics = SystemMetricsInstrumentor(config=runtime_config)
Expand All @@ -147,17 +153,21 @@ def test_runtime_metrics_instrument(self):
for scope_metrics in resource_metrics.scope_metrics:
for metric in scope_metrics.metrics:
metric_names.append(metric.name)
self.assertEqual(len(metric_names), 6)

observer_names = [
f"process.runtime.{self.implementation}.memory",
f"process.runtime.{self.implementation}.cpu_time",
f"process.runtime.{self.implementation}.gc_count",
f"process.runtime.{self.implementation}.thread_count",
f"process.runtime.{self.implementation}.context_switches",
f"process.runtime.{self.implementation}.cpu.utilization",
]

if self.implementation == "pypy":
self.assertEqual(len(metric_names), 5)
else:
self.assertEqual(len(metric_names), 6)
observer_names.append(f"process.runtime.{self.implementation}.gc_count")

for observer in metric_names:
self.assertIn(observer, observer_names)
observer_names.remove(observer)
Expand Down Expand Up @@ -782,6 +792,9 @@ def test_runtime_cpu_time(self, mock_process_cpu_times):

@mock.patch("gc.get_count")
def test_runtime_get_count(self, mock_gc_get_count):
if self.implementation == "pypy":
return

mock_gc_get_count.configure_mock(**{"return_value": (1, 2, 3)})

expected = [
Expand Down

0 comments on commit 1ce58db

Please sign in to comment.