Exemplo n.º 1
0
        public async Task JobCompletesWithoutForcedDelay_NoCancellationTokenAsync()
        {
            var job = new DelayingJob(TimeSpan.FromTicks(1));

            var jobCompleted = await JobHost.RunAsync(job);

            Assert.True(jobCompleted);
        }
Exemplo n.º 2
0
        public async Task ForceCancellingOfForeverJobAsync()
        {
            var job = new MyForever();

            var jobCompleted = await JobHost.RunAsync(job, TimeSpan.FromSeconds(1));

            Assert.False(jobCompleted);
        }
Exemplo n.º 3
0
        public async Task JobCompletesWithinAllowedTimeAsync()
        {
            var job = new DelayingJob(TimeSpan.FromSeconds(1));

            var jobCompleted = await JobHost.RunAsync(job, TimeSpan.FromSeconds(2));

            Assert.True(jobCompleted);
            Assert.True(job.Completed);
        }
Exemplo n.º 4
0
        public async Task ForceCancellingOfJobAsync()
        {
            var job = new DelayingJob(TimeSpan.FromSeconds(5));

            var jobCompleted = await JobHost.RunAsync(job, TimeSpan.FromSeconds(1));

            Assert.False(jobCompleted, "Job should not have completed due to auto cancelling.");
            Assert.False(job.Completed, "Job should not have completed due to auto cancelling.");
        }
Exemplo n.º 5
0
        public async Task DisposesWrappedJob()
        {
            var job          = new DisposableJob();
            var scheduledJob = new ScheduledJob <DisposableJob>(() => job, new FakeSchedule(2), NullLoggerFactory.Instance, Clock.DefaultClock);

            using (var cts = new CancellationTokenSource())
            {
                await JobHost.RunAsync(scheduledJob, TimeSpan.FromSeconds(3), cts.Token);
            }

            Assert.True(job.DisposedCalls > 0);
        }
Exemplo n.º 6
0
        public async Task SwallowsExceptionsInInnerJob()
        {
            var clock = Clock.DefaultClock;

            using (var cts = new CancellationTokenSource())
            {
                var job = new FakeFailingJob();

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

                await JobHost.RunAsync(scheduledJob, TimeSpan.FromSeconds(3), cts.Token);

                Assert.True(job.RunCallCount > 1);
            }
        }