black shift

This commit is contained in:
2025-04-22 11:10:29 +03:00
parent d7f1da8de8
commit e5f88f2eb4
30 changed files with 671 additions and 521 deletions

View File

@@ -478,46 +478,48 @@ def run_simple_concurrent_test(num_threads=10):
import time
import random
from concurrent.futures import ThreadPoolExecutor
print(f"\nStarting simple concurrent test with {num_threads} threads...")
# Results tracking
results = {"passed": 0, "failed": 0, "errors": []}
results_lock = threading.Lock()
def worker(thread_id):
try:
# Simple query to test connection pooling
with EndpointRestriction.new_session() as db_session:
# Just run a simple count query
count_query = db_session.query(EndpointRestriction).count()
# Small delay to simulate work
time.sleep(random.uniform(0.01, 0.05))
# Simple success criteria
success = count_query >= 0
# Update results with thread safety
with results_lock:
if success:
results["passed"] += 1
else:
results["failed"] += 1
results["errors"].append(f"Thread {thread_id} failed to get count")
results["errors"].append(
f"Thread {thread_id} failed to get count"
)
except Exception as e:
with results_lock:
results["failed"] += 1
results["errors"].append(f"Thread {thread_id} exception: {str(e)}")
# Create and start threads using a thread pool
start_time = time.time()
with ThreadPoolExecutor(max_workers=num_threads) as executor:
futures = [executor.submit(worker, i) for i in range(num_threads)]
# Calculate execution time
execution_time = time.time() - start_time
# Print results
print(f"\nConcurrent Operation Test Results:")
print(f"Total threads: {num_threads}")
@@ -525,21 +527,23 @@ def run_simple_concurrent_test(num_threads=10):
print(f"Failed: {results['failed']}")
print(f"Execution time: {execution_time:.2f} seconds")
print(f"Operations per second: {num_threads / execution_time:.2f}")
if results["failed"] > 0:
print("\nErrors:")
for error in results["errors"][:10]: # Show only first 10 errors to avoid flooding output
for error in results["errors"][
:10
]: # Show only first 10 errors to avoid flooding output
print(f"- {error}")
if len(results["errors"]) > 10:
print(f"- ... and {len(results['errors']) - 10} more errors")
return results["failed"] == 0
if __name__ == "__main__":
generate_table_in_postgres()
passed, failed = run_all_tests()
# If all tests pass, run the simple concurrent test
if failed == 0:
run_simple_concurrent_test(100)