-
Notifications
You must be signed in to change notification settings - Fork 340
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
Open
charlesroddie
wants to merge
4
commits into
dotnet:main
Choose a base branch
from
charlesroddie:trim-app-config-switch
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+167
−8
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
cdd0450
Allow app.config reading to be trimmed away
charlesroddie fecd953
Share the no-retry providers when app.config is not read
charlesroddie 6d0013c
Gate the LocalDB config section on EnableAppConfig
charlesroddie 6f5acf9
Document that EnableAppConfig trims only when set at publish time
charlesroddie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
...soft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/EnableAppConfigSwitchTest.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
|
|
||
| /// <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); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.