Skip to content

Commit c2f2f66

Browse files
CopilotYunchuWang
andcommitted
Fix test failure: update GetLogs() to use specific category to avoid duplicates
Co-authored-by: YunchuWang <[email protected]>
1 parent 4f48371 commit c2f2f66

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

test/Grpc.IntegrationTests/IntegrationTestBase.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,11 @@ protected IHostBuilder CreateHostBuilder(
9595

9696
protected IReadOnlyCollection<LogEntry> GetLogs()
9797
{
98-
// NOTE: Renaming the log category is a breaking change!
99-
const string ExpectedCategoryName = "Microsoft.DurableTask";
98+
// Use the specific Worker.Grpc category to get gRPC worker logs.
99+
// Note: TryGetLogs uses StartsWith matching, so "Microsoft.DurableTask" would match both
100+
// the legacy category AND "Microsoft.DurableTask.Worker.Grpc", causing duplicate entries
101+
// when dual-category logging is enabled. Using the specific category avoids this issue.
102+
const string ExpectedCategoryName = "Microsoft.DurableTask.Worker.Grpc";
100103
bool foundCategory = this.logProvider.TryGetLogs(ExpectedCategoryName, out IReadOnlyCollection<LogEntry> logs);
101104
Assert.True(foundCategory);
102105
return logs;

test/Worker/Grpc.Tests/LoggingCategoryTests.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ namespace Microsoft.DurableTask.Worker.Grpc.Tests;
2020
public class LoggingCategoryTests
2121
{
2222
const string NewGrpcCategory = "Microsoft.DurableTask.Worker.Grpc";
23+
const string LegacyCategory = "Microsoft.DurableTask";
2324

2425
[Fact]
2526
public void Worker_UsesLegacyCategories_ByDefault()
@@ -195,14 +196,14 @@ public void GrpcDurableTaskWorker_EmitsToBothCategories_WhenLegacyCategoriesEnab
195196
ILogger testLogger = loggerFactory.CreateLogger(NewGrpcCategory);
196197
testLogger.LogInformation("Integration test log");
197198

198-
ILogger legacyLogger = loggerFactory.CreateLogger("Microsoft.DurableTask");
199+
ILogger legacyLogger = loggerFactory.CreateLogger(LegacyCategory);
199200
legacyLogger.LogInformation("Integration test log");
200201

201202
// Assert - verify both categories receive logs
202203
logProvider.TryGetLogs(NewGrpcCategory, out var newLogs).Should().BeTrue("new category logger should receive logs");
203204
newLogs.Should().NotBeEmpty("logs should be written to new category");
204205

205-
logProvider.TryGetLogs("Microsoft.DurableTask", out var legacyLogs).Should().BeTrue("legacy category logger should receive logs");
206+
logProvider.TryGetLogs(LegacyCategory, out var legacyLogs).Should().BeTrue("legacy category logger should receive logs");
206207
legacyLogs.Should().NotBeEmpty("logs should be written to legacy category");
207208
}
208209

@@ -245,7 +246,7 @@ public void GrpcDurableTaskWorker_EmitsToNewCategoryOnly_WhenLegacyCategoriesDis
245246
// Verify we didn't create a legacy logger (by checking directly)
246247
// The TestLogProvider uses StartsWith, so we check that no logs exist with exactly the legacy category
247248
var allLogs = newLogs.ToList();
248-
allLogs.Should().NotContain(log => log.Category == "Microsoft.DurableTask",
249+
allLogs.Should().NotContain(log => log.Category == LegacyCategory,
249250
"no logs should have exactly the legacy category when disabled");
250251
}
251252

0 commit comments

Comments
 (0)