public async Task Test_CanWrite_NoExistingStats_UniquePayloadTypes(int nStats) { Faker faker = new Faker(); PostgreSqlExecutionPerformanceMonitorWriter writer = GetWriter(); List <TaskPerformanceStats> sampleStats = faker .RandomExecutionPerformanceStats(nStats); List <ExecutionPerformanceInfoRecord> expectedRecords = GetExecutionPerformanceInfoRecordsFromTaskPeformanceStats(sampleStats); await writer.WriteAsync(sampleStats); List <ExecutionPerformanceInfoRecord> dbRecords = await GetDbTaskPerformanceStatsAsync(); CollectionAssert.AreEquivalent(expectedRecords, dbRecords); foreach (ExecutionPerformanceInfoRecord r in dbRecords) { Assert.AreEqual(1, r.NExecutionCycles); } }
public async Task Test_CanWrite_AllZeroValues_NoInitialValues_SamePayloadTypes(int nStats, int nWrites) { Faker faker = new Faker(); PostgreSqlExecutionPerformanceMonitorWriter writer = GetWriter(); List <TaskPerformanceStats>[] sampleStats = new List <TaskPerformanceStats> [nWrites]; for (int i = 0; i < nWrites; i++) { if (i > 0) { sampleStats[i] = faker.RandomAllZeroExecutionPerformanceStats(sampleStats[0] .Select(s => s.PayloadType) .AsEnumerable()); } else { sampleStats[i] = faker.RandomAllZeroExecutionPerformanceStats(nStats); } } List <ExecutionPerformanceInfoRecord> expectedRecords = GetExecutionPerformanceInfoRecordsFromTaskPeformanceStats(sampleStats); for (int i = 0; i < nWrites; i++) { await writer.WriteAsync(sampleStats[i]); } List <ExecutionPerformanceInfoRecord> dbRecords = await GetDbTaskPerformanceStatsAsync(); CollectionAssert.AreEquivalent(expectedRecords, dbRecords); foreach (ExecutionPerformanceInfoRecord r in dbRecords) { Assert.AreEqual(nWrites, r.NExecutionCycles); Assert.IsTrue(r.AllZeroValues()); } }
public async Task Test_CanWrite_WithExistingStats_UniquePayloadTypesInSet_SamePayloadTypesAsExisting(int nStats) { Faker faker = new Faker(); PostgreSqlExecutionPerformanceMonitorWriter writer = GetWriter(); List <TaskPerformanceStats> dbStats = await GenerateExecutionPerformanceStatsInDbAsync(nStats); List <TaskPerformanceStats> newStats = faker.RandomExecutionPerformanceStats(dbStats .Select(s => s.PayloadType) .AsEnumerable()); List <ExecutionPerformanceInfoRecord> expectedRecords = GetExecutionPerformanceInfoRecordsFromTaskPeformanceStats(dbStats, newStats); await writer.WriteAsync(newStats); List <ExecutionPerformanceInfoRecord> dbRecords = await GetDbTaskPerformanceStatsAsync(); CollectionAssert.AreEquivalent(expectedRecords, dbRecords); foreach (ExecutionPerformanceInfoRecord r in dbRecords) { int expectedCycleCount = dbStats.Count(s => s.PayloadType == r.PayloadType) + newStats.Count(s => s.PayloadType == r.PayloadType); Assert.AreEqual(expectedCycleCount, r.NExecutionCycles); } }