Blame SOURCES/python-requests-toolbelt-fix-unhandled-exception-from-tests.patch

b06f05
From c4f918572751151eb3bfc7dfa94580b3e2867a9e Mon Sep 17 00:00:00 2001
b06f05
From: Jon Dufresne <jon.dufresne@gmail.com>
b06f05
Date: Sun, 3 Feb 2019 09:02:24 -0800
b06f05
Subject: [PATCH] Fix unhandled exceptions from threads during tests
b06f05
b06f05
A queue.Queue() object was not always passed to SessionThread. In this
b06f05
case, SessionThread._make_request() would raise an exception trying to
b06f05
call methods on the expected object. Now, always pass a usable object to
b06f05
SessionThread.
b06f05
b06f05
Previously appeared as:
b06f05
b06f05
    Traceback (most recent call last):
b06f05
      File "/usr/lib64/python3.7/threading.py", line 917, in _bootstrap_inner
b06f05
        self.run()
b06f05
      File "/usr/lib64/python3.7/threading.py", line 865, in run
b06f05
        self._target(*self._args, **self._kwargs)
b06f05
      File "toolbelt/requests_toolbelt/threaded/thread.py", line 41, in _make_request
b06f05
        kwargs = self._jobs.get_nowait()
b06f05
    AttributeError: 'NoneType' object has no attribute 'get_nowait'
b06f05
b06f05
    Exception in thread cd08fad6-d21d-41b0-921e-737a149b12be:
b06f05
    Traceback (most recent call last):
b06f05
      File "/usr/lib64/python3.7/threading.py", line 917, in _bootstrap_inner
b06f05
        self.run()
b06f05
      File "/usr/lib64/python3.7/threading.py", line 865, in run
b06f05
        self._target(*self._args, **self._kwargs)
b06f05
      File "toolbelt/requests_toolbelt/threaded/thread.py", line 41, in _make_request
b06f05
        kwargs = self._jobs.get_nowait()
b06f05
    AttributeError: 'NoneType' object has no attribute 'get_nowait'
b06f05
b06f05
    Exception in thread 4fb72f0d-ba1c-4a78-97a2-4a7283ea01fe:
b06f05
    Traceback (most recent call last):
b06f05
      File "/usr/lib64/python3.7/threading.py", line 917, in _bootstrap_inner
b06f05
        self.run()
b06f05
      File "/usr/lib64/python3.7/threading.py", line 865, in run
b06f05
        self._target(*self._args, **self._kwargs)
b06f05
      File "toolbelt/requests_toolbelt/threaded/thread.py", line 41, in _make_request
b06f05
        kwargs = self._jobs.get_nowait()
b06f05
    AttributeError: 'NoneType' object has no attribute 'get_nowait'
b06f05
b06f05
    Exception in thread 5f3711af-0c01-4821-9e25-8074bbbf769b:
b06f05
    Traceback (most recent call last):
b06f05
      File "/usr/lib64/python3.7/threading.py", line 917, in _bootstrap_inner
b06f05
        self.run()
b06f05
      File "/usr/lib64/python3.7/threading.py", line 865, in run
b06f05
        self._target(*self._args, **self._kwargs)
b06f05
      File "toolbelt/requests_toolbelt/threaded/thread.py", line 41, in _make_request
b06f05
        kwargs = self._jobs.get_nowait()
b06f05
    AttributeError: 'NoneType' object has no attribute 'get_nowait'
b06f05
b06f05
https://github.com/requests/toolbelt/commit/c4f918572751151eb3bfc7dfa94580b3e2867a9e
b06f05
---
b06f05
 tests/threaded/test_pool.py   | 15 ++++++++++-----
b06f05
 tests/threaded/test_thread.py |  5 ++++-
b06f05
 2 files changed, 14 insertions(+), 6 deletions(-)
