Skip to content

armgit / txtai

Public Imported from GitHub
0

💡 All-in-one AI framework for semantic search, LLM orchestration and language model workflows

Add test for API __del__ method

davidmezzetti07c2495952ec
diff --git a/src/python/txtai/api/base.py b/src/python/txtai/api/base.py
index 92ca8082..41f6b9e6 100644
--- a/src/python/txtai/api/base.py
+++ b/src/python/txtai/api/base.py
@@ -90,6 +90,7 @@ class API:
if self.pool:
self.pool.close()
+ self.pool = None
def pipes(self):
"""
diff --git a/test/python/testapi/testworkflow.py b/test/python/testapi/testworkflow.py
index ae9104c1..b36b9800 100644
--- a/test/python/testapi/testworkflow.py
+++ b/test/python/testapi/testworkflow.py
@@ -8,12 +8,13 @@ import tempfile
import unittest
from http.server import HTTPServer, BaseHTTPRequestHandler
+from multiprocessing.pool import ThreadPool
from threading import Thread
from unittest.mock import patch
from fastapi.testclient import TestClient
-from txtai.api import app, start
+from txtai.api import app, start, API
# Configuration for workflows
WORKFLOWS = """
@@ -175,6 +176,17 @@ class TestWorkflow(unittest.TestCase):
cls.httpd.shutdown()
+ def testAPICleanup(self):
+ """
+ Test API threadpool closed when __del__ called.
+ """
+
+ api = API({})
+ api.pool = ThreadPool()
+ api.__del__()
+
+ self.assertIsNone(api.pool)
+
def testServiceGet(self):
"""
Test workflow with ServiceTask GET via API