Factor Studios commited on
Commit
72acfcf
·
verified ·
1 Parent(s): 419f8a6

Update test_ai_integration_http.py

Browse files
Files changed (1) hide show
  1. test_ai_integration_http.py +25 -13
test_ai_integration_http.py CHANGED
@@ -30,25 +30,38 @@ def http_storage_manager(max_retries=5, retry_delay=2, timeout=30.0):
30
 
31
  def try_connect():
32
  nonlocal storage
33
- if storage:
34
- try:
35
  if storage.is_connected():
36
- return True
 
 
37
  storage.close()
38
- except:
39
- pass
40
- storage = HTTPGPUStorage() # Create storage instance with default configuration
41
- return storage._create_session()
 
 
 
 
 
 
 
 
 
42
 
43
  # Initial connection with improved error handling
44
  for attempt in range(max_retries):
45
  try:
46
  if try_connect():
47
  logging.info("Successfully connected to GPU storage server via HTTP")
48
- # Test connection by making a simple request
49
- status = storage.get_connection_status()
50
- if status["connected"]:
51
- break
 
 
52
  logging.warning("Connection established but not responsive")
53
  else:
54
  logging.warning(f"HTTP connection attempt {attempt + 1} failed, retrying in {retry_delay}s...")
@@ -65,7 +78,6 @@ def http_storage_manager(max_retries=5, retry_delay=2, timeout=30.0):
65
  raise RuntimeError(error_msg)
66
 
67
  try:
68
- # Yield the storage connection
69
  yield storage
70
  except Exception as e:
71
  logging.error(f"HTTP operation failed: {e}")
@@ -176,7 +188,7 @@ def test_ai_integration_http():
176
  model_data = {
177
  "model_name": model_id,
178
  "model_type": "florence-2-large",
179
- "parameters": 771000000, # Approximate parameter count
180
  "architecture": "vision-language",
181
  "loaded_at": time.time()
182
  }
 
30
 
31
  def try_connect():
32
  nonlocal storage
33
+ try:
34
+ if storage:
35
  if storage.is_connected():
36
+ # Verify session is active
37
+ if storage.session_token is not None:
38
+ return True
39
  storage.close()
40
+
41
+ # Create new storage instance
42
+ storage = HTTPGPUStorage()
43
+
44
+ # Initialize session
45
+ if storage._create_session():
46
+ # Verify session was created
47
+ if storage.session_token is not None and not storage._closing:
48
+ return True
49
+ return False
50
+ except Exception as e:
51
+ logging.error(f"Connection error: {e}")
52
+ return False
53
 
54
  # Initial connection with improved error handling
55
  for attempt in range(max_retries):
56
  try:
57
  if try_connect():
58
  logging.info("Successfully connected to GPU storage server via HTTP")
59
+ # Verify the connection is active
60
+ if storage.is_connected():
61
+ # Test the connection with a basic operation
62
+ test_key = "_connection_test"
63
+ if storage.cache_data(test_key, {"test": True}):
64
+ break
65
  logging.warning("Connection established but not responsive")
66
  else:
67
  logging.warning(f"HTTP connection attempt {attempt + 1} failed, retrying in {retry_delay}s...")
 
78
  raise RuntimeError(error_msg)
79
 
80
  try:
 
81
  yield storage
82
  except Exception as e:
83
  logging.error(f"HTTP operation failed: {e}")
 
188
  model_data = {
189
  "model_name": model_id,
190
  "model_type": "florence-2-large",
191
+ "parameters": 771000000,
192
  "architecture": "vision-language",
193
  "loaded_at": time.time()
194
  }