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

Add a way to notify test code that all handers were executed #3

Closed
rominf opened this issue Mar 2, 2019 · 8 comments
Closed

Add a way to notify test code that all handers were executed #3

rominf opened this issue Mar 2, 2019 · 8 comments

Comments

@rominf
Copy link
Contributor

rominf commented Mar 2, 2019

Now we have code like this:

httpserver.expect_oneshot_request(...).respond_with_response(Response(status=200))                                                                             
# make request from external software, which doesn't expose responses to requests
wait_for_truthy(lambda: not httpserver.oneshot_handlers, description='all requests processed')
httpserver.check_assertions()

where wait_for_truthy is a function that periodically calls its first argument until either the result becomes True or a timeout occurs.
This solution is not very beautiful and fast. Do you have ideas about how to do this properly?

@csernazs
Copy link
Owner

csernazs commented Mar 2, 2019

Well, in this case I assume that the 3rd party software is doing the request in a separate thread or a process. Is that right?
So the problem is that we don't know when the processing finished. Would it be possible to wait for that thread (by joining to it) or to call wait() on that process which is making the requests?
Then you could safely check httpserver's status.

@rominf
Copy link
Contributor Author

rominf commented Mar 2, 2019

We are writing tests for our main product which is written in C++. The request is made in response to request that I'm sending to this program using requests. So, firstly, communication between Python and C++ application is not simple, secondly, we want to test it without knowing implementation details.

Do you have other proposals?

@rominf
Copy link
Contributor Author

rominf commented Mar 2, 2019

I propose to store threading.Event or threading.Condition instance in httpserver and set it in request handlers.

@rominf
Copy link
Contributor Author

rominf commented Mar 2, 2019

Also, it to would be great to combine it somehow with httpserver.check_assertions to fail as soon as the wrong request arrives.

@csernazs
Copy link
Owner

csernazs commented Mar 2, 2019

In Linux you can wait for an file descriptor, thread or process. If you don't have any of these, only the polling will remain, however if you are creating the thread or the process from python directly, I would still suggest waiting on that object (fd, thread, process).
Polling is the last resort. Of course it would work in httpserver as well (let's say in a wait() method) httpserver which would do very similar to your code, but only the waiting would be there, calling the assertions would be the responsibility of the caller.

@rominf
Copy link
Contributor Author

rominf commented Mar 2, 2019

What's wrong with the method I described in #3 (comment)? Will you accept my patch implementing this?

@csernazs
Copy link
Owner

csernazs commented Mar 2, 2019

If you have a patch for this, that would help me to understand your solution. I think I haven't understood fully what you need and that would help. I can't make any guarantee that the patch will be accepted but I'm ok with using threading events.

@csernazs
Copy link
Owner

csernazs commented Mar 2, 2019

I'll be off the grid for a few days, so don't expect timely response from me. I can get back to you mid next week.

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