-
Notifications
You must be signed in to change notification settings - Fork 341
Add an EnableAppConfig switch to remove trim warnings #4697
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
cdd0450
fecd953
6d0013c
6f5acf9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -166,6 +166,9 @@ public sealed partial class SqlCommand : DbCommand, ICloneable | |
| /// </summary> | ||
| private static readonly SqlDiagnosticListener s_diagnosticListener = new(); | ||
|
|
||
| // Shared by all commands when app.config is not read. | ||
| private static SqlRetryLogicBaseProvider s_noneRetryProvider; | ||
|
|
||
| /// <summary> | ||
| /// Connection that will be used to process the current instance. | ||
| /// </summary> | ||
|
|
@@ -763,7 +766,9 @@ public SqlRetryLogicBaseProvider RetryLogicProvider | |
| { | ||
| get | ||
| { | ||
| _retryLogicProvider ??= SqlConfigurableRetryLogicManager.CommandProvider; | ||
| _retryLogicProvider ??= LocalAppContextSwitches.EnableAppConfig | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| ? SqlConfigurableRetryLogicManager.CommandProvider | ||
| : LazyInitializer.EnsureInitialized(ref s_noneRetryProvider, SqlConfigurableRetryFactory.CreateNoneRetryProvider); | ||
| return _retryLogicProvider; | ||
| } | ||
| set => _retryLogicProvider = value; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using Microsoft.Data.SqlClient.Tests.Common; | ||
| using Xunit; | ||
|
|
||
| namespace Microsoft.Data.SqlClient.UnitTests; | ||
|
|
||
| /// <summary> | ||
| /// Tests that the EnableAppConfig switch gates the configurable retry logic | ||
| /// providers used by commands and connections. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// The authentication provider and switch override readers run once, in | ||
| /// static constructors, so they cannot be exercised in-process. | ||
| /// </remarks> | ||
| [Collection(AppContextSwitchTestCollection.Name)] | ||
| public class EnableAppConfigSwitchTest | ||
| { | ||
| /// <summary> | ||
| /// With the switch off, commands share one non-retriable provider that | ||
| /// does not come from the configurable retry logic manager. | ||
| /// </summary> | ||
| [Fact] | ||
| public void Disabled_CommandsShareNonRetriableProvider() | ||
| { | ||
| using LocalAppContextSwitchesHelper switchesHelper = new(); | ||
| switchesHelper.EnableAppConfig = false; | ||
|
|
||
| using SqlCommand first = new(); | ||
| using SqlCommand second = new(); | ||
|
|
||
| Assert.Same(first.RetryLogicProvider, second.RetryLogicProvider); | ||
| Assert.False(SqlConfigurableRetryFactory.IsRetriable(first.RetryLogicProvider)); | ||
| Assert.NotSame(SqlConfigurableRetryLogicManager.CommandProvider, first.RetryLogicProvider); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This |
||
| } | ||
|
|
||
| /// <summary> | ||
| /// With the switch off, connections share one non-retriable provider that | ||
| /// does not come from the configurable retry logic manager. | ||
| /// </summary> | ||
| [Fact] | ||
| public void Disabled_ConnectionsShareNonRetriableProvider() | ||
| { | ||
| using LocalAppContextSwitchesHelper switchesHelper = new(); | ||
| switchesHelper.EnableAppConfig = false; | ||
|
|
||
| using SqlConnection first = new(); | ||
| using SqlConnection second = new(); | ||
|
|
||
| Assert.Same(first.RetryLogicProvider, second.RetryLogicProvider); | ||
| Assert.False(SqlConfigurableRetryFactory.IsRetriable(first.RetryLogicProvider)); | ||
| Assert.NotSame(SqlConfigurableRetryLogicManager.ConnectionProvider, first.RetryLogicProvider); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// With the switch on, commands and connections use the manager's | ||
| /// providers, as they did before the switch existed. | ||
| /// </summary> | ||
| [Fact] | ||
| public void Enabled_UsesManagerProviders() | ||
| { | ||
| using LocalAppContextSwitchesHelper switchesHelper = new(); | ||
| switchesHelper.EnableAppConfig = true; | ||
|
|
||
| using SqlCommand command = new(); | ||
| using SqlConnection connection = new(); | ||
|
|
||
| Assert.Same(SqlConfigurableRetryLogicManager.CommandProvider, command.RetryLogicProvider); | ||
| Assert.Same(SqlConfigurableRetryLogicManager.ConnectionProvider, connection.RetryLogicProvider); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will remove the trim warning - does it allow ILLink to trim away every type within the System.Configuration assembly? We can use sizoscope to check this, it'll remove around 1.4MB if so.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not every type but most.
System.Configuration.ConfigurationManager.dllgoes from 443KB untrimmed, to 133KB trimmed before this PR (i.e. with the switch on), to 42KB trimmed with the switch off.The residual is to do with
SqlAuthenticationProviderManagerwhere is ongoing work.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without loading data from
app.config, the constructor forSqlAuthenticationProviderManagerhas no work to do. One way to remove this might be to have a private parameterless constructor which no-ops or logs; the class could be instantiated with that if theEnableAppConfigswitch is disabled.