Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(271)

Unified Diff: recipe_engine/unittests/stream_logdog_test.py

Issue 2378903002: Annotation protobuf code can now dump final. (Closed)
Patch Set: Rebase, add unit test. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: recipe_engine/unittests/stream_logdog_test.py
diff --git a/recipe_engine/unittests/stream_logdog_test.py b/recipe_engine/unittests/stream_logdog_test.py
index 66b0e89c1ef4d6de6cb642b9ff08e6a97f5c30e6..5d2a8b922b7c04530023abf7f233728df49a0032 100755
--- a/recipe_engine/unittests/stream_logdog_test.py
+++ b/recipe_engine/unittests/stream_logdog_test.py
@@ -7,6 +7,9 @@ import collections
import contextlib
import datetime
import json
+import os
+import shutil
+import tempfile
import threading
import time
import unittest
@@ -25,6 +28,15 @@ from recipe_engine import stream_logdog
import annotations_pb2 as pb
+@contextlib.contextmanager
+def tempdir():
+ tdir = tempfile.mkdtemp(suffix='stream_logdog_test', dir=test_env.BASE_DIR)
+ try:
+ yield tdir
+ finally:
+ shutil.rmtree(tdir)
+
+
def _translate_annotation_datagram(dg):
"""Translate annotation datagram binary data into a Python dict modeled after
the JSONPB projection of the datagram.
@@ -404,6 +416,45 @@ class StreamEngineTest(unittest.TestCase):
},
})
+ def testDumpFinalState(self):
+ self.env.argv = ['fake_program', 'arg0', 'arg1']
+ self.env.environ['foo'] = 'bar'
+ self.env.cwd = 'CWD'
+
+ # Create a StreamEngine with an update interval that will trigger each time
+ # _advance_time is called.
+ with tempdir() as tdir:
+ dump_path = os.path.join(tdir, 'dump.bin')
+ with self._new_stream_engine(
+ update_interval=datetime.timedelta(seconds=1),
+ dump_path=dump_path) as se:
+ # Initial stream state (no steps).
+ self.assertEqual(self.client.all_streams(), {
+ u'annotations': {
+ u'name': u'steps',
+ u'started': u'2106-06-12T01:02:03Z',
+ u'command': {
+ u'commandLine': [u'fake_program', u'arg0', u'arg1'],
+ u'cwd': u'CWD',
+ u'environ': {u'foo': u'bar'},
+ },
+ },
+ })
+
+ with open(dump_path, 'rb') as fd:
+ step = _translate_annotation_datagram(fd.read())
+ self.assertEqual(step, {
+ u'name': u'steps',
+ u'status': u'SUCCESS',
+ u'started': u'2106-06-12T01:02:03Z',
+ u'ended': u'2106-06-12T01:02:04Z',
+ u'command': {
+ u'commandLine': [u'fake_program', u'arg0', u'arg1'],
+ u'cwd': u'CWD',
+ u'environ': {u'foo': u'bar'},
+ },
+ })
+
def testBasicStream(self):
self.env.argv = ['fake_program', 'arg0', 'arg1']
self.env.environ['foo'] = 'bar'
« recipe_engine/stream_logdog.py ('K') | « recipe_engine/stream_logdog.py ('k') | recipes.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698