Blob Blame History Raw
From cfd4861795ac7cc2fa2d28382b1464d9c09a3aac Mon Sep 17 00:00:00 2001
From: Chenxiong Qi <qcxhome@gmail.com>
Date: Mon, 14 Jun 2021 11:25:47 +0800
Subject: [PATCH 1/4] Fix issue 'Too many open files' for tests

The root problem is the HTTPretty is not reset properly.

I'm running Fedora 34, and `ulimit -n' reports 1024. This problem
happens after around 58% of tests run.

HTTPretty opens temporary file for the internal FakeSocketFile, and all
of such file descriptors are stored inside __internals__.temp_files.
HTTPretty.reset must be called to release those fds as well as other
internal used resources.

Meanwhile, HTTPretty provides a decorator httprettized, which also has
the pattern to have the following pair of calls when exiting the context:

    httpretty.disable()
    httpretty.reset()

This change ensures all the HTTPretty internal resources including the
created temporary files are released after every test method.

Signed-off-by: Chenxiong Qi <qcxhome@gmail.com>
---
 social_core/tests/backends/base.py    | 1 +
 social_core/tests/backends/open_id.py | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/social_core/tests/backends/base.py b/social_core/tests/backends/base.py
index 040c5b88..fe2b7aa0 100644
--- a/social_core/tests/backends/base.py
+++ b/social_core/tests/backends/base.py
@@ -42,6 +42,7 @@ class BaseBackendTest(unittest.TestCase):
 
     def tearDown(self):
         HTTPretty.disable()
+        HTTPretty.reset()
         self.backend = None
         self.strategy = None
         self.name = None
diff --git a/social_core/tests/backends/open_id.py b/social_core/tests/backends/open_id.py
index b3698b9b..830e05a6 100644
--- a/social_core/tests/backends/open_id.py
+++ b/social_core/tests/backends/open_id.py
@@ -13,7 +13,6 @@ from ..models import TestStorage, User, TestUserSocialAuth, \
 from ..strategy import TestStrategy
 from .base import BaseBackendTest
 
-
 sys.path.insert(0, '..')
 
 
@@ -69,6 +68,7 @@ class OpenIdTest(BaseBackendTest):
         TestNonce.reset_cache()
         TestAssociation.reset_cache()
         HTTPretty.disable()
+        HTTPretty.reset()
 
     def get_form_data(self, html):
         parser = FormHTMLParser()
-- 
2.31.1