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); PipRuntimeTimeTable table = new PipRuntimeTimeTable(); 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); int execTime = 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), 1024 * 1024, 1, workerId: 0); PipHistoricPerfData runTimeData = new PipHistoricPerfData(processPipExecutionPerformance); table[semiStableHash] = runTimeData; } XAssert.IsTrue(table.Count == 10); stream.Position = 0; table.Save(stream); stream.Position = 0; table = PipRuntimeTimeTable.Load(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].DurationInMs >= (uint)s.Next(MaxExecTime)); } } }
public void TimeToLive() { int execTime = 1; 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), 1024 * 1024, 1, workerId: 0); PipHistoricPerfData runTimeData = new PipHistoricPerfData(processPipExecutionPerformance); PipRuntimeTimeTable table = new PipRuntimeTimeTable(); var semiStableHashToKeep = 0; table[semiStableHashToKeep] = runTimeData; var semiStableHashToDrop = 1; table[semiStableHashToDrop] = runTimeData; var stream = new MemoryStream(); for (int i = 0; i < PipHistoricPerfData.DefaultTimeToLive; i++) { stream.Position = 0; table.Save(stream); stream.Position = 0; table = PipRuntimeTimeTable.Load(stream); Analysis.IgnoreResult(table[semiStableHashToKeep]); } stream.Position = 0; table = PipRuntimeTimeTable.Load(stream); XAssert.AreEqual(1u, table[semiStableHashToKeep].DurationInMs); XAssert.AreEqual(0u, table[semiStableHashToDrop].DurationInMs); }