Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wait For will error if timeout is too small #60

Open
damies13 opened this issue Feb 25, 2022 · 6 comments
Open

Wait For will error if timeout is too small #60

damies13 opened this issue Feb 25, 2022 · 6 comments

Comments

@damies13
Copy link

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

@Tattoo
Copy link
Contributor

Tattoo commented Feb 25, 2022

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.

@damies13
Copy link
Author

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.

@Tattoo
Copy link
Contributor

Tattoo commented Feb 25, 2022

@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.

@damies13
Copy link
Author

damies13 commented Feb 26, 2022

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
Copy link
Author

damies13 commented Feb 26, 2022

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
Copy link
Author

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 added a commit to damies13/robotframework-imagehorizonlibrary that referenced this issue Feb 27, 2022
Fix for issue eficode#60

This fix ensures even if timeout is set to 0 (zero) locate is called at least once.
damies13 added a commit to damies13/robotframework-imagehorizonlibrary that referenced this issue Feb 27, 2022
Keywords that now have the optional timeout are:
- Click Image
- Click To The Above Of Image
- Click To The Below Of Image
- Click To The Left Of Image
- Click To The Right Of Image
- Copy From The Above Of
- Copy From The Below Of
- Copy From The Left Of
- Copy From The Right Of

The default timeout is 0 sec so there is no functional change from previous version unless a timeout is set, this does require  Pull request eficode#64 (fix for issue eficode#60) as a prerequisite for this change in order to work as expected. Please only merge after Pull request eficode#64
noubar added a commit to noubar/Robotframework-ImageLibrary that referenced this issue Oct 17, 2024
commit 9db931a
Author: Dave Amies <damies13@gmail.com>
Date:   Sun Feb 27 10:02:46 2022 +1000

    Fix for issue eficode#60

    Fix for issue eficode#60

    This fix ensures even if timeout is set to 0 (zero) locate is called at least once.
noubar added a commit to noubar/Robotframework-ImageLibrary that referenced this issue Oct 17, 2024
commit d95e646
Author: Dave Amies <damies13@gmail.com>
Date:   Sun Feb 27 13:23:14 2022 +1000

    Add timeout option to keywords - Issue eficode#61

    Keywords that now have the optional timeout are:
    - Click Image
    - Click To The Above Of Image
    - Click To The Below Of Image
    - Click To The Left Of Image
    - Click To The Right Of Image
    - Copy From The Above Of
    - Copy From The Below Of
    - Copy From The Left Of
    - Copy From The Right Of

    The default timeout is 0 sec so there is no functional change from previous version unless a timeout is set, this does require  Pull request eficode#64 (fix for issue eficode#60) as a prerequisite for this change in order to work as expected. Please only merge after Pull request eficode#64
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants