-
-
Notifications
You must be signed in to change notification settings - Fork 65
Fix issue 24 #114
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
base: master
Are you sure you want to change the base?
Fix issue 24 #114
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -60,3 +60,60 @@ def test_complex(): | |||||
| sleep(1) | ||||||
| rq.stop() | ||||||
| rq.join() | ||||||
|
|
||||||
| def test_add_request_disk_full(): | ||||||
| """Ensures that add_request doesn't crash if the queue can't be written to disk""" | ||||||
| client = MockClient() | ||||||
| rq = RequestQueue(client) # type: ignore | ||||||
|
|
||||||
| def raise_oserror(*args, **kwargs): | ||||||
| raise OSError("No space left on device") | ||||||
|
|
||||||
| rq._persistqueue.put = raise_oserror # type: ignore | ||||||
|
|
||||||
| # Should not raise, the OSError should be caught internally and logged instead | ||||||
| rq.add_request("/api/0/buckets/test/heartbeat", {}) | ||||||
|
|
||||||
| def test_wait_for_queue_empty_basic(): | ||||||
| """Queue empties normally while connected and running.""" | ||||||
| client = MockClient() | ||||||
| rq = RequestQueue(client) # type: ignore | ||||||
| rq.start() | ||||||
|
|
||||||
| rq.add_request("/api/0/buckets/test/heartbeat", {}) | ||||||
| result = rq.wait_for_queue_empty(timeout=5) | ||||||
|
|
||||||
| rq.stop() | ||||||
| rq.join() | ||||||
| assert result is True | ||||||
|
|
||||||
|
|
||||||
| def test_wait_for_queue_empty_not_running(): | ||||||
| """Returns True immediately if the queue thread isn't running.""" | ||||||
| client = MockClient() | ||||||
| rq = RequestQueue(client) # type: ignore | ||||||
| # Thread never started, should return True instantly | ||||||
| result = rq.wait_for_queue_empty(timeout=5) | ||||||
| assert result is True | ||||||
|
|
||||||
|
|
||||||
| def test_wait_for_queue_empty_timeout(): | ||||||
| """Returns False if the queue doesn't empty before the timeout.""" | ||||||
| import unittest.mock as mock | ||||||
|
|
||||||
| client = MockClient() | ||||||
| rq = RequestQueue(client) # type: ignore | ||||||
|
|
||||||
| # Make _post block long enough that the queue won't empty before timeout | ||||||
| def slow_post(endpoint, data): | ||||||
| from time import sleep | ||||||
| sleep(10) | ||||||
|
|
||||||
| with mock.patch.object(client, "_post", slow_post): | ||||||
| rq.start() | ||||||
| rq.add_request("/api/0/buckets/test/heartbeat", {}) | ||||||
| result = rq.wait_for_queue_empty(timeout=0.5) | ||||||
| rq.stop() | ||||||
| rq.join() | ||||||
|
Comment on lines
+112
to
+117
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||
|
|
||||||
| assert result is False | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! |
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wait_for_queue_emptyspinning indefinitelyis_alive()is checked once at entry, but not inside the polling loop. If theRequestQueuethread dies unexpectedly (e.g., an unhandled exception propagates out ofrun()'s inner loops without setting_stop_event),self.wait(0.1)will keep returningFalseon timeout every 100 ms,qsize()and_currentwill never change, and any call withtimeout=Nonewill spin forever. Addingif not self.is_alive(): return Falseas the first check inside the loop would break out cleanly in that scenario.