'Ensure that a connection that is not explicitly shareable cannot be
closed by another thread.
Refs #17258.'

def test_closing_non_shared_connections(self):

    exceptions = set()
    def runner1():
        def runner2(other_thread_connection):
            try:
                other_thread_connection.close()
            except DatabaseError as e:
                exceptions.add(e)
        t2 = threading.Thread(target=runner2, args=[connections[u'default']])
        t2.start()
        t2.join()
    t1 = threading.Thread(target=runner1)
    t1.start()
    t1.join()
    self.assertEqual(len(exceptions), 1)
    exceptions = set()
    def runner1():
        def runner2(other_thread_connection):
            try:
                other_thread_connection.close()
            except DatabaseError as e:
                exceptions.add(e)
        connections[u'default'].allow_thread_sharing = True
        t2 = threading.Thread(target=runner2, args=[connections[u'default']])
        t2.start()
        t2.join()
    t1 = threading.Thread(target=runner1)
    t1.start()
    t1.join()
    self.assertEqual(len(exceptions), 0)
