From 8025df5fe39fe4df25bbf1880f8f4adb5d6d2402 Mon Sep 17 00:00:00 2001
From: Trenton H <holmes.trenton@gmail.com>
Date: Mon, 10 Oct 2022 14:21:42 -0700
Subject: [PATCH] Catch the new error raised by redis when it can't find the
 broker and stub out the call for testing

---
 src/documents/tasks.py               | 8 +++-----
 src/documents/tests/test_barcodes.py | 9 ++++++---
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/src/documents/tasks.py b/src/documents/tasks.py
index d41b19b51..667c3d9df 100644
--- a/src/documents/tasks.py
+++ b/src/documents/tasks.py
@@ -31,6 +31,7 @@ from documents.parsers import DocumentParser
 from documents.parsers import get_parser_class_for_mime_type
 from documents.sanity_checker import SanityCheckFailedException
 from filelock import FileLock
+from redis.exceptions import ConnectionError
 from whoosh.writing import AsyncWriter
 
 
@@ -157,11 +158,8 @@ def consume_file(
                         "status_updates",
                         {"type": "status_update", "data": payload},
                     )
-                except OSError as e:
-                    logger.warning(
-                        "OSError. It could be, the broker cannot be reached.",
-                    )
-                    logger.warning(str(e))
+                except ConnectionError as e:
+                    logger.warning(f"ConnectionError on status send: {str(e)}")
                 # consuming stops here, since the original document with
                 # the barcodes has been split and will be consumed separately
                 return "File successfully split"
diff --git a/src/documents/tests/test_barcodes.py b/src/documents/tests/test_barcodes.py
index c58596a1f..5de475578 100644
--- a/src/documents/tests/test_barcodes.py
+++ b/src/documents/tests/test_barcodes.py
@@ -397,7 +397,8 @@ class TestBarcode(DirectoriesMixin, TestCase):
         dst = os.path.join(settings.SCRATCH_DIR, "patch-code-t-middle.pdf")
         shutil.copy(test_file, dst)
 
-        self.assertEqual(tasks.consume_file(dst), "File successfully split")
+        with mock.patch("documents.tasks.async_to_sync"):
+            self.assertEqual(tasks.consume_file(dst), "File successfully split")
 
     @override_settings(
         CONSUMER_ENABLE_BARCODES=True,
@@ -411,7 +412,8 @@ class TestBarcode(DirectoriesMixin, TestCase):
         dst = os.path.join(settings.SCRATCH_DIR, "patch-code-t-middle.tiff")
         shutil.copy(test_file, dst)
 
-        self.assertEqual(tasks.consume_file(dst), "File successfully split")
+        with mock.patch("documents.tasks.async_to_sync"):
+            self.assertEqual(tasks.consume_file(dst), "File successfully split")
 
     @override_settings(
         CONSUMER_ENABLE_BARCODES=True,
@@ -465,4 +467,5 @@ class TestBarcode(DirectoriesMixin, TestCase):
         dst = os.path.join(settings.SCRATCH_DIR, "patch-code-t-middle")
         shutil.copy(test_file, dst)
 
-        self.assertEqual(tasks.consume_file(dst), "File successfully split")
+        with mock.patch("documents.tasks.async_to_sync"):
+            self.assertEqual(tasks.consume_file(dst), "File successfully split")