Skip to content

Testing Get-DbaDbQueryStoreOption - Create the database before anything has read model - #10595

Open
andreasjordan wants to merge 1 commit into
developmentfrom
fix-querystore-test-model-lock
Open

Testing Get-DbaDbQueryStoreOption - Create the database before anything has read model#10595
andreasjordan wants to merge 1 commit into
developmentfrom
fix-querystore-test-model-lock

Conversation

@andreasjordan

Copy link
Copy Markdown
Collaborator

Type of Change

  • Bug fix (non-breaking change, test only)
  • Ran manual Pester test and has passed
  • Pester test is included

Purpose

development is red. The Context that #10592 added to Get-DbaDbQueryStoreOption.Tests.ps1 creates its database after the Contexts that read Query Store on model, and those leave a session parked there. On the runners the next CREATE DATABASE cannot get the lock:

Get-DbaDbQueryStoreOption > When a value is available from SMO > ...
  Block Error: Could not obtain exclusive lock on database 'model'. Retry the operation later.
  CREATE DATABASE failed. Some file names listed could not be created.

Three attempts, all three the same. It passed in the lab because the run there happened to win the lock, which is exactly what makes this kind of failure easy to merge by accident.

Approach

The database is created in the BeforeAll of the Describe, which runs before any Context, and removed in a new AfterAll. Nothing else changes - no assertion is touched.

The cause, and why this is a workaround

The parked session is the connection leak that #10584 fixes: Invoke-DbaQuery -SqlInstance $server -Database model, which Get-DbaDbQueryStoreOption uses per database, orphaned a non-pooled connection that nothing could close. Once that is merged, the ordering here stops mattering - but a test should not depend on the order of its Contexts either way, so this is worth having regardless.

This is the third sighting of the same race:

  • Get-DbaDbRecoveryModel failing intermittently in a lab run, diagnosed to a session parked in model
  • this failure
  • Set-DbaDbCompatibility.Tests.ps1, which already carries Get-DbaProcess -Database model | Stop-DbaProcess in its BeforeAll - someone hit it before and worked around it the same way

The same care was taken in the Set-DbaDbQueryStoreOption test of #10593, which is why that one did not break.

Tests

Get-DbaDbQueryStoreOption: 7 tests, all passing, no leftovers in the lab.


This text was created by Claude and reviewed by Andreas Jordan.

…ng has read model

The Context added by #10592 created its database after the Contexts that read Query Store on model,
and those leave a session parked in model. On the CI runners the next CREATE DATABASE then failed:

    Could not obtain exclusive lock on database 'model'. Retry the operation later.
    CREATE DATABASE failed. Some file names listed could not be created.

Three attempts, all three the same, so development is red on it. It did not show up in the lab because
the run there happened to get the lock.

The database is created in the BeforeAll of the Describe now, which runs before any Context, and
removed in a new AfterAll. Nothing else changes.

The parked session is the leak of #10584. Once that is merged this workaround is no longer needed, but
the test should not depend on the order of the Contexts either way. The same care was already taken in
the Set-DbaDbQueryStoreOption test of #10593, which is why that one did not break.

(do Get-DbaDbQueryStoreOption)
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