GranularRetriableTestWrapper

public class GranularRetriableTestWrapper
extends Object implements IRemoteTest, ITestCollector

java.lang.Object
   ↳ com.android.tradefed.testtype.suite.GranularRetriableTestWrapper


A wrapper class works on the IRemoteTest to granulate the IRemoteTest in testcase level. An IRemoteTest can contain multiple testcases. Previously, these testcases are treated as a whole: When IRemoteTest runs, all testcases will run. Some IRemoteTest (The ones that implements ITestFilterReceiver) can accept a whitelist of testcases and only run those testcases. This class takes advantage of the existing feature and provides a more flexible way to run test suite.

  • Single testcase can be retried multiple times (within the same IRemoteTest run) to reduce the non-test-error failure rates.
  • The retried testcases are dynamically collected from previous run failures.

Note:

  • The prerequisite to run a subset of test cases is that the test type should implement the interface ITestFilterReceiver.
  • X is customized max retry number.

Summary

Public constructors

GranularRetriableTestWrapper(IRemoteTest test, ITestInvocationListener mainListener, TestFailureListener failureListener, moduleLevelListeners, int maxRunLimit)

Public methods

getAttemptSuccessStats()

Returns the attempts that turned into success.

final int getExpectedTestsCount()

Calculate the number of testcases in the IRemoteTest.

final getFinalTestRunResults()

Get the merged TestRunResults from each IRemoteTest run.

ModuleListener getResultListener()

Returns the listener containing all the results.

final long getRetryFailed()

Returns the number of tests we couldn't change status from failed to pass.

final long getRetrySuccess()

Returns the number of tests we managed to change status from failed to pass.

final long getRetryTime()

Returns the elapsed time in retry attempts.

boolean hasFailed()

Check if any testRunResult has ever failed.

void run(ITestInvocationListener listener)

Schedule a series of IRemoteTest#run(ITestInvocationListener).

void setCollectTestsOnly(boolean shouldCollectTest)

Enables or disables test collection mode

void setInvocationContext(IInvocationContext moduleInvocationContext)

Set the IInvocationContext as a GranularRetriableTestWrapper attribute.

void setLogSaver(ILogSaver logSaver)

Set the Module's ILogSaver as a GranularRetriableTestWrapper attribute.

void setMarkTestsSkipped(boolean skipTestCases)

Set the ModuleDefinition RunStrategy as a GranularRetriableTestWrapper attribute.

void setMetricCollectors( runMetricCollectors)

Set the ModuleDefinition's runMetricCollector as a GranularRetriableTestWrapper attribute.

void setModuleConfig(IConfiguration moduleConfiguration)

Set the ModuleDefinition's ModuleConfig as a GranularRetriableTestWrapper attribute.

void setModuleId(String moduleId)

Set the ModuleDefinition name as a GranularRetriableTestWrapper attribute.

final void setRebootAtLastRetry(boolean rebootAtLastRetry)

Sets the flag to reboot devices at the last intra-module retry.

final void setRetryStrategy(ITestSuite.RetryStrategy retryStrategy)

Sets the RetryStrategy to be used when retrying.

Public constructors

GranularRetriableTestWrapper

public GranularRetriableTestWrapper (IRemoteTest test, 
                ITestInvocationListener mainListener, 
                TestFailureListener failureListener, 
                 moduleLevelListeners, 
                int maxRunLimit)

Parameters
test IRemoteTest

mainListener ITestInvocationListener

failureListener TestFailureListener

moduleLevelListeners

maxRunLimit int

Public methods

getAttemptSuccessStats

public  getAttemptSuccessStats ()

Returns the attempts that turned into success.

Returns

getExpectedTestsCount

public final int getExpectedTestsCount ()

Calculate the number of testcases in the IRemoteTest. This value distincts the same testcases that are rescheduled multiple times.

Returns
int

getFinalTestRunResults

public final  getFinalTestRunResults ()

Get the merged TestRunResults from each IRemoteTest run.

Returns

getResultListener

public ModuleListener getResultListener ()

Returns the listener containing all the results.

Returns
ModuleListener

getRetryFailed

public final long getRetryFailed ()

Returns the number of tests we couldn't change status from failed to pass.

Returns
long

getRetrySuccess

public final long getRetrySuccess ()

Returns the number of tests we managed to change status from failed to pass.

Returns
long

getRetryTime

public final long getRetryTime ()

Returns the elapsed time in retry attempts.

Returns
long

hasFailed

public boolean hasFailed ()

Check if any testRunResult has ever failed. This check is used for bug report only.

Returns
boolean

run

public void run (ITestInvocationListener listener)

Schedule a series of IRemoteTest#run(ITestInvocationListener).

Parameters
listener ITestInvocationListener: The ResultForwarder listener which contains a new moduleListener for each run.

Throws
DeviceNotAvailableException

setCollectTestsOnly

public void setCollectTestsOnly (boolean shouldCollectTest)

Enables or disables test collection mode

setInvocationContext

public void setInvocationContext (IInvocationContext moduleInvocationContext)

Set the IInvocationContext as a GranularRetriableTestWrapper attribute.

Parameters
moduleInvocationContext IInvocationContext: The wrapper uses the InvocationContext to initialize the MetricCollector when necessary.

setLogSaver

public void setLogSaver (ILogSaver logSaver)

Set the Module's ILogSaver as a GranularRetriableTestWrapper attribute.

Parameters
logSaver ILogSaver: The listeners for each test run should save the logs.

setMarkTestsSkipped

public void setMarkTestsSkipped (boolean skipTestCases)

Set the ModuleDefinition RunStrategy as a GranularRetriableTestWrapper attribute.

Parameters
skipTestCases boolean: whether the testcases should be skipped.

setMetricCollectors

public void setMetricCollectors ( runMetricCollectors)

Set the ModuleDefinition's runMetricCollector as a GranularRetriableTestWrapper attribute.

Parameters
runMetricCollectors : A list of MetricCollector for the module.

setModuleConfig

public void setModuleConfig (IConfiguration moduleConfiguration)

Set the ModuleDefinition's ModuleConfig as a GranularRetriableTestWrapper attribute.

Parameters
moduleConfiguration IConfiguration: Provide the module metrics.

setModuleId

public void setModuleId (String moduleId)

Set the ModuleDefinition name as a GranularRetriableTestWrapper attribute.

Parameters
moduleId String: the name of the moduleDefinition.

setRebootAtLastRetry

public final void setRebootAtLastRetry (boolean rebootAtLastRetry)

Sets the flag to reboot devices at the last intra-module retry.

Parameters
rebootAtLastRetry boolean

setRetryStrategy

public final void setRetryStrategy (ITestSuite.RetryStrategy retryStrategy)

Sets the RetryStrategy to be used when retrying.

Parameters
retryStrategy ITestSuite.RetryStrategy