public async Task QueueBackgroundDiagnosticsEventsTablePurge_PurgesTables() { IEnvironment testEnvironment = new TestEnvironment(); testEnvironment.SetEnvironmentVariable(EnvironmentSettingNames.AzureWebsitePlaceholderMode, "0"); DiagnosticEventTableStorageRepository repository = new DiagnosticEventTableStorageRepository(_configuration, _hostIdProvider, testEnvironment, _logger); // delete any existing non-current diagnostics events tables string tablePrefix = DiagnosticEventTableStorageRepository.TableNamePrefix; var currentTable = repository.GetDiagnosticEventsTable(); var tables = await TableStorageHelpers.ListOldTablesAsync(currentTable, repository.TableClient, tablePrefix); foreach (var table in tables) { await table.DeleteIfExistsAsync(); } // create 3 old tables for (int i = 0; i < 3; i++) { var table = repository.TableClient.GetTableReference($"{tablePrefix}Test{i}"); await TableStorageHelpers.CreateIfNotExistsAsync(table, 2); } // verify tables were created tables = await TableStorageHelpers.ListOldTablesAsync(currentTable, repository.TableClient, tablePrefix); Assert.Equal(3, tables.Count()); // queue the background purge TableStorageHelpers.QueueBackgroundTablePurge(currentTable, repository.TableClient, tablePrefix, NullLogger.Instance, 0); // wait for the purge to complete await TestHelpers.Await(async() => { tables = await TableStorageHelpers.ListOldTablesAsync(currentTable, repository.TableClient, tablePrefix); return(tables.Count() == 0); }, timeout : 5000); }