Пример #1
0
        public void JobsShouldFireWithHighPrecisionHeartbeat()
        {
            using (var manager = new JobManager())
            {
                var did_run = false;
                manager.Initialize();
                var job = new Mocks.MockFastJob(everyMilliseconds: JobManager.HIGH_PRECISION_HEARTBEAT_INTERVAL_MSEC * 2, action: (token) =>
                {
                    did_run = true;
                });
                manager.LoadJobInstance(job);
                manager.EnableHighPrecisionHeartbeat = true;
                manager.Start();

                var elapsed = Utility.Threading.BlockUntil(() => did_run, JobManager.HIGH_PRECISION_HEARTBEAT_INTERVAL_MSEC * 3);
                Assert.True(did_run);
                Assert.True(elapsed <= JobManager.HIGH_PRECISION_HEARTBEAT_INTERVAL_MSEC * 5);
            }
        }
Пример #2
0
        public void JobFiringShouldRespectSchedule()
        {
            var RUN_COUNT     = 10;
            var JOB_INTERVAL  = JobManager.HIGH_PRECISION_HEARTBEAT_INTERVAL_MSEC * 5;
            var EXPECTED_TIME = JOB_INTERVAL * RUN_COUNT;
            var MAXIMUM_TIME  = JOB_INTERVAL * (RUN_COUNT + 1);

            using (var manager = new JobManager())
            {
                var runtimes       = new List <DateTime>();
                var complete_times = new List <DateTime>();
                manager.Initialize();
                manager.EnableHighPrecisionHeartbeat = true;

                var job = new Mocks.MockFastJob(everyMilliseconds: JOB_INTERVAL, action: (token) =>
                {
                    runtimes.Add(DateTime.UtcNow);
                });

                job.Complete += (sender, event_args) =>
                {
                    complete_times.Add(DateTime.UtcNow);
                };

                manager.LoadJobInstance(job);
                manager.Start();

                var elapsed = Utility.Threading.BlockUntil(() => runtimes.Count == RUN_COUNT, timeout: MAXIMUM_TIME);

                //stop processing new events ...
                manager.Standby();
                var diff_from_expected = Math.Abs(elapsed - EXPECTED_TIME);

                Assert.True(diff_from_expected < JobManager.HIGH_PRECISION_HEARTBEAT_INTERVAL_MSEC);
                Assert.Equal(RUN_COUNT, runtimes.Count);
                Assert.Equal(RUN_COUNT, complete_times.Count);
            }
        }