git-cl: Add tests for metrics collection.
Bug: 897394
Change-Id: I07959e870fef4e6a6b8e6e7c974397d3306460c1
Reviewed-on: https://chromium-review.googlesource.com/c/1315839
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
Reviewed-by: Andrii Shyshkalov <tandrii@chromium.org>
diff --git a/tests/git_cl_test.py b/tests/git_cl_test.py
index 63b9b0c..4560065 100755
--- a/tests/git_cl_test.py
+++ b/tests/git_cl_test.py
@@ -622,6 +622,10 @@
super(TestGitCl, self).setUp()
self.calls = []
self._calls_done = []
+ self.mock(git_cl, 'time_time',
+ lambda: self._mocked_call('time.time'))
+ self.mock(git_cl.metrics.collector, 'add_repeated',
+ lambda *a: self._mocked_call('add_repeated', *a))
self.mock(subprocess2, 'call', self._mocked_call)
self.mock(subprocess2, 'check_call', self._mocked_call)
self.mock(subprocess2, 'check_output', self._mocked_call)
@@ -1007,16 +1011,22 @@
'1hashPerLine\n'),
]
+ metrics_arguments = []
+
if notify:
ref_suffix = '%ready,notify=ALL'
+ metrics_arguments += ['ready', 'notify=ALL']
else:
if not issue and squash:
ref_suffix = '%wip'
+ metrics_arguments.append('wip')
else:
ref_suffix = '%notify=NONE'
+ metrics_arguments.append('notify=NONE')
if title:
ref_suffix += ',m=' + title
+ metrics_arguments.append('m')
calls += [
((['git', 'config', 'rietveld.cc'],), ''),
@@ -1025,9 +1035,11 @@
# All reviwers and ccs get into ref_suffix.
for r in sorted(reviewers):
ref_suffix += ',r=%s' % r
+ metrics_arguments.append('r')
for c in sorted(['chromium-reviews+test-more-cc@chromium.org',
'joe@example.com'] + cc):
ref_suffix += ',cc=%s' % c
+ metrics_arguments.append('cc')
reviewers, cc = [], []
else:
# TODO(crbug/877717): remove this case.
@@ -1043,36 +1055,51 @@
for r in sorted(reviewers):
if r != 'bad-account-or-email':
ref_suffix += ',r=%s' % r
+ metrics_arguments.append('r')
reviewers.remove(r)
for c in sorted(['joe@example.com'] + cc):
ref_suffix += ',cc=%s' % c
+ metrics_arguments.append('cc')
if c in cc:
cc.remove(c)
if not tbr:
for k, v in sorted((labels or {}).items()):
ref_suffix += ',l=%s+%d' % (k, v)
+ metrics_arguments.append('l=%s+%d' % (k, v))
- calls.append((
- (['git', 'push',
- 'https://%s.googlesource.com/my/repo' % short_hostname,
- ref_to_push + ':refs/for/refs/heads/master' + ref_suffix],),
- (('remote:\n'
- 'remote: Processing changes: (\)\n'
- 'remote: Processing changes: (|)\n'
- 'remote: Processing changes: (/)\n'
- 'remote: Processing changes: (-)\n'
- 'remote: Processing changes: new: 1 (/)\n'
- 'remote: Processing changes: new: 1, done\n'
- 'remote:\n'
- 'remote: New Changes:\n'
- 'remote: https://%s-review.googlesource.com/#/c/my/repo/+/123456'
- ' XXX\n'
- 'remote:\n'
- 'To https://%s.googlesource.com/my/repo\n'
- ' * [new branch] hhhh -> refs/for/refs/heads/master\n'
- ) % (short_hostname, short_hostname))
- ))
+ calls += [
+ (('time.time',), 1000,),
+ ((['git', 'push',
+ 'https://%s.googlesource.com/my/repo' % short_hostname,
+ ref_to_push + ':refs/for/refs/heads/master' + ref_suffix],),
+ (('remote:\n'
+ 'remote: Processing changes: (\)\n'
+ 'remote: Processing changes: (|)\n'
+ 'remote: Processing changes: (/)\n'
+ 'remote: Processing changes: (-)\n'
+ 'remote: Processing changes: new: 1 (/)\n'
+ 'remote: Processing changes: new: 1, done\n'
+ 'remote:\n'
+ 'remote: New Changes:\n'
+ 'remote: https://%s-review.googlesource.com/#/c/my/repo/+/123456'
+ ' XXX\n'
+ 'remote:\n'
+ 'To https://%s.googlesource.com/my/repo\n'
+ ' * [new branch] hhhh -> refs/for/refs/heads/master\n'
+ ) % (short_hostname, short_hostname)),),
+ (('time.time',), 2000,),
+ (('add_repeated',
+ 'sub_commands',
+ {
+ 'execution_time': 1000,
+ 'command': 'git push',
+ 'exit_code': 0,
+ 'arguments': sorted(metrics_arguments),
+ }),
+ None,),
+ ]
+
if squash:
calls += [
((['git', 'config', 'branch.master.gerritissue', '123456'],),