Skip to content

Commit

Permalink
Cherry pick test for API client context manager
Browse files Browse the repository at this point in the history
The implementation and tests were already picked up by the upstream OpenAPI
generator [here](OpenAPITools/openapi-generator#5094).
Patching in the tests here for correctness and clarity.

Reference: kubernetes-client#1073

Signed-off-by: Nabarun Pal <pal.nabarun95@gmail.com>
  • Loading branch information
palnabarun committed Jun 22, 2020
1 parent 228a29a commit 8ba0d71
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions kubernetes/test/test_api_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# coding: utf-8


import atexit
import weakref
import unittest

import kubernetes


class TestApiClient(unittest.TestCase):

def test_context_manager_closes_threadpool(self):
with kubernetes.client.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 = kubernetes.client.ApiClient()
self.assertIsNotNone(client.pool)
self.assertIsNotNone(client._pool)
atexit._run_exitfuncs()
self.assertIsNone(client._pool)

0 comments on commit 8ba0d71

Please sign in to comment.