Ejemplo n.º 1
0
        public async Task WaitsForScheduleBeforeRunningWrappedJob()
        {
            var clock = Clock.DefaultClock;

            using (var cts = new CancellationTokenSource())
            {
                var job = new FakeJob(cts, clock);

                var fakeSchedule = new FakeSchedule(2);
                var scheduledJob = new ScheduledJob <FakeJob>(() => job, fakeSchedule, NullLoggerFactory.Instance, clock);

                var timeBefore = clock.UtcNow;

                await Assert.ThrowsAsync <OperationCanceledException>(() => scheduledJob.RunAsync(cts.Token));

                Assert.True(job.RunTime.Subtract(timeBefore) >= TimeSpan.FromSeconds(2));
            }
        }