b06f05
b06f05
diff --git a/tests/threaded/test_pool.py b/tests/threaded/test_pool.py
b06f05
index b0653bb..b949dd8 100644
b06f05
--- a/tests/threaded/test_pool.py
b06f05
+++ b/tests/threaded/test_pool.py
b06f05
@@ -26,32 +26,37 @@ def test_requires_positive_number_of_processes(self):
b06f05
 
b06f05
     def test_number_of_processes_can_be_arbitrary(self):
b06f05
         """Show that the number of processes can be set."""
b06f05
-        p = pool.Pool(None, num_processes=100)
b06f05
+        job_queue = queue.Queue()
b06f05
+        p = pool.Pool(job_queue, num_processes=100)
b06f05
         assert p._processes == 100
b06f05
         assert len(p._pool) == 100
b06f05
 
b06f05
-        p = pool.Pool(None, num_processes=1)
b06f05
+        job_queue = queue.Queue()
b06f05
+        p = pool.Pool(job_queue, num_processes=1)
b06f05
         assert p._processes == 1
b06f05
         assert len(p._pool) == 1
b06f05
 
b06f05
     def test_initializer_is_called(self):
b06f05
         """Ensure that the initializer function is called."""
b06f05
+        job_queue = queue.Queue()
b06f05
         initializer = mock.MagicMock()
b06f05
-        pool.Pool(None, num_processes=1, initializer=initializer)
b06f05
+        pool.Pool(job_queue, num_processes=1, initializer=initializer)
b06f05
         assert initializer.called is True
b06f05
         initializer.assert_called_once_with(mock.ANY)
b06f05
 
b06f05
     def test_auth_generator_is_called(self):
b06f05
         """Ensure that the auth_generator function is called."""
b06f05
+        job_queue = queue.Queue()
b06f05
         auth_generator = mock.MagicMock()
b06f05
-        pool.Pool(None, num_processes=1, auth_generator=auth_generator)
b06f05
+        pool.Pool(job_queue, num_processes=1, auth_generator=auth_generator)
b06f05
         assert auth_generator.called is True
b06f05
         auth_generator.assert_called_once_with(mock.ANY)
b06f05
 
b06f05
     def test_session_is_called(self):
b06f05
         """Ensure that the session function is called."""
b06f05
+        job_queue = queue.Queue()
b06f05
         session = mock.MagicMock()
b06f05
-        pool.Pool(None, num_processes=1, session=session)
b06f05
+        pool.Pool(job_queue, num_processes=1, session=session)
b06f05
         assert session.called is True
b06f05
         session.assert_called_once_with()
b06f05
 
b06f05
diff --git a/tests/threaded/test_thread.py b/tests/threaded/test_thread.py
b06f05
index bb92f7f..fd7e96b 100644
b06f05
--- a/tests/threaded/test_thread.py
b06f05
+++ b/tests/threaded/test_thread.py
b06f05
@@ -19,6 +19,8 @@ def _make_mocks():
b06f05
 
b06f05
 def _initialize_a_session_thread(session=None, job_queue=None,
b06f05
                                  response_queue=None, exception_queue=None):
b06f05
+    if job_queue is None:
b06f05
+        job_queue = queue.Queue()
b06f05
     with mock.patch.object(threading, 'Thread') as Thread:
b06f05
         thread_instance = mock.MagicMock()
b06f05
         Thread.return_value = thread_instance
b06f05
@@ -52,10 +54,11 @@ def test_thread_initialization(self):
b06f05
 
b06f05
     def test_is_alive_proxies_to_worker(self):
b06f05
         """Test that we proxy the is_alive method to the Thread."""
b06f05
+        job_queue = queue.Queue()
b06f05
         with mock.patch.object(threading, 'Thread') as Thread:
b06f05
             thread_instance = mock.MagicMock()
b06f05
             Thread.return_value = thread_instance
b06f05
-            st = thread.SessionThread(None, None, None, None)
b06f05
+            st = thread.SessionThread(None, job_queue, None, None)
b06f05
 
b06f05
         st.is_alive()
b06f05
         thread_instance.is_alive.assert_called_once_with()