xref: /aosp_15_r20/external/angle/build/android/test_runner_test.py (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1#!/usr/bin/env vpython3
2#
3# Copyright 2024 The Chromium Authors
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
7import unittest
8
9from unittest import mock
10
11import test_runner
12
13
14class UploadExceptionTest(unittest.TestCase):
15
16  def setUp(self):
17    self.sink_client = mock.MagicMock()
18    self.exc_recorder = mock.MagicMock()
19
20  def testNoExceptions(self):
21    self.exc_recorder.size.return_value = 0
22    test_runner.UploadExceptions(self.sink_client, self.exc_recorder)
23    self.exc_recorder.to_dict.assert_not_called()
24    self.sink_client.UpdateInvocationExtendedProperties.assert_not_called()
25
26  def testUploadSuccess(self):
27    test_runner.UploadExceptions(self.sink_client, self.exc_recorder)
28    self.exc_recorder.to_dict.assert_called_once()
29    self.sink_client.UpdateInvocationExtendedProperties.assert_called_once()
30    self.exc_recorder.clear.assert_called_once()
31
32  def testUploadSuccessWithClearStacktrace(self):
33    self.sink_client.UpdateInvocationExtendedProperties.side_effect = [
34        Exception("Error 1"), None
35    ]
36    test_runner.UploadExceptions(self.sink_client, self.exc_recorder)
37    self.assertEqual(self.exc_recorder.to_dict.call_count, 2)
38    self.assertEqual(
39        self.sink_client.UpdateInvocationExtendedProperties.call_count, 2)
40    self.exc_recorder.clear_stacktrace.assert_called_once()
41    self.exc_recorder.clear.assert_called_once()
42
43  def testUploadSuccessWithClearRecords(self):
44    self.sink_client.UpdateInvocationExtendedProperties.side_effect = [
45        Exception("Error 1"), Exception("Error 2"), None
46    ]
47    test_runner.UploadExceptions(self.sink_client, self.exc_recorder)
48    self.assertEqual(self.exc_recorder.to_dict.call_count, 3)
49    self.assertEqual(
50        self.sink_client.UpdateInvocationExtendedProperties.call_count, 3)
51    self.exc_recorder.clear_stacktrace.assert_called_once()
52    self.assertEqual(self.exc_recorder.clear.call_count, 2)
53    self.exc_recorder.register.assert_called_once()
54
55  def testUploadFailure(self):
56    self.sink_client.UpdateInvocationExtendedProperties.side_effect = (
57        Exception("Error"))
58    test_runner.UploadExceptions(self.sink_client, self.exc_recorder)
59    self.assertEqual(self.exc_recorder.to_dict.call_count, 3)
60    self.assertEqual(
61        self.sink_client.UpdateInvocationExtendedProperties.call_count, 3)
62    self.assertEqual(self.exc_recorder.clear.call_count, 2)
63    self.exc_recorder.clear_stacktrace.assert_called_once()
64    self.exc_recorder.register.assert_called_once()
65