Skip to content

Commit

Permalink
Add test case for metric lifetime error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
krishung5 committed Jun 7, 2023
1 parent 11be9f6 commit df20cf2
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions qa/python_models/custom_metrics/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,34 @@ def test_dup_metric_empty_labels(self):
# underlying metric, and all instances will be updated
self._dup_metric_helper()

def test_metric_lifetime_error(self):
# Test the error handling when the corresponding 'MetricFamily' is
# deleted before the 'Metric' is deleted, and the 'Metric' is still
# being used for metric operations
metric_family = pb_utils.MetricFamily(
name="test_metric_lifetime_error",
description="test metric lifetime error",
kind=pb_utils.MetricFamily.COUNTER)
labels = {"example1": "counter_label1", "example2": "counter_label2"}
metric = metric_family.Metric(labels=labels)

# Intentionally delete the 'MetricFamily' before the 'Metric' being deleted
del metric_family

error_msg = "Invalid metric operation as the corresponding 'MetricFamily' has been deleted."

with self.assertRaises(pb_utils.TritonModelException) as ex:
metric.set(10)
self.assertIn(error_msg, str(ex.exception))

with self.assertRaises(pb_utils.TritonModelException) as ex:
metric.increment(10)
self.assertIn(error_msg, str(ex.exception))

with self.assertRaises(pb_utils.TritonModelException) as ex:
metric.value()
self.assertIn(error_msg, str(ex.exception))


class TritonPythonModel:

Expand Down

0 comments on commit df20cf2

Please sign in to comment.