title: Threads in Django Test Case are not closing DB Connections
body: <p>I am trying to test out that the code I put in place to prevent race conditions is working.</p>
  
  <p>In my test case I've started two threads and have them both call the code in question. The threads return normally but it seems that the postgres database connections remain open.</p>
  
  <p>I've reduced the entire test case to a very simple example where the problem shows up:</p>
  
  <pre><code>    def test_threading(self):
          obj = mommy.make(self.model_class)
  
          def test_concurrency():
              self.model_class.objects.get(id=obj.id)
  
          t1 = Thread(target=test_concurrency)
          t2 = Thread(target=test_concurrency)
  
          t1.start()
          t2.start()
  
          t1.join()
          t2.join()
  </code></pre>
  
  <p>After the test runs and the test database is being destroyed I get the following error:</p>
  
  <pre><code>psycopg2.errors.ObjectInUse: database "test_db" is being accessed by other users
  DETAIL:  There are 2 other sessions using the database.
  </code></pre>
  
  <p>I've tried manually closing the connections at the end of the test case by adding:</p>
  
  <pre><code>for conn in db.connections.all():
      conn.close()
  </code></pre>
  
  <p>But this doesn't seem to have any effect. </p>
  
  <p>I am using <code>django.test.TransactionTestCase</code> as my base TestCase class, <code>Django 2.2</code> and <code>PostgreSQL 10.6</code>.</p>