You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
I've written a small test that plays with Topology.step() method. The aim of the test is to check that N invocations of the method should yield N invocations of the onClock method of a ClockListener. Both assertions at the end of the test fail. Where do I make a mistake ?
import io.jbotsim.core.event.ClockListener;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class TopologyStepTest {
public static class CycleCounter implements ClockListener {
public int nbCycles = 0;
@Override
public void onClock() {
nbCycles++;
}
}
@Test
void test_Step() {
int N = 10;
Topology tp = new Topology();
CycleCounter cc = new CycleCounter();
tp.addClockListener(cc);
for (int r = 0; r < N; r++) {
tp.step();
}
assertEquals(N, cc.nbCycles);
assertFalse(tp.isRunning());
}
}
The text was updated successfully, but these errors were encountered:
My two cents with my understanding of the situation:
Since no Clock has been provided, the ClockManager spawns a DefaultClock.
This Clock's implementation is based on a simple Thread and conditions.
The step mechanism is basically " Call resume() while in step(), and pause() during the next Topology.onClock()" .
The clock thread simply does not have the time to wake up. Adding a System.sleep(500) to you loop "fixes" the test. Note: using a JClock won't help, here.
I suppose that the step mechanism has originally been added in a UI-oriented context, and not designed to handle strong thread competition without help from the developer?
Hi,
I've written a small test that plays with
Topology.step()
method. The aim of the test is to check thatN
invocations of the method should yieldN
invocations of theonClock
method of aClockListener
. Both assertions at the end of the test fail. Where do I make a mistake ?The text was updated successfully, but these errors were encountered: