Skip to content

Tests - Case sensitive lookups and backup cleanup in seven test files - #10670

Open
andreasjordan wants to merge 3 commits into
developmentfrom
fix-cs-test-leftovers
Open

Tests - Case sensitive lookups and backup cleanup in seven test files#10670
andreasjordan wants to merge 3 commits into
developmentfrom
fix-cs-test-leftovers

Conversation

@andreasjordan

@andreasjordan andreasjordan commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

Test-only. Found by a full suite run against three case sensitive instances (SQL_Latin1_General_CP1_CS_AS) plus two leftovers the same run reported.

Case sensitivity

  • Copy-DbaDbViewData.Tests.ps1: two query-mode tests select Id from a column called id - "Invalid column name 'Id'" on a case sensitive instance (the same defect in Copy-DbaDbTableData.Tests.ps1 is part of Copy-DbaDbTableData - Map query columns onto the writable destination columns #10666).

  • New-DbaDatabase.Tests.ps1: the tests create the log file with -LogFileSuffix "_Log" and then look it up as LogFiles["<name>_log"]. SMO collections follow the server collation, so on a case sensitive instance the lookup returns $null and the size and growth assertions fail. The lookups with the default suffix (randomDb) are untouched, they are _log for real.

  • Sync-DbaLoginPermission.Tests.ps1: the setup batch says USE Master, which a case sensitive instance rejects, so the whole batch is dropped and the login never exists on the source - the sync then finds nothing and warns. The test also passed -WarningVariable $warn (an empty variable name), which hid exactly that warning. Now master, warn, and the setup runs with EnableException so a failing setup fails the file.

Leftovers

  • Enable-DbaForceNetworkEncryption.Tests.ps1 enabled force encryption on InstanceSingle and never put it back; the registry value survives everything except an explicit Disable, and four lab instances had drifted to True that way. Both the Enable and the Disable test now read the state in BeforeAll and restore it in AfterAll.
  • Connect-DbaInstance.Tests.ps1 ("clones when using Backup-DabInstace") took two msdb backups with the same default name (same minute) and removed each with a silenced Remove-Item. One removal failed silently once and the file was reported as a leftover by the 18 following test files. The backups now get unique names, and the removal retries a few times and then asserts that the file is gone.
  • Measure-DbaBackupThroughput.Tests.ps1 removed its backup folder with a single Remove-Item -Recurse seconds after the backup, which once left the whole folder behind (55 files flagged it). Same treatment: retry, and let the last attempt report its error.

Neither leftover reproduced when the file ran alone, so both are timing races on the share rather than deterministic bugs; the retries make the cleanup robust either way.

Tests

All seven files green through the testing-dbatools harness against the case sensitive lab (SQL Server 2019/2022/2025), with the Enable/Disable pair verified to leave ForceEncryption as it found it.

created by Claude and reviewed by Andreas Jordan

🤖 Generated with Claude Code

Found by a full run against case sensitive instances (SQL_Latin1_General_CP1_CS_AS):

- Copy-DbaDbViewData.Tests.ps1 selects Id from a column called id.
- New-DbaDatabase.Tests.ps1 creates the log file with -LogFileSuffix "_Log" and then looks it up
  as "<name>_log"; SMO collections follow the server collation, so the lookup returns nothing.
- Enable-DbaForceNetworkEncryption.Tests.ps1 left the instance with force encryption enabled;
  both the Enable and the Disable test now remember the state and put it back.
- Connect-DbaInstance.Tests.ps1 took two msdb backups with the same default name and removed
  them with a silenced Remove-Item, which once failed and left the file behind for every later
  test file; the backups now get unique names and the removal retries and asserts.
- Measure-DbaBackupThroughput.Tests.ps1 removed its backup folder with a single Remove-Item
  seconds after the backup, which once left the whole folder behind; it retries now too.

(do Copy-DbaDbViewData, New-DbaDatabase, Connect-DbaInstance, Measure-DbaBackupThroughput, *ForceNetworkEncryption)
…e the warning for real

The setup batch says USE Master, which a case sensitive instance rejects ("Database 'Master' does not exist"),
so the whole batch is dropped, the login never exists on the source and the sync finds nothing. The setup
now runs with EnableException like the other files, so a failing setup fails the file instead of two tests
later on. The test also passed -WarningVariable $warn, an empty variable name, which hid that warning and
made the warning assertion vacuous.

(do Sync-DbaLoginPermission)
@andreasjordan andreasjordan changed the title Tests - Case sensitive lookups and backup cleanup in six test files Tests - Case sensitive lookups and backup cleanup in seven test files Sep 1, 2026
…string literals

(do Sync-DbaLoginPermission)
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.

1 participant