Skip to content
Merged
Changes from all commits
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
15 changes: 14 additions & 1 deletion tensorboard/uploader/uploader_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from __future__ import print_function

import collections
import itertools
import os

import grpc
Expand Down Expand Up @@ -81,6 +82,12 @@ def _create_mock_client():
experiment_id="123", url="should not be used!"
)
mock_client.CreateExperiment.return_value = fake_exp_response
mock_client.GetOrCreateBlobSequence.side_effect = (
write_service_pb2.GetOrCreateBlobSequenceResponse(
blob_sequence_id="blob%d" % i
)
for i in itertools.count()
)
return mock_client


Expand Down Expand Up @@ -281,7 +288,6 @@ def test_start_uploading_graphs(self):
graph_event = event_pb2.Event(
graph_def=_create_example_graph_bytes(950)
)

mock_logdir_loader = mock.create_autospec(logdir_loader.LogdirLoader)
mock_logdir_loader.get_run_events.side_effect = [
{
Expand All @@ -302,6 +308,13 @@ def test_start_uploading_graphs(self):
uploader.start_uploading()
self.assertEqual(1, mock_client.CreateExperiment.call_count)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could add self.assertEqual(5, mock_client. GetOrCreateBlobSequence.call_count) here while we're at it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s called 10 times, not 5; twice for each run. I’m presuming that that
was intentional? but unless you feel strongly I’d prefer not to add such
an assertion, as (a) it’s unchanged by this patch and (b) I try to limit
mocking and mock assertions wherever possible because of how brittle
they are and how hard they make it to further update the code and tests.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah indeed, 10 times with 1 graph each. Anyway, fine to leave the assertion out.

self.assertEqual(10, mock_client.WriteBlob.call_count)
for (i, call) in enumerate(mock_client.WriteBlob.call_args_list):
requests = list(call[0][0])
data = b"".join(r.data for r in requests)
self.assertEqual(data, graph_event.graph_def)
self.assertEqual(
set(r.blob_sequence_id for r in requests), {"blob%d" % i},
)
self.assertEqual(0, mock_rate_limiter.tick.call_count)
self.assertEqual(10, mock_blob_rate_limiter.tick.call_count)

Expand Down