Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Instead of just checking that a particular thread is finished or not, why not create a fake <code>Foo</code> to be invoked by your wrapper in which the functions record the time at which they were actually started/completed. Then your yield thread need only wait long enough to be able to distinguish the difference between the recorded times. In your test you can assert that <code>another_func</code>'s start time is after <code>some_func</code>'s start time and it's completed time is before <code>some_func</code>s completed time. Since your fake class is only recording the times, this should be sufficient to guarantee that the wrapper class is working properly.</p> <p><strong>EDIT</strong>: You know, of course, that what your <code>Foo</code> object does could be an <a href="http://en.wikipedia.org/wiki/Anti-pattern" rel="nofollow noreferrer">anti-pattern</a>, namely <a href="http://en.wikipedia.org/wiki/Sequential_coupling" rel="nofollow noreferrer">Sequential Coupling</a>. Depending what it does, you may be able to handle it by simply having the second method do nothing if the first method has not yet been called. Using the example from the Sequential Coupling link, this would be similar to having the car do nothing when the accelerator pedal is pressed, if the car has not yet been started. If doing nothing is not appropriate, you could either wait and try again later, initiate the "start sequence" in the current thread, or handle it as an error. All of these things could be enforced by your wrapper as well and would probably be easier to test.</p> <p>You also may need to be careful to make sure that the same method doesn't get invoked twice in sequence if an intervening call to another method is required.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload