lava icon indicating copy to clipboard operation
lava copied to clipboard

Unit tests for `probe()` of PyInPorts have a non-deterministic component

Open gkarray opened this issue 4 years ago • 0 comments

Given the nature of probe method of PyInPort, the unit test for it was written in the following manner :

...

recv_py_port.start()
send_py_port_1.start()
send_py_port_2.start()

# Send data through first PyOutPort
send_py_port_1.send(data)
# Send data through second PyOutPort
send_py_port_2.send(data)
# Sleep to let message reach the PyInPort
time.sleep(0.001)
# Probe PyInPort
probe_value = recv_py_port.probe()

# probe_value should be True if message reached the PyInPort
self.assertTrue(probe_value)

...

In other words, data is sent through some OutPorts, time.sleep() is called for 0.001 seconds to give some time for data to reach the InPort, then, probe() is executed to check if data reached it.

This is non-deterministic, as there are cases where 0.001 seconds is not enough for data to reach the InPort.

One possible fix would be to increase the time for which to sleep (to 0.1 seconds or more ?) to reduce chances of such scenarios happening. This doesn't seem adequate however, as it theoretically doesn't actually get rid of the non-determinism. It just reduces the chances for it to happen.

Given that use of non-deterministic components will increase as soon as AsyncProtocol is supported, might it not be preferable to have a well-defined methodology for unit testing those ?

gkarray avatar Nov 29 '21 14:11 gkarray