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

Side by Side Diff: recipe_engine/simulation_test.py

Issue 2576163002: Fix _GEN_TEST_CACHE. (Closed)
Patch Set: Created 4 years 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 | « no previous file | 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 2014 The LUCI Authors. All rights reserved. 1 # Copyright 2014 The LUCI Authors. All rights reserved.
2 # Use of this source code is governed under the Apache License, Version 2.0 2 # Use of this source code is governed under the Apache License, Version 2.0
3 # that can be found in the LICENSE file. 3 # that can be found in the LICENSE file.
4 4
5 """Provides simulator test coverage for individual recipes.""" 5 """Provides simulator test coverage for individual recipes."""
6 6
7 import StringIO 7 import StringIO
8 import ast 8 import ast
9 import contextlib 9 import contextlib
10 import copy 10 import copy
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 # RunRecipe so that it can persist between RunRecipe calls in the same process. 86 # RunRecipe so that it can persist between RunRecipe calls in the same process.
87 _GEN_TEST_CACHE = {} 87 _GEN_TEST_CACHE = {}
88 88
89 def RunRecipe(recipe_name, test_name): 89 def RunRecipe(recipe_name, test_name):
90 """Actually runs the recipe given the GenTests-supplied test_data.""" 90 """Actually runs the recipe given the GenTests-supplied test_data."""
91 from . import config_types 91 from . import config_types
92 from . import loader 92 from . import loader
93 from . import run 93 from . import run
94 from . import step_runner 94 from . import step_runner
95 95
96 if recipe_name not in _GEN_TEST_CACHE: 96 cache_key = (recipe_name, test_name)
97 if cache_key not in _GEN_TEST_CACHE:
97 recipe_script = _UNIVERSE.load_recipe(recipe_name) 98 recipe_script = _UNIVERSE.load_recipe(recipe_name)
98 test_api = loader.create_test_api(recipe_script.LOADED_DEPS, _UNIVERSE) 99 test_api = loader.create_test_api(recipe_script.LOADED_DEPS, _UNIVERSE)
99 for test_data in recipe_script.gen_tests(test_api): 100 for test_data in recipe_script.gen_tests(test_api):
100 _GEN_TEST_CACHE[(recipe_name, test_data.name)] = copy.deepcopy(test_data) 101 _GEN_TEST_CACHE[(recipe_name, test_data.name)] = copy.deepcopy(test_data)
101 102
102 test_data = _GEN_TEST_CACHE[(recipe_name, test_name)] 103 test_data = _GEN_TEST_CACHE[cache_key]
103 104
104 config_types.ResetTostringFns() 105 config_types.ResetTostringFns()
105 106
106 annotator = SimulationAnnotatorStreamEngine() 107 annotator = SimulationAnnotatorStreamEngine()
107 with stream.StreamEngineInvariants.wrap(annotator) as stream_engine: 108 with stream.StreamEngineInvariants.wrap(annotator) as stream_engine:
108 step_runner = step_runner.SimulationStepRunner(stream_engine, test_data, 109 step_runner = step_runner.SimulationStepRunner(stream_engine, test_data,
109 annotator) 110 annotator)
110 111
111 props = test_data.properties.copy() 112 props = test_data.properties.copy()
112 props['recipe'] = recipe_name 113 props['recipe'] = recipe_name
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 logging.warn("Ignoring %s environment variable." % env_var) 224 logging.warn("Ignoring %s environment variable." % env_var)
224 os.environ.pop(env_var) 225 os.environ.pop(env_var)
225 226
226 global _UNIVERSE 227 global _UNIVERSE
227 _UNIVERSE = universe 228 _UNIVERSE = universe
228 global _ENGINE_FLAGS 229 global _ENGINE_FLAGS
229 _ENGINE_FLAGS = engine_flags 230 _ENGINE_FLAGS = engine_flags
230 231
231 expect_tests.main('recipe_simulation_test', GenerateTests, 232 expect_tests.main('recipe_simulation_test', GenerateTests,
232 cover_omit=cover_omit(), args=args) 233 cover_omit=cover_omit(), args=args)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698