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

Side by Side Diff: appengine/chromium_try_flakes/handlers/test/flake_issues_test.py

Issue 2007133005: Cap the maximum number of flaky tests that we record from a step (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Added test Created 4 years, 7 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 unified diff | Download patch
« no previous file with comments | « appengine/chromium_try_flakes/handlers/flake_issues.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2015 The Chromium Authors. All rights reserved. 1 # Copyright 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import datetime 5 import datetime
6 import json 6 import json
7 import mock 7 import mock
8 import urllib2 8 import urllib2
9 9
10 from google.appengine.datastore import datastore_stub_util 10 from google.appengine.datastore import datastore_stub_util
(...skipping 839 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 850
851 flakes = Flake.query().fetch() 851 flakes = Flake.query().fetch()
852 self.assertEqual(len(flakes), len(EXPECTED_FLAKES)) 852 self.assertEqual(len(flakes), len(EXPECTED_FLAKES))
853 expected_flake_names = set([ef[1] for ef in EXPECTED_FLAKES]) 853 expected_flake_names = set([ef[1] for ef in EXPECTED_FLAKES])
854 actual_flake_names = set([f.name for f in flakes]) 854 actual_flake_names = set([f.name for f in flakes])
855 self.assertEqual(expected_flake_names, actual_flake_names) 855 self.assertEqual(expected_flake_names, actual_flake_names)
856 856
857 for flake in flakes: 857 for flake in flakes:
858 self.assertEqual(flake.occurrences, [flaky_run.key]) 858 self.assertEqual(flake.occurrences, [flaky_run.key])
859 859
860 def test_records_step_as_a_flake_when_too_many_tests_fail(self):
861 now = datetime.datetime.utcnow()
862 br_f, br_s = self._create_build_runs(now - datetime.timedelta(hours=1), now)
863 urlfetch_mock = mock.Mock(side_effect = [
864 # Buildbot reply.
865 mock.Mock(status_code=200, content=json.dumps({
866 'steps': [
867 {'results': [2], 'name': 'test-step', 'text': ['']},
868 ]
869 })),
870 # Test-results reply.
871 mock.Mock(status_code=200, content=json.dumps({
872 'tests': {
873 'test%d' % i: {
874 'expected': 'PASS',
875 'actual': 'FAIL',
876 } for i in range(51)
877 }
878 }))
879 ])
880
881 with mock.patch('google.appengine.api.urlfetch.fetch', urlfetch_mock):
882 self.test_app.post('/issues/create_flaky_run',
883 {'failure_run_key': br_f.urlsafe(),
884 'success_run_key': br_s.urlsafe()})
885
886 flaky_runs = FlakyRun.query().fetch(100)
887 self.assertEqual(len(flaky_runs), 1)
888 flaky_run = flaky_runs[0]
889 self.assertEqual(len(flaky_run.flakes), 1)
890 self.assertEqual(flaky_run.flakes[0].name, 'test-step')
891 self.assertEqual(flaky_run.flakes[0].failure, 'test-step')
892
860 def test_flattens_tests_correctly(self): 893 def test_flattens_tests_correctly(self):
861 passed, failed, skipped = CreateFlakyRun._flatten_tests( 894 passed, failed, skipped = CreateFlakyRun._flatten_tests(
862 json.loads(TEST_TEST_RESULTS_REPLY)['tests'], '/') 895 json.loads(TEST_TEST_RESULTS_REPLY)['tests'], '/')
863 self.assertEqual(set(passed), set(['test1'])) 896 self.assertEqual(set(passed), set(['test1']))
864 self.assertEqual(set(failed), set(['test2/a', 'test2/d'])) 897 self.assertEqual(set(failed), set(['test2/a', 'test2/d']))
865 self.assertEqual(set(skipped), set(['test2/b'])) 898 self.assertEqual(set(skipped), set(['test2/b']))
866 899
867 def test_stores_and_updates_is_step_property(self): 900 def test_stores_and_updates_is_step_property(self):
868 now = datetime.datetime.utcnow() 901 now = datetime.datetime.utcnow()
869 br_f, br_s = self._create_build_runs(now - datetime.timedelta(hours=1), now) 902 br_f, br_s = self._create_build_runs(now - datetime.timedelta(hours=1), now)
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
921 key = Flake(name='foobar', issue_id=issue.id).put() 954 key = Flake(name='foobar', issue_id=issue.id).put()
922 self.test_app.get( 955 self.test_app.get(
923 '/override_issue_id?key=%s&issue_id=%d' % (key.urlsafe(), issue.id)) 956 '/override_issue_id?key=%s&issue_id=%d' % (key.urlsafe(), issue.id))
924 self.assertEqual(key.get().issue_id, issue.id) 957 self.assertEqual(key.get().issue_id, issue.id)
925 958
926 def test_overrides_issue_id_with_0(self): 959 def test_overrides_issue_id_with_0(self):
927 key = Flake(name='foobar', issue_id=100000).put() 960 key = Flake(name='foobar', issue_id=100000).put()
928 self.test_app.get( 961 self.test_app.get(
929 '/override_issue_id?key=%s&issue_id=0' % key.urlsafe()) 962 '/override_issue_id?key=%s&issue_id=0' % key.urlsafe())
930 self.assertEqual(key.get().issue_id, 0) 963 self.assertEqual(key.get().issue_id, 0)
OLDNEW
« no previous file with comments | « appengine/chromium_try_flakes/handlers/flake_issues.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698