Skip to content

Commit 9780c1e

Browse files
authored
Fixing a bug in DiagnosticEvent that results into empty events (#9688)
1 parent 2ae1292 commit 9780c1e

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

src/WebJobs.Script.WebHost/Diagnostics/DiagnosticEventTableStorageRepository.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,9 @@ internal virtual async Task FlushLogs(CloudTable table = null)
144144
catch (Exception ex)
145145
{
146146
_logger.LogError(ex, $"Unable to get table reference or create table. Aborting write operation.");
147-
return;
148-
}
149-
finally
150-
{
151147
// Clearing the memory cache to avoid memory build up.
152148
_events.Clear();
149+
return;
153150
}
154151

155152
// Assigning a new empty directory to reset the event count in the new duration window.

test/WebJobs.Script.Tests.Integration/Diagnostics/DiagnosticEventTableStorageRepositoryTests.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,28 @@ public async Task ExecuteBatchAsync_WritesToTableStorage()
249249
Assert.Equal(results.Count(), 1);
250250
}
251251

252+
[Fact]
253+
public async Task FlushLogs_WritesToTableStorage()
254+
{
255+
IEnvironment testEnvironment = new TestEnvironment();
256+
testEnvironment.SetEnvironmentVariable(EnvironmentSettingNames.AzureWebsitePlaceholderMode, "0");
257+
258+
DiagnosticEventTableStorageRepository repository =
259+
new DiagnosticEventTableStorageRepository(_configuration, _hostIdProvider, testEnvironment, _logger);
260+
261+
var table = repository.GetDiagnosticEventsTable();
262+
await TableStorageHelpers.CreateIfNotExistsAsync(table, 2);
263+
await EmptyTableAsync(table);
264+
265+
var dateTime = DateTime.UtcNow;
266+
var diagnosticEvent = new DiagnosticEvent("hostId", dateTime);
267+
repository.Events.TryAdd("EC123", diagnosticEvent);
268+
await repository.FlushLogs(table);
269+
270+
var results = ExecuteQuery(table, new TableQuery());
271+
Assert.Equal(results.Count(), 1);
272+
}
273+
252274
[Fact]
253275
public async Task ExecuteBatchAsync_LogsError()
254276
{

0 commit comments

Comments
 (0)