Spaces:
Build error
Build error
File size: 5,240 Bytes
6423ff2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# Test Music Generation End-to-End
# Tests the complete flow from API call to generation
$Colors = @{
Red = "Red"
Green = "Green"
Yellow = "Yellow"
Blue = "Cyan"
}
function Write-Info { Write-Host "[INFO] $args" -ForegroundColor $Colors.Blue }
function Write-Success { Write-Host "[SUCCESS] $args" -ForegroundColor $Colors.Green }
function Write-Warning { Write-Host "[WARNING] $args" -ForegroundColor $Colors.Yellow }
function Write-Error { Write-Host "[ERROR] $args" -ForegroundColor $Colors.Red }
Write-Host "`n"
Write-Host "===========================================================" -ForegroundColor Cyan
Write-Host " Music Generation End-to-End Test " -ForegroundColor Cyan
Write-Host "===========================================================" -ForegroundColor Cyan
Write-Host "`n"
$baseUrl = "http://127.0.0.1:8001"
$maxAttempts = 3
$attempt = 0
# Test 1: Backend Health
Write-Info "Test 1: Backend Health Check"
try {
$response = Invoke-WebRequest -Uri "$baseUrl/health" -UseBasicParsing -TimeoutSec 5
if ($response.StatusCode -eq 200) {
Write-Success "Backend is healthy"
} else {
Write-Error "Backend returned status $($response.StatusCode)"
exit 1
}
} catch {
Write-Error "Backend not responding: $($_.Exception.Message)"
Write-Warning "Make sure backend is running: cd backend; uvicorn app.main:app --reload"
exit 1
}
# Test 2: Create Generation
Write-Info "`nTest 2: Creating Music Generation"
$testPrompt = "A peaceful piano melody with soft strings"
$body = @{
prompt = $testPrompt
duration = 10
} | ConvertTo-Json
while ($attempt -lt $maxAttempts) {
$attempt++
Write-Host "Attempt $attempt/$maxAttempts..." -ForegroundColor Yellow
try {
$response = Invoke-WebRequest -Uri "$baseUrl/api/v1/generations" `
-Method POST `
-Body $body `
-ContentType "application/json" `
-UseBasicParsing `
-TimeoutSec 15
if ($response.StatusCode -eq 202 -or $response.StatusCode -eq 201 -or $response.StatusCode -eq 200) {
$data = $response.Content | ConvertFrom-Json
Write-Success "Generation created successfully!"
Write-Host " Generation ID: $($data.id)" -ForegroundColor Gray
Write-Host " Status: $($data.status)" -ForegroundColor Gray
Write-Host " Prompt: $testPrompt" -ForegroundColor Gray
# Test 3: Check Generation Status
Write-Info "`nTest 3: Checking Generation Status"
$statusAttempt = 0
$maxStatusAttempts = 30
while ($statusAttempt -lt $maxStatusAttempts) {
$statusAttempt++
Start-Sleep -Seconds 5
try {
$statusResponse = Invoke-WebRequest -Uri "$baseUrl/api/v1/generations/$($data.id)" -UseBasicParsing -TimeoutSec 5
$statusData = $statusResponse.Content | ConvertFrom-Json
Write-Host " Current status: $($statusData.status) ($statusAttempt/$maxStatusAttempts)" -ForegroundColor Gray
if ($statusData.status -eq "completed") {
Write-Success "Generation completed!"
if ($statusData.audio_path) {
Write-Host " Audio file: $($statusData.audio_path)" -ForegroundColor Green
}
Write-Host "`nMusic generation feature is working!`n" -ForegroundColor Green
exit 0
} elseif ($statusData.status -eq "failed") {
Write-Error "Generation failed: $($statusData.error_message)"
exit 1
}
} catch {
Write-Warning "Could not check status: $($_.Exception.Message)"
}
}
Write-Error "Generation timed out"
exit 1
}
} catch {
$statusCode = if ($_.Exception.Response) { $_.Exception.Response.StatusCode.value__ } else { "Unknown" }
$errorMsg = $_.Exception.Message
Write-Error "Failed: Status $statusCode - $errorMsg"
if ($statusCode -eq 500) {
Write-Warning "500 error usually means:"
Write-Host " * Database connection issue (check Docker)" -ForegroundColor Gray
Write-Host " * ML dependencies not installed" -ForegroundColor Gray
Write-Host " * Check backend logs for details" -ForegroundColor Gray
}
if ($attempt -lt $maxAttempts) {
Write-Host " Retrying in 3 seconds..." -ForegroundColor Gray
Start-Sleep -Seconds 3
}
}
}
Write-Error "Failed after $maxAttempts attempts"
Write-Host "Troubleshooting:" -ForegroundColor Yellow
Write-Host "1. Check backend is running" -ForegroundColor White
Write-Host "2. Verify ML dependencies" -ForegroundColor White
Write-Host "3. Check Docker containers" -ForegroundColor White
Write-Host "4. Review backend logs for errors" -ForegroundColor White
exit 1 |