def SideEffect(*_, **__): SideEffect.call_count += 1 if SideEffect.call_count == 1: return unittest_utils.FakeProcess( stdout=json.dumps([{ 'foo': 'bar' }])) else: return unittest_utils.FakeProcess( stdout=json.dumps([{ 'bar': 'baz' }]))
def testNoResults(self): """Tests functionality if the query returns no results.""" self._popen_mock.return_value = unittest_utils.FakeProcess(stdout='[]') results, expectation_files = self._querier.QueryBuilder( 'builder', 'ci') self.assertEqual(results, []) self.assertIsNone(expectation_files, None)
def testRateLimitRetryFailure(self): """Tests that rate limit errors stop retrying after enough iterations.""" self._popen_mock.return_value = unittest_utils.FakeProcess( returncode=1, stdout='Exceeded rate limits for foo.') with self.assertRaises(RuntimeError): self._querier._RunBigQueryCommandsForJsonOutput('', {}) self.assertEqual(self._popen_mock.call_count, queries.MAX_QUERY_TRIES)
def testValidResults(self): """Tests functionality when valid results are returned.""" self._relevant_file_mock.return_value = ['foo_expectations'] query_results = [ { 'id': 'build-1234', 'test_id': ('ninja://chrome/test:telemetry_gpu_integration_test/' 'gpu_tests.pixel_integration_test.' 'PixelIntegrationTest.test_name'), 'status': 'FAIL', 'typ_expectations': [ 'RetryOnFailure', ], 'typ_tags': [ 'win', 'intel', ], 'step_name': 'step_name', }, ] self._popen_mock.return_value = unittest_utils.FakeProcess( stdout=json.dumps(query_results)) results, expectation_files = self._querier.QueryBuilder( 'builder', 'ci') self.assertEqual(len(results), 1) self.assertEqual( results[0], data_types.Result('test_name', ['win', 'intel'], 'Failure', 'step_name', '1234')) self.assertEqual(expectation_files, ['foo_expectations'])
def testWebGlVersion(self): """Tests that only results for the correct WebGL version are returned.""" query_results = [ { 'id': 'build-1234', 'test_id': ('ninja://chrome/test:telemetry_gpu_integration_test/' 'gpu_tests.webgl_conformance_integration_test.' 'WebGLConformanceIntegrationTest.test_name'), 'status': 'FAIL', 'typ_expectations': [ 'RetryOnFailure', ], 'typ_tags': [ 'webgl-version-1', ], 'step_name': 'step_name', }, { 'id': 'build-2345', 'test_id': ('ninja://chrome/test:telemetry_gpu_integration_test/' 'gpu_tests.webgl_conformance_integration_test.' 'WebGLConformanceIntegrationTest.test_name'), 'status': 'FAIL', 'typ_expectations': [ 'RetryOnFailure', ], 'typ_tags': [ 'webgl-version-2', ], 'step_name': 'step_name', }, ] querier = gpu_uu.CreateGenericGpuQuerier(suite='webgl_conformance1') self._popen_mock.return_value = uu.FakeProcess( stdout=json.dumps(query_results)) results, expectation_files = querier.QueryBuilder('builder', 'ci') self.assertEqual(len(results), 1) self.assertIsNone(expectation_files) self.assertEqual( results[0], data_types.Result('test_name', ['webgl-version-1'], 'Failure', 'step_name', '1234')) querier = gpu_uu.CreateGenericGpuQuerier(suite='webgl_conformance2') results, expectation_files = querier.QueryBuilder('builder', 'ci') self.assertEqual(len(results), 1) self.assertIsNone(expectation_files) self.assertEqual( results[0], data_types.Result('test_name', ['webgl-version-2'], 'Failure', 'step_name', '2345'))
def testJsonReturned(self): """Tests that valid JSON parsed from stdout is returned.""" query_output = [{'foo': 'bar'}] self._popen_mock.return_value = unittest_utils.FakeProcess( stdout=json.dumps(query_output)) result = self._querier._RunBigQueryCommandsForJsonOutput('', {}) self.assertEqual(result, query_output) self._popen_mock.assert_called_once()
def testInactiveBuilders(self): """Tests that inactive builders are removed.""" results = [{ 'builder_name': 'foo_builder', }] fake_process = unittest_utils.FakeProcess(stdout=json.dumps(results)) self._subprocess_mock.return_value = fake_process initial_builders = [ 'foo_builder', 'bar_builder', ] expected_builders = ['foo_builder'] filtered_builders = self._querier._FilterOutInactiveBuilders( initial_builders, 'ci') self.assertEqual(filtered_builders, expected_builders)
def testByteConversion(self): """Tests that bytes are properly handled if returned.""" results = [{ 'builder_name': 'foo_builder', }] fake_process = unittest_utils.FakeProcess( stdout=json.dumps(results).encode('utf-8')) self._subprocess_mock.return_value = fake_process initial_builders = [ 'foo_builder', 'bar_builder', ] expected_builders = ['foo_builder'] filtered_builders = self._querier._FilterOutInactiveBuilders( initial_builders, 'ci') self.assertEqual(filtered_builders, expected_builders)
def testQueryFailureRaised(self): """Tests that a query failure is properly surfaced.""" self._popen_mock.return_value = unittest_utils.FakeProcess( returncode=1) with self.assertRaises(RuntimeError): self._querier.QueryBuilder('builder', 'ci')
def SideEffect(*_, **__): SideEffect.call_count += 1 if SideEffect.call_count == 1: return unittest_utils.FakeProcess( returncode=1, stdout='Exceeded rate limits for foo.') return unittest_utils.FakeProcess(stdout='[]')
def testExceptionRaisedOnFailure(self): """Tests that an exception is raised if the query fails.""" self._popen_mock.return_value = unittest_utils.FakeProcess( returncode=1) with self.assertRaises(RuntimeError): self._querier._RunBigQueryCommandsForJsonOutput('', {})