@@ -346,31 +346,7 @@ def gzip_then_base64_encode(s: str) -> str:
346
346
instance .terminate ()
347
347
raise TimeoutError ("init.sh failed to complete within the timeout period" )
348
348
349
- < << << << HEAD
350
349
def is_healthy (ssh ) -> bool :
351
- == == == =
352
- # Check PostgreSQL logs directory
353
- logger .info ("Checking PostgreSQL logs directory:" )
354
- result = host .run ("sudo ls -la /var/log/postgresql/" )
355
- logger .info (f"log directory contents:\n { result .stdout } \n { result .stderr } " )
356
-
357
- # Check any existing PostgreSQL logs
358
- logger .info ("Checking existing PostgreSQL logs:" )
359
- result = host .run ("sudo cat /var/log/postgresql/*.log" )
360
- logger .info (f"postgresql logs:\n { result .stdout } \n { result .stderr } " )
361
-
362
- # Check the startup log
363
- logger .info ("PostgreSQL startup log:" )
364
- result = host .run (f"sudo cat { startup_log } " )
365
- logger .info (f"startup log contents:\n { result .stdout } \n { result .stderr } " )
366
-
367
- # Check PostgreSQL environment
368
- logger .info ("PostgreSQL environment:" )
369
- result = host .run ("sudo -u postgres env | grep POSTGRES" )
370
- logger .info (f"postgres environment:\n { result .stdout } \n { result .stderr } " )
371
-
372
- def is_healthy (host , instance_ip , ssh_identity_file ) - > bool :
373
- >> >> >> > c2631e8c (test : reorg and print logs while waiting continue on other checks when ready )
374
350
health_checks = [
375
351
("postgres" , "sudo -u postgres /usr/bin/pg_isready -U postgres" ),
376
352
("adminapi" , f"curl -sf -k --connect-timeout 30 --max-time 60 https://localhost:8085/health -H 'apikey: { supabase_admin_key } '" ),
@@ -382,22 +358,16 @@ def is_healthy(host, instance_ip, ssh_identity_file) -> bool:
382
358
383
359
for service , command in health_checks :
384
360
try :
385
- << << << < HEAD
386
361
result = run_ssh_command (ssh , command )
387
362
if not result ['succeeded' ]:
388
363
logger .warning (f"{ service } not ready" )
389
364
logger .error (f"{ service } command failed with rc={ cmd .rc } " )
390
365
logger .error (f"{ service } stdout: { cmd .stdout } " )
391
366
logger .error (f"{ service } stderr: { cmd .stderr } " )
392
- == == == =
393
- if service == "postgres" :
394
- pg_isready = check (host )
395
- > >> >> >> 65 ef0692 (test : do not unpack result )
396
367
397
- # Always read and log the PostgreSQL logs first
368
+ # Always read and log the PostgreSQL logs
398
369
logger .warning ("PostgreSQL status check:" )
399
370
try :
400
- # Read both .log and .csv files
401
371
log_files = [
402
372
"/var/log/postgresql/*.log" ,
403
373
"/var/log/postgresql/*.csv"
@@ -415,33 +385,42 @@ def is_healthy(host, instance_ip, ssh_identity_file) -> bool:
415
385
except Exception as e :
416
386
logger .error (f"Error reading PostgreSQL logs: { str (e )} " )
417
387
418
- # Then check the status and return
419
- if not pg_isready .failed :
420
- continue
421
- # Wait before next attempt
422
- sleep (5 )
423
- return False
388
+ service_status [service ] = not pg_isready .failed
389
+
424
390
else :
425
391
cmd = check (host )
426
- if cmd .failed is True :
392
+ service_status [service ] = not cmd .failed
393
+ if cmd .failed :
427
394
logger .warning (f"{ service } not ready" )
428
395
logger .error (f"{ service } command failed with rc={ cmd .rc } " )
429
396
logger .error (f"{ service } stdout: { cmd .stdout } " )
430
397
logger .error (f"{ service } stderr: { cmd .stderr } " )
431
- return False
398
+
432
399
except Exception as e :
433
- logger .warning (
434
- f"Connection failed during { service } check, attempting reconnect..."
435
- )
400
+ logger .warning (f"Connection failed during { service } check, attempting reconnect..." )
436
401
logger .error (f"Error details: { str (e )} " )
437
402
host = get_ssh_connection (instance_ip , ssh_identity_file )
438
- return False
403
+ service_status [service ] = False
404
+
405
+ # Log overall status of all services
406
+ logger .info ("Service health status:" )
407
+ for service , healthy in service_status .items ():
408
+ logger .info (f"{ service } : { 'healthy' if healthy else 'unhealthy' } " )
409
+
410
+ # If any service is unhealthy, wait and return False with status
411
+ if not all (service_status .values ()):
412
+ if service_status .get ("postgres" , False ): # If postgres is healthy but others aren't
413
+ sleep (5 ) # Only wait if postgres is up but other services aren't
414
+ logger .warning ("Some services are not healthy, will retry..." )
415
+ return False , service_status
439
416
440
- return True
417
+ logger .info ("All services are healthy, proceeding to tests..." )
418
+ return True , service_status
441
419
442
420
while True :
443
421
if is_healthy (ssh ):
444
422
break
423
+ logger .warning (f"Health check failed, service status: { status } " )
445
424
sleep (1 )
446
425
447
426
# Return both the SSH connection and instance IP for use in tests
0 commit comments