Main Content

matlab.unittest.constraints.Eventually Class

Namespace: matlab.unittest.constraints
Superclasses: matlab.unittest.constraints.Constraint

Test if function asynchronously satisfies constraint

Description

The matlab.unittest.constraints.Eventually class provides a constraint that polls for a function handle to satisfy a given constraint within a timeout period.

The matlab.unittest.constraints.Eventually class is a handle class.

Creation

Description

example

c = matlab.unittest.constraints.Eventually(constraint) creates a constraint that polls for a function handle to satisfy constraint. The constraint c is satisfied if, within a timeout period of 20 seconds, the function handle produces a value that satisfies constraint.

The testing framework updates figures and processes any pending callbacks while Eventually waits for the function handle to satisfy constraint.

example

c = matlab.unittest.constraints.Eventually(constraint,"WithTimeoutOf",timeout) creates a constraint that polls for constraint to be satisfied within the specified timeout period.

Input Arguments

expand all

Constraint that must asynchronously be satisfied, specified as a matlab.unittest.constraints.Constraint object.

Timeout period in seconds, specified as a nonnegative numeric scalar.

This argument sets the Timeout property.

Data Types: double | single | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Properties

expand all

Last output produced by the function handle, returned as a value of any data type.

Attributes:

GetAccess
public
SetAccess
private

Timeout period in seconds, returned as a nonnegative numeric scalar.

This property is set by the timeout input argument.

Attributes:

GetAccess
public
SetAccess
immutable

Examples

collapse all

Test if a qualification eventually passes by using the Eventually constraint.

First, import the classes used in this example.

import matlab.unittest.TestCase
import matlab.unittest.constraints.Eventually
import matlab.unittest.constraints.IsGreaterThan
import matlab.unittest.constraints.IsLessThan

Create a test case for interactive testing.

testCase = TestCase.forInteractiveUse;

Verify that, within 20 seconds, a call to toc produces a value greater than 10 since the last call to tic. In this test, the Eventually constraint repeatedly calls toc until either the IsGreaterThan constraint is satisfied or the elapsed time exceeds the timeout period. If you call tic and then wait more than 10 seconds before calling verifyThat, the test immediately passes because toc already produces a value greater than 10.

tic
testCase.verifyThat(@toc,Eventually(IsGreaterThan(10)))
Verification passed.

Test if, within 20 seconds, toc produces a negative value. Even though the test fails because the elapsed time cannot be negative, Eventually polls toc for the duration of the timeout period.

testCase.verifyThat(@toc,Eventually(IsLessThan(0)))
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:
          45.073031200000003
        Maximum Value (Exclusive):
             0
    
    Evaluated Function:
      function_handle with value:
    
        @toc

Adjust the timeout period so Eventually polls for 5 seconds. If you do not wait more than 5 seconds between calls to tic and verifyThat, the test fails because the elapsed time is not greater than 10 seconds within the modified timeout period.

tic
testCase.verifyThat(@toc,Eventually(IsGreaterThan(10), ...
    "WithTimeoutOf",5))
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.068235800000000
        Minimum Value (Exclusive):
            10
    
    Evaluated Function:
      function_handle with value:
    
        @toc

Version History

Introduced in R2013a