Open fwolter opened 3 years ago
You could use waitForAssertion(() -> ...) provided from the JavaTest class instead of the sleeps, which are error prone and depend on the load of the build machine.
Thanks for the hint. I will have a closer look at it next weekend.
@fwolter I had a look into the implementation of waitForAssertion(), but I am not sure that it can be used to replace the sleep calls completely.
In the first part of the test, a double press is simulated and the sleep() is used to have a small interval between two short press events. If I replaced the sleep() with waitForAssert there would be no sleep before the first test.
The second sleep() is necessary because a short press should be detected as a single press and not a double press. Therefore it needs a longer pause, and this won't work with waitForAssert().
But since the problem occurs in the first part of the test, we could try to see if the problem can be solved this way.
After looking into this test for a few minutes, I don't understand what happens there really. In any case there's something fishy about the sleep in the "mock". Seems to me some state is reset after some time. This could be done manually in the test as it seems the sleep in the mock is the only concurrent operation in the unit test. So, if you replace the sleep in the mock by an external manual reset, the sleep in the tests might be removed, too.
I'd consider waiting for assertions in unit tests a hack, tough. Often that means you also test some scheduler along with your code, which shouldn't be your intention when writing unit tests.
I agree with you and I have the same problem to understand why it is implemented this way. In my opinion the whole test does not make sense.
See https://ci.openhab.org/job/PR-openHAB-Addons/org.openhab.addons.bundles$org.openhab.binding.homematic/4245/testReport/org.openhab.binding.homematic.internal.communicator.virtual/ButtonDatapointTest/testDoublePress/
@FStolte @gerrieg @mdicke2s Can you take a look?