public void RaceCondition() { var timeManager = new AlgorithmTimeLimitManager(TokenBucket.Null, TimeSpan.FromMinutes(1)); const int loops = 1000000; var task = Task.Factory.StartNew(() => { var count = 0; while (count++ < loops) { var result = timeManager.IsWithinLimit(); Assert.IsTrue(result.IsWithinCustomLimits, result.ErrorMessage); } }); var task2 = Task.Factory.StartNew(() => { var count = 0; while (count++ < loops) { timeManager.StartNewTimeStep(); } }); Task.WaitAll(task, task2); }
public void DuplicateScheduledEventsAreBothFired() { var algorithm = new QCAlgorithm(); var handler = new BacktestingRealTimeHandler(); var timeLimitManager = new AlgorithmTimeLimitManager(TokenBucket.Null, TimeSpan.MaxValue); handler.Setup(algorithm, new AlgorithmNodePacket(PacketType.BacktestNode), null, null, timeLimitManager); algorithm.Schedule.SetEventSchedule(handler); var time = new DateTime(2018, 1, 1); algorithm.SetDateTime(time); var count1 = 0; var count2 = 0; algorithm.Schedule.On(algorithm.Schedule.DateRules.EveryDay(), algorithm.Schedule.TimeRules.Every(TimeSpan.FromHours(1)), () => { count1++; }); algorithm.Schedule.On(algorithm.Schedule.DateRules.EveryDay(), algorithm.Schedule.TimeRules.Every(TimeSpan.FromHours(1)), () => { count2++; }); const int timeSteps = 12; for (var i = 0; i < timeSteps; i++) { handler.SetTime(time); time = time.AddHours(1); } Assert.AreEqual(timeSteps, count1); Assert.AreEqual(timeSteps, count2); }