Poll for value to asynchronously satisfy constraint
outConstObj = Eventually( creates a
outConstObj, that polls for an actual value returned from
a function handle to asynchronously satisfy the
It is not satisfied if evaluation of the function handle does not produce a value that
satisfies the constraint within 20 seconds. The testing framework invokes the
drawnow function while the
waits for specified function to satisfy the constraint.
Maximum time to attempt to produce passing behavior, specified in seconds
Output produced when the test framework invokes the supplied function handle. This property is read only and is set when the test framework invokes the function handle.
Maximum time to attempt to produce passing behavior, specified by the
Value. To learn how value classes affect copy operations, see Copying Objects.
Verify Test Passes Eventually
Create a test case for interactive testing.
import matlab.unittest.TestCase import matlab.unittest.constraints.Eventually import matlab.unittest.constraints.IsGreaterThan import matlab.unittest.constraints.IsLessThan testCase = TestCase.forInteractiveUse;
Verify that, within the timeout period, a call to
results in a value greater than 10 (seconds). The
Eventually constraint repeatedly calls
toc until either the constraint is satisfied or the
elapsed time exceeds the timeout period. Repeated calls to
toc result in the elapsed time since the last call to
tic testCase.verifyThat(@toc, Eventually(IsGreaterThan(10)))
Interactive verification passed.
The verification may take as long as 10 seconds for
to reach a passing value. If you issue the call to
and wait more than 10 seconds before issuing the
verifyThat command, the verification returns
toc already returns a value greater
Verify that, within the timeout period,
toc does not
return a negative value.
Interactive verification failed. --------------------- Framework Diagnostic: --------------------- Eventually failed. --> The constraint never passed with a timeout of 20 second(s). --> IsLessThan failed. --> The value must be less than the maximum value. Actual Value: 36.532254706346720 Maximum Value (Exclusive): 0 Evaluated Function: function_handle with value: @toc
This failure is expected since elapsed time is not going to be less than
for the duration of the timeout period.
Adjust the timeout period so
Eventually polls for 5
tic testCase.verifyThat(@toc, Eventually(IsGreaterThan(10), ... 'WithTimeoutOf', 5))
Interactive verification failed. --------------------- Framework Diagnostic: --------------------- Eventually failed. --> The constraint never passed with a timeout of 5 second(s). --> IsGreaterThan failed. --> The value must be greater than the minimum value. Actual Value: 5.143138452046230 Minimum Value (Exclusive): 10 Evaluated Function: function_handle with value: @toc
If you didn’t wait more than 5 seconds between calls to
verifyThat, the test fails
because the elapsed time is not greater than 10 seconds within the modified