Skip to content

Commit 3f68429

Browse files
Copilotpremun
andcommitted
Fix static state bug in ChannelCategorizer causing test failures
Co-authored-by: premun <[email protected]>
1 parent d1cffa3 commit 3f68429

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

  • src/ProductConstructionService/Microsoft.DotNet.ProductConstructionService.Client/Helpers

src/ProductConstructionService/Microsoft.DotNet.ProductConstructionService.Client/Helpers/ChannelCategorizer.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,23 @@ namespace Microsoft.DotNet.ProductConstructionService.Client.Helpers
1414
/// </summary>
1515
public static class ChannelCategorizer
1616
{
17-
private static readonly Lazy<List<ChannelCategory>> s_categories = new Lazy<List<ChannelCategory>>(() =>
17+
private static readonly List<string> s_categoryNames =
1818
// .NET 6-20
19-
Enumerable.Range(0, 16).Select(v => new ChannelCategory($".NET {20 - v}"))
19+
Enumerable.Range(0, 16).Select(v => $".NET {20 - v}")
2020
.Concat(new[]
2121
{
22-
new ChannelCategory(".NET"),
23-
new ChannelCategory("VS"),
24-
new ChannelCategory("Windows"),
25-
new ChannelCategory("Other"),
26-
new ChannelCategory("Test"),
22+
".NET",
23+
"VS",
24+
"Windows",
25+
"Other",
26+
"Test",
2727
})
28-
.ToList());
28+
.ToList();
2929

3030
public static List<ChannelCategory> CategorizeChannels(IEnumerable<Channel> channels)
3131
{
32-
var categories = s_categories.Value;
32+
// Create fresh category instances for each call to avoid static state issues
33+
var categories = s_categoryNames.Select(name => new ChannelCategory(name)).ToList();
3334
var otherCategory = categories.First(c => c.Name == "Other");
3435
var testCategory = categories.First(c => c.Name == "Test");
3536

0 commit comments

Comments
 (0)