Skip to content

Commit 999bcec

Browse files
author
root
committed
update test code
1 parent 13cc650 commit 999bcec

2 files changed

Lines changed: 8 additions & 9 deletions

File tree

kubesys/client.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
from typing import Union
22
from kubesys.common import getLastIndex,dictToJsonString,jsonStringToBytes,getParams,formatURL
3-
from requests import status_codes
4-
from requests.api import request
5-
from kubesys.http_request import createRequest,createRequestReturOriginal
3+
from kubesys.http_request import createRequest
64
from kubesys.analyzer import KubernetesAnalyzer
75
import requests
86
import json
@@ -275,10 +273,8 @@ def watchingBase(url,token,handlerFunction,kwargs):
275273

276274
jsonObj = jsonBytesToDict(json_bytes)
277275
handlerFunction(jsonObj=jsonObj)
278-
279-
print(KubernetesClient.getWatchThreadCount())
276+
280277
del KubernetesClient.watcher_threads[threading.currentThread().getName()]
281-
print(KubernetesClient.getWatchThreadCount())
282278

283279
def updateResourceStatus(self, jsonStr,**kwargs)->Union[dict,bool,str]:
284280
jsonObj = jsonStr

test.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ def test_CRUD(client):
5252
print("is OK: ", OK)
5353
print("HTTP status code: ", http_status_code,"\n")
5454

55-
time.sleep(5)
5655
# test delete pod
5756
print("--test delete pod:")
5857
response_dict,OK,http_status_code = client.deleteResource(kind="Pod", namespace="default", name="busybox")
@@ -69,7 +68,7 @@ def test_watcher(client,namespce,kind,name=None):
6968
def deal_watch(*args):
7069
def tt(jsonObj=None,args=args):
7170
print(dictToJsonString(jsonObj)[:20])
72-
71+
7372
return tt
7473

7574
def test_watcher_base(client,namespce,kind,name=None,handlerFunction=None,**kwargs):
@@ -83,9 +82,13 @@ def main():
8382
token = ""
8483

8584
client = KubernetesClient(url=url,token=token)
86-
test_watcher_base(client,"default","Pod",handlerFunction=deal_watch(),limit=1,timeoutSeconds=2)
85+
test_watcher_base(client,"default","Pod",handlerFunction=deal_watch(),timeoutSeconds=3)
8786
test_CRUD(client=client)
87+
88+
print("current thread count: ",KubernetesClient.getWatchThreadCount())
8889
time.sleep(7)
90+
# because of the timeoutSecond=3, watching thread is leave.
91+
print("current thread count: ",KubernetesClient.getWatchThreadCount())
8992

9093
if __name__ == '__main__':
9194
main()

0 commit comments

Comments
 (0)