Skip to content

Tests - Stop leaving backup files behind in the lab - #10539

Open
andreasjordan wants to merge 2 commits into
developmentfrom
fix-tests-leaving-backups
Open

Tests - Stop leaving backup files behind in the lab#10539
andreasjordan wants to merge 2 commits into
developmentfrom
fix-tests-leaving-backups

Conversation

@andreasjordan

Copy link
Copy Markdown
Collaborator

Three test files left backup files behind in the lab. Found by running the full suite and checking the
environment after every test file.

The count is worth stating, because it is what makes this worth fixing rather than tidy-up: the environment
check reports every file it finds, so one leftover from the 34th test file made 709 of 742 files in a
full run look like they had left something behind. That buries a real leftover from a later file in noise.

Connect-DbaInstance

$results = Backup-DbaDatabase -SqlInstance $server -Database msdb
if ($results.FullName) {
    Remove-Item -Path $results.FullName -ErrorAction SilentlyContinue
}

The cleanup was already there and looks correct, but it never worked against a remote instance. Without
-Path the backup lands in the default backup folder of the instance, so $results.FullName is a path on
the SQL Server. Remove-Item runs on the machine executing the tests, where that path does not exist, and
-ErrorAction SilentlyContinue swallows the failure. The backup stayed on the instance every time.

It now backs up to the shared temp folder, where the cleanup can actually reach the file. This test only cares
that Connect-DbaInstance clones the server object correctly, so where the backup goes is incidental.

Copy-DbaDatabase

The file already said what should happen:

# For all the backups that we want to clean up after the test, we create a directory that we can delete at the end.
$NetworkPath = $TestConfig.Temp

but the variable pointed at the shared temp folder itself and nothing ever deleted anything. It now creates a
directory per run and removes it in AfterAll, which is what the comment always described.

Invoke-DbaDbMirroring

Seeding the mirror leaves a full backup and a log backup in the shared folder. AfterAll removed the mirror,
the databases and the endpoints, but not those two files.

Testing

All three files pass and the environment check reports no leftovers afterwards, with the shared temp folder
empty at the end:

Connect-DbaInstance.Tests.ps1 28 passed / 1 skipped
Copy-DbaDatabase.Tests.ps1 28 passed
Invoke-DbaDbMirroring.Tests.ps1 2 passed

The one warning Copy-DbaDatabase.Tests.ps1 still writes (Set-DbaDbOwner ... is not accessible) is a
separate, real problem in its setup and is deliberately left visible rather than silenced.

馃 Generated with Claude Code

andreasjordan and others added 2 commits August 8, 2026 18:31
Three test files left backups behind, and because the environment check reports every file it
finds after every test file, one leftover from the 34th file made 709 of 742 files in a full
run look like they had left something in the lab.

Connect-DbaInstance backed msdb up without a path, so the backup landed in the default backup
folder of the instance. That is a path on the SQL Server, so the Remove-Item that was already
there ran against a path that does not exist on the machine running the tests and silently did
nothing. It backs up to the shared temp folder now, where the cleanup can actually reach it.

Copy-DbaDatabase already said in a comment that the backups go to a directory that gets deleted
at the end, but the variable pointed at the shared temp folder itself and nothing deleted
anything. It now creates a directory per run and removes it in AfterAll.

Invoke-DbaDbMirroring left the full backup and the log backup it uses to seed the mirror.

Verified in the lab: the three files pass and the environment check reports no leftovers.

(do Connect-DbaInstance, Copy-DbaDatabase, Invoke-DbaDbMirroring)

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants