From dca79770515861bba96987bcfb98d594dd39e2c0 Mon Sep 17 00:00:00 2001
From: FemtosecondLaser <38204088+FemtosecondLaser@users.noreply.github.com>
Date: Sat, 20 Nov 2021 00:22:25 +0000
Subject: [PATCH 1/4] added timeout of async operations to integration test
 setup/teardown

---
 lbry/testcase.py | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/lbry/testcase.py b/lbry/testcase.py
index 1845eade4..a1ac3d2ee 100644
--- a/lbry/testcase.py
+++ b/lbry/testcase.py
@@ -132,17 +132,18 @@ class AsyncioTestCase(unittest.TestCase):
 
             with outcome.testPartExecutor(self):
                 self.setUp()
+                self.addTimeout()
                 self.loop.run_until_complete(self.asyncSetUp())
             if outcome.success:
                 outcome.expecting_failure = expecting_failure
                 with outcome.testPartExecutor(self, isTest=True):
                     maybe_coroutine = testMethod()
                     if asyncio.iscoroutine(maybe_coroutine):
-                        if self.TIMEOUT:
-                            self.loop.call_later(self.TIMEOUT, self.cancel)
+                        self.addTimeout()
                         self.loop.run_until_complete(maybe_coroutine)
                 outcome.expecting_failure = False
                 with outcome.testPartExecutor(self):
+                    self.addTimeout()
                     self.loop.run_until_complete(self.asyncTearDown())
                     self.tearDown()
 
@@ -190,6 +191,7 @@ class AsyncioTestCase(unittest.TestCase):
             with outcome.testPartExecutor(self):
                 maybe_coroutine = function(*args, **kwargs)
                 if asyncio.iscoroutine(maybe_coroutine):
+                    self.addTimeout()
                     self.loop.run_until_complete(maybe_coroutine)
 
     def cancel(self):
@@ -198,6 +200,10 @@ class AsyncioTestCase(unittest.TestCase):
                 task.print_stack()
                 task.cancel()
 
+    def addTimeout(self):
+        if self.TIMEOUT:
+            self.loop.call_later(self.TIMEOUT, self.cancel)
+
 
 class AdvanceTimeTestCase(AsyncioTestCase):
 

From e6c1dc251ea6a50d6174032e773b86e12fa0d883 Mon Sep 17 00:00:00 2001
From: FemtosecondLaser <38204088+FemtosecondLaser@users.noreply.github.com>
Date: Sat, 20 Nov 2021 00:47:46 +0000
Subject: [PATCH 2/4] changed addTimeout to add_timeout for lint compliance

---
 lbry/testcase.py | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/lbry/testcase.py b/lbry/testcase.py
index a1ac3d2ee..6ad0dcb13 100644
--- a/lbry/testcase.py
+++ b/lbry/testcase.py
@@ -132,18 +132,18 @@ class AsyncioTestCase(unittest.TestCase):
 
             with outcome.testPartExecutor(self):
                 self.setUp()
-                self.addTimeout()
+                self.add_timeout()
                 self.loop.run_until_complete(self.asyncSetUp())
             if outcome.success:
                 outcome.expecting_failure = expecting_failure
                 with outcome.testPartExecutor(self, isTest=True):
                     maybe_coroutine = testMethod()
                     if asyncio.iscoroutine(maybe_coroutine):
-                        self.addTimeout()
+                        self.add_timeout()
                         self.loop.run_until_complete(maybe_coroutine)
                 outcome.expecting_failure = False
                 with outcome.testPartExecutor(self):
-                    self.addTimeout()
+                    self.add_timeout()
                     self.loop.run_until_complete(self.asyncTearDown())
                     self.tearDown()
 
@@ -191,7 +191,7 @@ class AsyncioTestCase(unittest.TestCase):
             with outcome.testPartExecutor(self):
                 maybe_coroutine = function(*args, **kwargs)
                 if asyncio.iscoroutine(maybe_coroutine):
-                    self.addTimeout()
+                    self.add_timeout()
                     self.loop.run_until_complete(maybe_coroutine)
 
     def cancel(self):
@@ -200,7 +200,7 @@ class AsyncioTestCase(unittest.TestCase):
                 task.print_stack()
                 task.cancel()
 
-    def addTimeout(self):
+    def add_timeout(self):
         if self.TIMEOUT:
             self.loop.call_later(self.TIMEOUT, self.cancel)
 

From d4ebfdbc3cd5bac803f9357fb89319e5559a8f53 Mon Sep 17 00:00:00 2001
From: FemtosecondLaser <38204088+FemtosecondLaser@users.noreply.github.com>
Date: Mon, 29 Nov 2021 22:56:50 +0000
Subject: [PATCH 3/4] removed conditional check in add_timeout()

---
 lbry/testcase.py | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/lbry/testcase.py b/lbry/testcase.py
index 6ad0dcb13..9a8e8d72d 100644
--- a/lbry/testcase.py
+++ b/lbry/testcase.py
@@ -201,8 +201,7 @@ class AsyncioTestCase(unittest.TestCase):
                 task.cancel()
 
     def add_timeout(self):
-        if self.TIMEOUT:
-            self.loop.call_later(self.TIMEOUT, self.cancel)
+        self.loop.call_later(self.TIMEOUT, self.cancel)
 
 
 class AdvanceTimeTestCase(AsyncioTestCase):

From d69486fb6e1a95538515350b6d4fd80198e84c9c Mon Sep 17 00:00:00 2001
From: FemtosecondLaser <38204088+FemtosecondLaser@users.noreply.github.com>
Date: Tue, 30 Nov 2021 01:01:35 +0000
Subject: [PATCH 4/4] returned conditional check in add_timeout() as it was
 making test_node.py tests unhappy

---
 lbry/testcase.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lbry/testcase.py b/lbry/testcase.py
index 9a8e8d72d..6ad0dcb13 100644
--- a/lbry/testcase.py
+++ b/lbry/testcase.py
@@ -201,7 +201,8 @@ class AsyncioTestCase(unittest.TestCase):
                 task.cancel()
 
     def add_timeout(self):
-        self.loop.call_later(self.TIMEOUT, self.cancel)
+        if self.TIMEOUT:
+            self.loop.call_later(self.TIMEOUT, self.cancel)
 
 
 class AdvanceTimeTestCase(AsyncioTestCase):