Skip to content

Conversation

@johnnypham
Copy link
Contributor

@johnnypham johnnypham commented Jan 11, 2022

s_globalCustomColumnEncryptionKeyStoreProviders can only be set once using SqlConnection.RegisterColumnEncryptionKeyStoreProviders(). It has to be cleared after any test sets it, so that other tests can set it again. Because the functional tests run in parallel, we sometimes see a Key store providers cannot be set more than once. error. We can add a lock to ensure only one test at a time is setting and clearing s_globalCustomColumnEncryptionKeyStoreProviders.

Repro:

https://github.com/johnnypham/SqlClient/tree/testfailurerepro

Run the two tests with the appropriate filter:

dotnet test "src\Microsoft.Data.SqlClient\tests\FunctionalTests\Microsoft.Data.SqlClient.Tests.csproj" -p:Platform="AnyCPU" -p:ReferenceType=Project -p:Configuration="Release" -p:TestTargetOS="Windowsnetcoreapp" --no-build --logger:"console;verbosity=normal" --filter "TestCanSetGlobalProvidersOnlyOnce|TestExceptionsFromCustomKeyStore"

/// <summary>
/// SetCustomColumnEncryptionKeyStoreProvider can be called only once in a process. To workaround that, we use this flag.
/// </summary>
private static bool s_testCustomEncryptioKeyStoreProviderExecutedOnce = false;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This field was never even changed anywhere.

@DavoudEshtehari DavoudEshtehari added the Area\Tests Issues that are targeted to tests or test projects label Jan 12, 2022
@DavoudEshtehari DavoudEshtehari added this to the 5.0.0-preview1 milestone Jan 13, 2022
@DavoudEshtehari DavoudEshtehari changed the title Tests - Add lock when using ClearSqlConnectionGlobalProviders Test | Add lock when using ClearSqlConnectionGlobalProviders Jan 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area\Tests Issues that are targeted to tests or test projects

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants