Skip to content

Commit

Permalink
Test to ensure threadpool is cleaned up
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianvf committed Jan 23, 2020
1 parent a2e3676 commit 6880e3f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

import os
import time
import atexit
import weakref
import unittest
from dateutil.parser import parse

Expand Down Expand Up @@ -199,3 +201,17 @@ def test_sanitize_for_serialization(self):
model = petstore_api.StringBooleanMap(**model_dict)
result = self.api_client.sanitize_for_serialization(model)
self.assertEqual(result, model_dict)

def test_context_manager_closes_threadpool(self):
with petstore_api.ApiClient() as client:
self.assertIsNotNone(client.pool)
pool_ref = weakref.ref(client._pool)
self.assertIsNotNone(pool_ref())
self.assertIsNone(pool_ref())

def test_atexit_closes_threadpool(self):
client = petstore_api.ApiClient()
self.assertIsNotNone(client.pool)
self.assertIsNotNone(client._pool)
atexit._run_exitfuncs()
self.assertIsNone(client._pool)
16 changes: 16 additions & 0 deletions samples/client/petstore/python/tests/test_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

import os
import time
import atexit
import weakref
import unittest
from dateutil.parser import parse

Expand Down Expand Up @@ -169,3 +171,17 @@ def test_sanitize_for_serialization(self):
data = [pet]
result = self.api_client.sanitize_for_serialization(data)
self.assertEqual(result, list_of_pet_dict)

def test_context_manager_closes_threadpool(self):
with petstore_api.ApiClient() as client:
self.assertIsNotNone(client.pool)
pool_ref = weakref.ref(client._pool)
self.assertIsNotNone(pool_ref())
self.assertIsNone(pool_ref())

def test_atexit_closes_threadpool(self):
client = petstore_api.ApiClient()
self.assertIsNotNone(client.pool)
self.assertIsNotNone(client._pool)
atexit._run_exitfuncs()
self.assertIsNone(client._pool)

0 comments on commit 6880e3f

Please sign in to comment.