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

Added request_interval feature to wait_for_successful_query module #53739

Closed
wants to merge 7 commits into from

Conversation

Oloremo
Copy link
Contributor

@Oloremo Oloremo commented Jul 6, 2019

What does this PR do?

Added request_interval kwargs to the http.wait_for_successful_query module to be aligned with the state.

What issues does this PR fix or reference?

#53738

Previous Behavior

request_interval was not supported in the http.wait_for_successful_query module

New Behavior

request_interval now supported in the http.wait_for_successful_query module

Tests written?

Yes

Commits signed with GPG?

Yes

@Oloremo Oloremo requested a review from a team as a code owner July 6, 2019 12:35
@ghost ghost requested a review from twangboy July 6, 2019 12:36
Copy link
Contributor

@gtmanfred gtmanfred left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small question

@@ -79,6 +79,10 @@ def wait_for_successful_query(url, wait_for=300, **kwargs):
raise caught_exception # pylint: disable=E0702

return result
else:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just put an elif here instead of else and then an if inside it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just copy-pasted this section from the state file. Keeping them the same sounds reasonable to me OR we could change them both...

@gtmanfred
Copy link
Contributor

gtmanfred commented Jul 6, 2019 via email

@Oloremo Oloremo force-pushed the http_request_interval branch from 9d4bf4b to 8946b08 Compare July 6, 2019 22:56
@Oloremo
Copy link
Contributor Author

Oloremo commented Jul 6, 2019

I would change both, I don't see a reason to not use elif.

done

@DmitryKuzmenko
Copy link
Contributor

@Oloremo, thank you for your patch.
The module unit test could be simply implemented by mocking the query function with return=[{'error': 'error'}, {}] and mock the time.sleep. Then call the wait_for_successful_query with request_interval set to a non-zero value and assert time.sleep mock called once with the value. Similar is for the state module test.

@Oloremo
Copy link
Contributor Author

Oloremo commented Jul 8, 2019

@DmitryKuzmenko I gave it a thought and still not sure how to implement it.
The main problem here is while True loop which could only be broken by the time check. And yet I need to pass the time check once to reach elif clause and check the logic but on a second iteration of the loop I need to break the loop somehow. And I have no idea how since if I mock time.time I'll never get out of the loop.

@DmitryKuzmenko
Copy link
Contributor

DmitryKuzmenko commented Jul 9, 2019

@Oloremo you don't need to mock time.time. If you're mocking query with MagicMock(return=[{'error': 'error'}, {}]) and time.sleep with MagicMock() you'll have the following:

    while True:
        caught_exception = None
        result = None
        try:
            result = query(url=url, **kwargs)
            # ITERATION 1: result = {'error': 'error'}
            # ITERATION 2: result = {}
            if not result.get('Error') and not result.get('error'):
                # ITERATION 2: returning the result
                return result
        except Exception as exc:
            caught_exception = exc

        if time.time() > starttime + wait_for:
            if not result and caught_exception:
                # workaround pylint bug https://www.logilab.org/ticket/3207
                raise caught_exception  # pylint: disable=E0702

            return result
        elif 'request_interval' in kwargs:
            # ITERATION 1: calling sleep
            # Space requests out by delaying for an interval
            time.sleep(kwargs['request_interval'])

It will exit on iteration 2 and called time.sleep once with the value of request_interval kwarg that you can check using the magic mock.

@Oloremo
Copy link
Contributor Author

Oloremo commented Jul 9, 2019

@DmitryKuzmenko

you don't need to mock time.time
It will exit on iteration 2

It won't unless we wait for wait_for with a minimum of 1 sec, and since we mock time.sleep() it could do a lot of loops during this one sec... Is it ok?

Or am I misunderstanding something?..

@Oloremo
Copy link
Contributor Author

Oloremo commented Jul 9, 2019

Oh wait, you're saying that in iteration 2 result = {} but how can I make different result for a second iteration if it's already mocked?

EDIT: Oh looks like I get it. MagicMock mocks the iterator with a list of results. Didn't know that, will try to implement!

@Oloremo Oloremo force-pushed the http_request_interval branch from 8946b08 to 6967470 Compare July 9, 2019 18:30
@Oloremo
Copy link
Contributor Author

Oloremo commented Jul 9, 2019

Test added. Please do check if they make sense.

@Oloremo
Copy link
Contributor Author

Oloremo commented Jul 10, 2019

Looks like failed jenkins/pr/py3-windows-2016 test has nothing to do with my changes. Not sure what to do here.

@Oloremo
Copy link
Contributor Author

Oloremo commented Jul 17, 2019

Now tests failing on boto stuff...

@waynew
Copy link
Contributor

waynew commented Jul 17, 2019

@Oloremo FWIW we've got an intense focus to stabilize our test suite/pipeline - you can feel free to investigate failures if you want to try to get this merged sooner, or alternatively after we've stabilized things it should be much easier to get merged in.

@Oloremo
Copy link
Contributor Author

Oloremo commented Jul 17, 2019

@waynew Well, I'd like to help but I have no idea how your CI works and have no idea what is wrong with the test I mentioned. :-(

@waynew
Copy link
Contributor

waynew commented Jul 25, 2019

We're running on Jenkins, using a tool called kitchen - you should be able to view most of the information available there if you click on the details of the builds.

If you check out the console logs, you can see the kitchen commands that we usually run. I don't have the time right now to put up some walkthroughs, unfortunately. If there are issues that crop up though, I'll do what I can - there's also the Salt community Slack and IRC where you might be able to find others who can assist.

@Oloremo
Copy link
Contributor Author

Oloremo commented Sep 13, 2019

re-run all

@Oloremo
Copy link
Contributor Author

Oloremo commented Sep 17, 2019

re-run full all

1 similar comment
@waynew
Copy link
Contributor

waynew commented Sep 17, 2019

re-run full all

@Oloremo
Copy link
Contributor Author

Oloremo commented Sep 17, 2019

it seems re-run is not working. :-)

@waynew
Copy link
Contributor

waynew commented Sep 17, 2019

I was thinking that it may not be active on this branch. If you rebase against 2018.3 and force push to your branch, that will re-run the tests... or something has gone terribly wrong 😛

@Oloremo Oloremo force-pushed the http_request_interval branch from 4de3411 to 2ef27ba Compare September 17, 2019 19:36
@Oloremo
Copy link
Contributor Author

Oloremo commented Sep 18, 2019

From a quick glance none of failed test related to the change. No idea how to pass tests. :-(

@waynew
Copy link
Contributor

waynew commented Oct 1, 2019

@Oloremo given the changes announced this morning, would you mind rebasing these changes against master and editing this PR to target master?

@Oloremo
Copy link
Contributor Author

Oloremo commented Oct 1, 2019

@waynew Sure, gimme a few days

@Oloremo Oloremo changed the base branch from 2018.3 to master October 7, 2019 20:20
@Oloremo Oloremo changed the base branch from master to 2018.3 October 7, 2019 20:21
@Oloremo
Copy link
Contributor Author

Oloremo commented Oct 7, 2019

deprecated by #54916

@Oloremo Oloremo closed this Oct 7, 2019
@Oloremo Oloremo deleted the http_request_interval branch November 7, 2019 23:09
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

Successfully merging this pull request may close these issues.

5 participants