robotframework-imagehorizonlibrary icon indicating copy to clipboard operation
robotframework-imagehorizonlibrary copied to clipboard

Wait For will error if timeout is too small

Open damies13 opened this issue 3 years ago • 6 comments
trafficstars

I was looking at the code for the wait_for function and I believe that if the timeout is too small this function will always error.

If the timeout is 0 then the while loop will not be entered and self._locate will never be called, therefore location will remain none and ImageNotFoundException will be called, i'm not sure how big timeout would have to be to prevent this happening and I suspect a small timeout of 0.01 would be enough to allow the while loop to be entered at least once.

https://github.com/eficode/robotframework-imagehorizonlibrary/blob/master/src/ImageHorizonLibrary/recognition/_recognize_images.py#L247

damies13 avatar Feb 25 '22 12:02 damies13

Hi @damies13 ,

Yes, your analysis is correct, however the default timeout is 10 seconds (as set in the method definition).

This means for timeout to be zero, user needs to explicitly set it so and in the sense, we don't consider the behavior incorrect.

Tattoo avatar Feb 25 '22 13:02 Tattoo

I understand and agree it's not a major issue, the only reason I raised it is because it would make implementing feature suggestion #61 a lot easier.

damies13 avatar Feb 25 '22 13:02 damies13

@damies13 ,

Ok, now I wrapped my head around the bigger point behind these two issues :) Your comment really illuminated the situation

I think your plan is solid: make so that one can pass 0 to the wait_for and it actually runs the loop once. Quickly looking, it seems to only require changing < => <=.

I have a note about #61, but I'll comment there about that

I'm currently bit busy for at least a month so contributions if you have time are more than welcome :) Reviewing & releasing I can do in timely manner.

Tattoo avatar Feb 25 '22 13:02 Tattoo

My before test: Screen Shot 2022-02-27 at 9 28 53 am

@Tattoo In this line is there a reason for forcing timeout to an integer when time() returns a float to 6 decimal places?

       stop_time = time() + int(timeout)

FYI - I have seen application performance SLA's that require for certain functions the application responds within 1/2 second (500ms) or 300ms, so I'm thinking to remove the int() and allow decimal values. The alternative is we should place int around time() on this line and 247.

>>> from time import time
>>> time()
1645917976.066547
>>> 

damies13 avatar Feb 26 '22 23:02 damies13

Never mind I see now why the limit at 1 sec, it takes ~800-900ms to identify the image, so it would never be able to be accurate down to 100ms precision anyway.

Screen Shot 2022-02-27 at 9 53 01 am

damies13 avatar Feb 26 '22 23:02 damies13

Ok I wrapped int() around both time() calls and the timeout value, and like this it will pass even with a 0 sec timeout. I will submit this fix soon. Screen Shot 2022-02-27 at 9 56 42 am

damies13 avatar Feb 26 '22 23:02 damies13