public void EverythingAsync() { const int MaxExecTime = 24 * 3600 * 1000; var stream = new MemoryStream(); var r = new Random(0); for (int i = 0; i < 10; i++) { int seed = r.Next(100 * 1000); HistoricPerfDataTable table = new HistoricPerfDataTable(LoggingContext); XAssert.IsTrue(table.Count == 0); var s = new Random(seed); var buffer = new byte[sizeof(long)]; for (int j = 0; j < 10; j++) { s.NextBytes(buffer); long semiStableHash = BitConverter.ToInt64(buffer, 0); var execTime = (uint)s.Next(MaxExecTime); var processPipExecutionPerformance = new ProcessPipExecutionPerformance( PipExecutionLevel.Executed, DateTime.UtcNow, DateTime.UtcNow.AddMilliseconds(execTime), FingerprintUtilities.ZeroFingerprint, TimeSpan.FromMilliseconds(execTime), default(FileMonitoringViolationCounters), default(IOCounters), TimeSpan.FromMilliseconds(execTime), TimeSpan.FromMilliseconds(execTime / 2), ProcessMemoryCounters.CreateFromMb(1024, 1024, 1024, 1024), 1, workerId: 0, suspendedDurationMs: 0); ProcessPipHistoricPerfData runTimeData = new ProcessPipHistoricPerfData(processPipExecutionPerformance, execTime); table[semiStableHash] = runTimeData; } XAssert.IsTrue(table.Count == 10); stream.Position = 0; table.Save(stream); stream.Position = 0; table = HistoricPerfDataTable.Load(LoggingContext, stream); XAssert.IsTrue(table.Count == 10); s = new Random(seed); for (int j = 0; j < 10; j++) { s.NextBytes(buffer); long semiStableHash = BitConverter.ToInt64(buffer, 0); XAssert.IsTrue(table[semiStableHash].ExeDurationInMs >= (uint)s.Next(MaxExecTime)); } } }
public void TimeToLive() { int execTime = 1; uint runTime = 2; var processPipExecutionPerformance = new ProcessPipExecutionPerformance( PipExecutionLevel.Executed, DateTime.UtcNow, DateTime.UtcNow.AddMilliseconds(execTime), FingerprintUtilities.ZeroFingerprint, TimeSpan.FromMilliseconds(execTime), default(FileMonitoringViolationCounters), default(IOCounters), TimeSpan.FromMilliseconds(execTime), TimeSpan.FromMilliseconds(execTime / 2), ProcessMemoryCounters.CreateFromMb(1024, 1024, 1024, 1024), 1, workerId: 0, suspendedDurationMs: 0); ProcessPipHistoricPerfData runTimeData = new ProcessPipHistoricPerfData(processPipExecutionPerformance, runTime); HistoricPerfDataTable table = new HistoricPerfDataTable(LoggingContext); var semiStableHashToKeep = 0; table[semiStableHashToKeep] = runTimeData; var semiStableHashToDrop = 1; table[semiStableHashToDrop] = runTimeData; var stream = new MemoryStream(); for (int i = 0; i < ProcessPipHistoricPerfData.DefaultTimeToLive; i++) { stream.Position = 0; table.Save(stream); stream.Position = 0; table = HistoricPerfDataTable.Load(LoggingContext, stream); Analysis.IgnoreResult(table[semiStableHashToKeep]); } stream.Position = 0; table = HistoricPerfDataTable.Load(LoggingContext, stream); XAssert.AreEqual(1u, table[semiStableHashToKeep].ExeDurationInMs); XAssert.AreEqual(0u, table[semiStableHashToDrop].ExeDurationInMs); }