Home | History | Annotate | Download | only in examples
      1 # Copyright 2017 The Chromium Authors. All rights reserved.
      2 # Use of this source code is governed by a BSD-style license that can be
      3 # found in the LICENSE file.
      4 
      5 
      6 DEPS = [
      7   'recipe_engine/context',
      8   'recipe_engine/path',
      9   'recipe_engine/properties',
     10   'recipe_engine/step',
     11   'run',
     12   'vars',
     13 ]
     14 
     15 
     16 def myfunc(api, i):
     17   api.run(api.step, 'run %d' % i, cmd=['echo', str(i)])
     18 
     19 
     20 def RunSteps(api):
     21   api.vars.setup()
     22   try:
     23     api.run(api.step, 'fail', cmd=['false'])
     24   except api.step.StepFailure:
     25     pass
     26   api.run(api.step, 'fail again', cmd=['false'], abort_on_failure=False)
     27   api.run(api.step, 'do a thing', cmd=['echo', 'do the thing'])
     28   assert len(api.run.failed_steps) == 2
     29 
     30   # Run once.
     31   for i in range(10):
     32     api.run.run_once(myfunc, api, i)
     33 
     34   # Read and write files.
     35   api.run.readfile('myfile.txt')
     36   api.run.writefile('myfile.txt', 'contents')
     37   api.run.rmtree('mydir')
     38   api.run.asset_version('my_asset', api.vars.cache_dir.join('work', 'skia'))
     39 
     40   # Merge PATHs.
     41   with api.context(env={'PATH': 'mydir:%(PATH)s'}):
     42     api.run(api.step, 'env', cmd=['env'])
     43 
     44   def between_attempts_fn(attempt):
     45     api.run(api.step, 'between_attempts #%d' % attempt,
     46             cmd=['echo', 'between_attempt'])
     47 
     48   # Retries.
     49   try:
     50     api.run.with_retry(api.step, 'retry fail', 5, cmd=['false'],
     51                        between_attempts_fn=between_attempts_fn)
     52   except api.step.StepFailure:
     53     pass
     54   assert len(api.run.failed_steps) == 7
     55 
     56   api.run.with_retry(api.step, 'retry success', 3, cmd=['false'],
     57                      between_attempts_fn=between_attempts_fn)
     58   assert len(api.run.failed_steps) == 7
     59 
     60   # Check failure.
     61   api.run.check_failure()
     62 
     63 
     64 def GenTests(api):
     65   buildername = 'Build-Win-Clang-x86_64-Release-Vulkan'
     66   yield (
     67       api.test('test') +
     68       api.properties(buildername=buildername,
     69                      repository='https://skia.googlesource.com/skia.git',
     70                      revision='abc123',
     71                      path_config='kitchen',
     72                      swarm_out_dir='[SWARM_OUT_DIR]') +
     73       api.step_data('fail', retcode=1) +
     74       api.step_data('fail again', retcode=1) +
     75       api.step_data('retry fail', retcode=1) +
     76       api.step_data('retry fail (attempt 2)', retcode=1) +
     77       api.step_data('retry fail (attempt 3)', retcode=1) +
     78       api.step_data('retry fail (attempt 4)', retcode=1) +
     79       api.step_data('retry fail (attempt 5)', retcode=1) +
     80       api.step_data('retry success', retcode=1) +
     81       api.step_data('retry success (attempt 2)', retcode=1)
     82     )
     83