diff --git a/tests/PSProxmoxVE.Tests/Integration/06_VMs.Tests.ps1 b/tests/PSProxmoxVE.Tests/Integration/06_VMs.Tests.ps1 index 86263c2..4190347 100644 --- a/tests/PSProxmoxVE.Tests/Integration/06_VMs.Tests.ps1 +++ b/tests/PSProxmoxVE.Tests/Integration/06_VMs.Tests.ps1 @@ -17,16 +17,8 @@ BeforeAll { } AfterAll { - if (-not $script:SkipReason -and $script:TestVmId) { - # Stop and remove pester-test-vm and any clone - foreach ($vmId in @($script:TestVmId, ($script:TestVmId + 1000))) { - try { - Stop-PveVm -Node $script:Node -VmId $vmId -Confirm:$false -ErrorAction SilentlyContinue | Out-Null - Start-Sleep -Seconds 3 - Remove-PveVm -Node $script:Node -VmId $vmId -Force -Purge -Confirm:$false -ErrorAction SilentlyContinue - } catch { } - } - } + # Do NOT clean up pester-test-vm here — later test files (07_Snapshots, + # 09_CloudInit, 15_Tasks) depend on it. 99_Cleanup handles removal. Disconnect-TestPve } diff --git a/tests/PSProxmoxVE.Tests/Integration/10_Containers.Tests.ps1 b/tests/PSProxmoxVE.Tests/Integration/10_Containers.Tests.ps1 index d1312df..f5cf4d3 100644 --- a/tests/PSProxmoxVE.Tests/Integration/10_Containers.Tests.ps1 +++ b/tests/PSProxmoxVE.Tests/Integration/10_Containers.Tests.ps1 @@ -21,11 +21,12 @@ AfterAll { if ($null -eq $script:SkipReason) { foreach ($ctId in $script:CreatedContainerIds) { try { - Stop-PveContainer -Node $script:Node -VmId $ctId -Confirm:$false -ErrorAction SilentlyContinue | Out-Null - Start-Sleep -Seconds 3 + Stop-PveContainer -Node $script:Node -VmId $ctId -Wait -Timeout 30 -Confirm:$false -ErrorAction SilentlyContinue | Out-Null + } catch { } + Start-Sleep -Seconds 2 + try { Remove-PveContainer -Node $script:Node -VmId $ctId -Force -Purge -Confirm:$false -ErrorAction SilentlyContinue - } - catch { <# non-fatal #> } + } catch { } } } Disconnect-TestPve diff --git a/tests/PSProxmoxVE.Tests/Integration/99_Cleanup.Tests.ps1 b/tests/PSProxmoxVE.Tests/Integration/99_Cleanup.Tests.ps1 index 9fc8b1e..247324b 100644 --- a/tests/PSProxmoxVE.Tests/Integration/99_Cleanup.Tests.ps1 +++ b/tests/PSProxmoxVE.Tests/Integration/99_Cleanup.Tests.ps1 @@ -19,9 +19,9 @@ Describe 'Safety-Net Cleanup — Integration' -Tag 'Integration' { $pesterVms = $vms | Where-Object { $_.Name -like 'pester-*' } foreach ($vm in $pesterVms) { try { - Stop-PveVm -Node $script:Node -VmId $vm.VmId -Confirm:$false -ErrorAction SilentlyContinue | Out-Null - Start-Sleep -Seconds 3 + Stop-PveVm -Node $script:Node -VmId $vm.VmId -Wait -Timeout 30 -Confirm:$false -ErrorAction SilentlyContinue | Out-Null } catch { } + Start-Sleep -Seconds 2 try { # Try removing as template first (templates need Remove-PveTemplate) Remove-PveTemplate -Node $script:Node -VmId $vm.VmId -Confirm:$false -ErrorAction SilentlyContinue @@ -31,6 +31,8 @@ Describe 'Safety-Net Cleanup — Integration' -Tag 'Integration' { } catch { } } } + # Wait for removals to complete + Start-Sleep -Seconds 3 # Verify $remaining = Get-PveVm -Node $script:Node -ErrorAction SilentlyContinue | @@ -45,13 +47,15 @@ Describe 'Safety-Net Cleanup — Integration' -Tag 'Integration' { $pesterCts = $containers | Where-Object { $_.Name -like 'pester-*' } foreach ($ct in $pesterCts) { try { - Stop-PveContainer -Node $script:Node -VmId $ct.VmId -Confirm:$false -ErrorAction SilentlyContinue | Out-Null - Start-Sleep -Seconds 3 + Stop-PveContainer -Node $script:Node -VmId $ct.VmId -Wait -Timeout 30 -Confirm:$false -ErrorAction SilentlyContinue | Out-Null } catch { } + Start-Sleep -Seconds 2 try { Remove-PveContainer -Node $script:Node -VmId $ct.VmId -Force -Purge -Confirm:$false -ErrorAction SilentlyContinue } catch { } } + # Wait for removals to complete + Start-Sleep -Seconds 3 # Verify $remaining = Get-PveContainer -Node $script:Node -ErrorAction SilentlyContinue |