Testing code that is executed when solve reaches non-optimal status

I’m looking for advice on the best way to test code that is executed only when the termination status for optimization returns a status of MathOptInterface.TIME_LIMIT.

The first approach I tried was to construct models that are difficult to deal with for the optimizer (but easy to understand for the human tester) and setting a short time limit (seconds => 1 with Cbc) to try to cause MathOptInterface.TIME_LIMIT to be hit. I haven’t had much success as the solver heuristics seem quite good.

I’ve also considered mocking the function call to JuMP.termination_status via (https://github.com/invenia/Mocking.jl or https://github.com/burrowsa/Fixtures.jl).

Is there any option I’m missing?

1 Like

Do you need the solver to have found a feasible solution before hitting the time limit?
If not, you can always set a time limit of 0s.

1 Like

Another approach is if you structure your code so that those actions are performed by a separate function which you just feed the right input in the test.


Look at MockOptimizer in MOI and how it’s used in JuMP:

1 Like