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

Side by Side Diff: recipe_engine/unittests/run_test.py

Issue 1959563002: Use subprocess42 in recipe_engine to avoid threading madness. (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/recipes-py@master
Patch Set: Don't need a lock because we're single threaded now! 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
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2014 The Chromium Authors. All rights reserved. 2 # Copyright 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 import json 6 import json
7 import os 7 import os
8 import re 8 import re
9 import subprocess 9 import subprocess
10 import sys 10 import sys
11 import unittest 11 import unittest
12 import time
12 13
13 BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname( 14 BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(
14 os.path.abspath(__file__)))) 15 os.path.abspath(__file__))))
15 THIRD_PARTY = os.path.join(BASE_DIR, 'recipe_engine', 'third_party') 16 THIRD_PARTY = os.path.join(BASE_DIR, 'recipe_engine', 'third_party')
16 sys.path.insert(0, os.path.join(THIRD_PARTY, 'mock-1.0.1')) 17 sys.path.insert(0, os.path.join(THIRD_PARTY, 'mock-1.0.1'))
17 sys.path.insert(0, BASE_DIR) 18 sys.path.insert(0, BASE_DIR)
18 19
19 import recipe_engine.run 20 import recipe_engine.run
20 import recipe_engine.step_runner 21 import recipe_engine.step_runner
21 from recipe_engine import recipe_test_api 22 from recipe_engine import recipe_test_api
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 return None 137 return None
137 138
138 with self.assertRaises(AssertionError): 139 with self.assertRaises(AssertionError):
139 engine.run(FakeScript(), api) 140 engine.run(FakeScript(), api)
140 141
141 def test_subannotations(self): 142 def test_subannotations(self):
142 proc = subprocess.Popen( 143 proc = subprocess.Popen(
143 self._run_cmd('engine_tests/subannotations'), 144 self._run_cmd('engine_tests/subannotations'),
144 stdout=subprocess.PIPE, 145 stdout=subprocess.PIPE,
145 stderr=subprocess.PIPE) 146 stderr=subprocess.PIPE)
146 stdout, stderr = proc.communicate() 147 stdout, _ = proc.communicate()
147 self.assertRegexpMatches(stdout, r'(?m)^!@@@BUILD_STEP@steppy@@@$') 148 self.assertRegexpMatches(stdout, r'(?m)^!@@@BUILD_STEP@steppy@@@$')
148 self.assertRegexpMatches(stdout, r'(?m)^@@@BUILD_STEP@pippy@@@$') 149 self.assertRegexpMatches(stdout, r'(?m)^@@@BUILD_STEP@pippy@@@$')
149 # Before 'Subannotate me' we expect an extra STEP_CURSOR to reset the 150 # Before 'Subannotate me' we expect an extra STEP_CURSOR to reset the
150 # state. 151 # state.
151 self.assertRegexpMatches(stdout, 152 self.assertRegexpMatches(stdout,
152 r'(?m)^@@@STEP_CURSOR@Subannotate me@@@\n@@@STEP_CLOSED@@@$') 153 r'(?m)^@@@STEP_CURSOR@Subannotate me@@@\n@@@STEP_CLOSED@@@$')
153 154
155 def test_bad_subprocess(self):
156 now = time.time()
157 self._test_recipe('engine_tests/bad_subprocess')
158 after = time.time()
159
160 # Test has an internal 10s timeout for the bad daemon step, but the daemon's
161 # parent process quits immediately. If this takes longer than 5 seconds to
162 # run, we consider it failed.
163 self.assertLess(after - now, 5)
164
154 165
155 if __name__ == '__main__': 166 if __name__ == '__main__':
156 unittest.TestCase.maxDiff = None 167 unittest.TestCase.maxDiff = None
157 unittest.main() 168 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698