Skip to content

Commit 5c68827

Browse files
authored
Alembic Migration Testing Suite supports #252 (#827)
* Add migration testing Signed-off-by: Mihai Criveti <[email protected]> * Add migration testing Signed-off-by: Mihai Criveti <[email protected]> --------- Signed-off-by: Mihai Criveti <[email protected]>
1 parent 5d7cfca commit 5c68827

21 files changed

+7802
-1
lines changed

Makefile

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4468,3 +4468,133 @@ fuzz-clean: ## 🧹 Clean fuzzing artifacts
44684468

44694469
fuzz-all: fuzz-hypothesis fuzz-atheris fuzz-api fuzz-security fuzz-report ## 🎯 Run complete fuzzing suite
44704470
@echo "🎯 Complete fuzzing suite finished"
4471+
4472+
# =============================================================================
4473+
# 🔄 MIGRATION TESTING
4474+
# =============================================================================
4475+
# help: 🔄 MIGRATION TESTING
4476+
# help: migration-test-all - Run comprehensive migration test suite (SQLite + PostgreSQL)
4477+
# help: migration-test-sqlite - Run SQLite container migration tests only
4478+
# help: migration-test-postgres - Run PostgreSQL compose migration tests only
4479+
# help: migration-test-performance - Run migration performance benchmarking
4480+
# help: migration-setup - Setup migration test environment
4481+
# help: migration-cleanup - Clean up migration test containers and volumes
4482+
# help: migration-debug - Debug migration test failures with diagnostic info
4483+
# help: migration-status - Show current version configuration and supported versions
4484+
4485+
# Migration testing configuration
4486+
MIGRATION_TEST_DIR := tests/migration
4487+
MIGRATION_REPORTS_DIR := $(MIGRATION_TEST_DIR)/reports
4488+
4489+
# Get supported versions from version config (n-2 policy)
4490+
MIGRATION_VERSIONS := $(shell cd $(MIGRATION_TEST_DIR) && python3 -c "from version_config import get_supported_versions; print(' '.join(get_supported_versions()))" 2>/dev/null || echo "0.5.0 0.6.0 latest")
4491+
4492+
.PHONY: migration-test-all migration-test-sqlite migration-test-postgres migration-test-performance \
4493+
migration-setup migration-cleanup migration-debug migration-status
4494+
4495+
migration-test-all: migration-setup ## Run comprehensive migration test suite (SQLite + PostgreSQL)
4496+
@echo "🚀 Running comprehensive migration tests..."
4497+
@echo "📋 Testing SQLite migrations..."
4498+
@test -d "$(VENV_DIR)" || $(MAKE) venv
4499+
@/bin/bash -c "source $(VENV_DIR)/bin/activate && \
4500+
pytest $(MIGRATION_TEST_DIR)/test_docker_sqlite_migrations.py \
4501+
-v --tb=short --maxfail=3 \
4502+
--log-cli-level=INFO --log-cli-format='%(asctime)s [%(levelname)s] %(name)s: %(message)s'"
4503+
@echo ""
4504+
@echo "📋 Testing PostgreSQL migrations..."
4505+
@/bin/bash -c "source $(VENV_DIR)/bin/activate && \
4506+
pytest $(MIGRATION_TEST_DIR)/test_compose_postgres_migrations.py \
4507+
-v --tb=short --maxfail=3 -m 'not slow' \
4508+
--log-cli-level=INFO --log-cli-format='%(asctime)s [%(levelname)s] %(name)s: %(message)s'"
4509+
@echo ""
4510+
@echo "📊 Generating migration test report..."
4511+
@/bin/bash -c "source $(VENV_DIR)/bin/activate && \
4512+
python3 -c 'from tests.migration.utils.reporting import MigrationReportGenerator; \
4513+
r = MigrationReportGenerator(); r.generate_summary_report()'"
4514+
@echo "✅ Migration tests complete! Reports in $(MIGRATION_REPORTS_DIR)/"
4515+
4516+
migration-test-sqlite: ## Run SQLite container migration tests only
4517+
@echo "🐍 Running SQLite migration tests..."
4518+
@test -d "$(VENV_DIR)" || $(MAKE) venv
4519+
@/bin/bash -c "source $(VENV_DIR)/bin/activate && \
4520+
pytest $(MIGRATION_TEST_DIR)/test_docker_sqlite_migrations.py \
4521+
-v --tb=short --log-cli-level=INFO"
4522+
@echo "✅ SQLite migration tests complete!"
4523+
4524+
migration-test-postgres: ## Run PostgreSQL compose migration tests only
4525+
@echo "🐘 Running PostgreSQL migration tests..."
4526+
@test -d "$(VENV_DIR)" || $(MAKE) venv
4527+
@/bin/bash -c "source $(VENV_DIR)/bin/activate && \
4528+
pytest $(MIGRATION_TEST_DIR)/test_compose_postgres_migrations.py \
4529+
-v --tb=short --log-cli-level=INFO -m 'not slow'"
4530+
@echo "✅ PostgreSQL migration tests complete!"
4531+
4532+
migration-test-performance: ## Run migration performance benchmarking
4533+
@echo "⚡ Running migration performance tests..."
4534+
@test -d "$(VENV_DIR)" || $(MAKE) venv
4535+
@/bin/bash -c "source $(VENV_DIR)/bin/activate && \
4536+
pytest $(MIGRATION_TEST_DIR)/test_migration_performance.py \
4537+
-v --tb=short --log-cli-level=INFO"
4538+
@echo "✅ Performance tests complete!"
4539+
4540+
migration-setup: ## Setup migration test environment
4541+
@echo "🔧 Setting up migration test environment..."
4542+
@test -d "$(VENV_DIR)" || $(MAKE) venv
4543+
@mkdir -p $(MIGRATION_REPORTS_DIR)
4544+
@mkdir -p $(MIGRATION_TEST_DIR)/logs
4545+
@echo "📦 Pulling required container images..."
4546+
@if command -v docker >/dev/null 2>&1; then \
4547+
for version in $(MIGRATION_VERSIONS); do \
4548+
echo " 🔄 Pulling ghcr.io/ibm/mcp-context-forge:$$version..."; \
4549+
docker pull ghcr.io/ibm/mcp-context-forge:$$version || true; \
4550+
done; \
4551+
else \
4552+
echo "⚠️ Docker not available - tests may fail"; \
4553+
fi
4554+
@echo "✅ Migration test environment ready!"
4555+
4556+
migration-cleanup: ## Clean up migration test containers and volumes
4557+
@echo "🧹 Cleaning up migration test environment..."
4558+
@if command -v docker >/dev/null 2>&1; then \
4559+
echo "🛑 Stopping migration test containers..."; \
4560+
docker ps -a --filter "name=migration-test-" -q | xargs -r docker stop; \
4561+
docker ps -a --filter "name=migration-test-" -q | xargs -r docker rm; \
4562+
echo "🗑️ Removing migration test volumes..."; \
4563+
docker volume ls --filter "name=migration-test-" -q | xargs -r docker volume rm; \
4564+
echo "🧼 Pruning migration test networks..."; \
4565+
docker network ls --filter "name=migration-test-" -q | xargs -r docker network rm; \
4566+
fi
4567+
@echo "🗂️ Cleaning up temporary files..."
4568+
@rm -rf /tmp/migration_test_*
4569+
@rm -rf $(MIGRATION_TEST_DIR)/logs/*.log
4570+
@echo "✅ Migration test cleanup complete!"
4571+
4572+
migration-debug: ## Debug migration test failures with diagnostic info
4573+
@echo "🔍 Migration test diagnostic information:"
4574+
@echo ""
4575+
@echo "📦 Container Runtime Info:"
4576+
@if command -v docker >/dev/null 2>&1; then \
4577+
echo " Docker version: $$(docker --version)"; \
4578+
echo " Running containers:"; \
4579+
docker ps --filter "name=migration-test-" --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"; \
4580+
echo " Available images:"; \
4581+
docker images --filter "reference=ghcr.io/ibm/mcp-context-forge" --format "table {{.Repository}}\t{{.Tag}}\t{{.Size}}"; \
4582+
else \
4583+
echo " ❌ Docker not available"; \
4584+
fi
4585+
@echo ""
4586+
@echo "📁 Test Environment:"
4587+
@echo " Migration test dir: $(MIGRATION_TEST_DIR)"
4588+
@echo " Reports dir: $(MIGRATION_REPORTS_DIR)"
4589+
@echo " Virtual env: $(VENV_DIR)"
4590+
@echo " Logs: $$(find $(MIGRATION_TEST_DIR)/logs -name "*.log" 2>/dev/null | wc -l) log files"
4591+
@echo ""
4592+
@echo "🔧 Recent log entries:"
4593+
@find $(MIGRATION_TEST_DIR)/logs -name "*.log" -type f -exec tail -n 5 {} + 2>/dev/null || echo " No log files found"
4594+
@echo "✅ Diagnostic complete!"
4595+
4596+
migration-status: ## Show current version configuration and supported versions
4597+
@echo "📊 Migration Test Version Configuration:"
4598+
@test -d "$(VENV_DIR)" || $(MAKE) venv
4599+
@/bin/bash -c "source $(VENV_DIR)/bin/activate && \
4600+
cd $(MIGRATION_TEST_DIR) && python3 version_status.py"

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ plugins = ["pydantic.mypy"] # Enable mypy plugin for Pydantic model
404404

405405
[tool.pytest.ini_options]
406406
minversion = "6.0"
407-
addopts = "-ra -q --cov=mcpgateway --ignore=tests/playwright"
407+
addopts = "-ra -q --cov=mcpgateway --ignore=tests/playwright --ignore=tests/migration"
408408
testpaths = [ "tests",]
409409
asyncio_mode = "auto"
410410
filterwarnings = [
@@ -428,6 +428,7 @@ markers = [
428428
"smoke: marks tests as smoke tests for quick validation",
429429
"e2e: marks tests as end-to-end tests",
430430
"fuzz: marks tests as fuzz tests (excluded from main test suite)",
431+
"benchmark: marks tests as performance benchmarks (migration testing)",
431432
]
432433

433434
# Playwright-specific test discovery patterns

0 commit comments

Comments
 (0)