Skip to content

Commit

Permalink
Last one wins flag providers (#501)
Browse files Browse the repository at this point in the history
* Adjusts to last one wins logic for flag provider

* Removed unused schema

* Reverted dotnet feature definition to continue to use FirstOrDefault
  • Loading branch information
rossgrambo authored Sep 16, 2024
1 parent 138fe01 commit 8603981
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ private FeatureDefinition GetMicrosoftSchemaFeatureDefinition(string featureName
IEnumerable<IConfigurationSection> microsoftFeatureDefinitionSections = GetMicrosoftFeatureDefinitionSections();

IConfigurationSection configuration = microsoftFeatureDefinitionSections
.FirstOrDefault(section =>
.LastOrDefault(section =>
string.Equals(section[MicrosoftFeatureManagementFields.Id], featureName, StringComparison.OrdinalIgnoreCase));

if (configuration == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
]
}
}
}
}
20 changes: 20 additions & 0 deletions tests/Tests.FeatureManagement/FeatureManagementTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,26 @@ public async Task CustomFeatureDefinitionProvider()

Assert.True(called);
}

[Fact]
public async Task LastFeatureFlagWins()
{
IConfiguration configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.Build();

IServiceCollection services = new ServiceCollection();

services
.AddSingleton(configuration)
.AddFeatureManagement();

ServiceProvider serviceProvider = services.BuildServiceProvider();

IFeatureManager featureManager = serviceProvider.GetRequiredService<IFeatureManager>();

Assert.True(await featureManager.IsEnabledAsync(Features.DuplicateFlag));
}
}

public class FeatureManagementFeatureFilterGeneralTest
Expand Down
1 change: 1 addition & 0 deletions tests/Tests.FeatureManagement/Features.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ static class Features
public const string OnTelemetryTestFeature = "OnTelemetryTestFeature";
public const string OffTelemetryTestFeature = "OffTelemetryTestFeature";
public const string ContextualFeatureWithVariant = "ContextualFeatureWithVariant";
public const string DuplicateFlag = "DuplicateFlag";
}
}
8 changes: 8 additions & 0 deletions tests/Tests.FeatureManagement/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,14 @@
"default_when_enabled": "Big",
"default_when_disabled": "Small"
}
},
{
"id": "DuplicateFlag",
"enabled": false
},
{
"id": "DuplicateFlag",
"enabled": true
}
]
}
Expand Down

0 comments on commit 8603981

Please sign in to comment.