Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stats: Make defensive copy and set end time for ViewData when export. #512

Merged
merged 5 commits into from
Feb 21, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix one test.
  • Loading branch information
songy23 committed Feb 21, 2019
commit 13f724ba45a476375d7a03b2909650149d9ea839
23 changes: 22 additions & 1 deletion tests/unit/stats/test_measure_to_view_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,27 @@

import mock

from opencensus.stats import aggregation as aggregation_module
from opencensus.stats import measure as measure_module
from opencensus.stats import view as view_module
from opencensus.stats import view_data as view_data_module
from opencensus.stats import measure_to_view_map as measure_to_view_map_module
from opencensus.stats.measure import BaseMeasure
from opencensus.stats.measure import MeasureInt
from opencensus.stats.view import View
from opencensus.stats.view_data import ViewData
from opencensus.tags import tag_key as tag_key_module


METHOD_KEY = tag_key_module.TagKey("method")
REQUEST_COUNT_MEASURE = measure_module.MeasureInt(
"request_count", "number of requests", "1")
REQUEST_COUNT_VIEW_NAME = "request_count_view"
COUNT = aggregation_module.CountAggregation()
REQUEST_COUNT_VIEW = view_module.View(
REQUEST_COUNT_VIEW_NAME,
"number of requests broken down by methods",
[METHOD_KEY], REQUEST_COUNT_MEASURE, COUNT)


class TestMeasureToViewMap(unittest.TestCase):
Expand Down Expand Up @@ -386,7 +402,10 @@ def test_export_duplicates_viewdata(self):
exporter = mock.Mock()
mtvm.exporters.append(exporter)

view_data = mock.Mock(spec=ViewData)
timestamp1 = mock.Mock()
timestamp2 = mock.Mock()
view_data = view_data_module.ViewData(
REQUEST_COUNT_VIEW, timestamp1, timestamp2)
mtvm.export([view_data])
mtvm.export([view_data])
self.assertEqual(exporter.export.call_count, 2)
Expand All @@ -395,3 +414,5 @@ def test_export_duplicates_viewdata(self):
exported_vd1 = exported_call1[0][0][0]
exported_vd2 = exported_call2[0][0][0]
self.assertIsNot(exported_vd1, exported_vd2)
self.assertIsNot(exported_vd1.end_time, view_data.end_time)
self.assertIsNot(exported_vd2.end_time, view_data.end_time)