Exemplo n.º 1
0
        public void QueueHangfire_WaitForJobToComplete_ZeroTimeout()
        {
            using (var server = new TestBackgroundJobServer(FileSystem, ServiceHost.HangfireTest))
            {
                server.Should().NotBeNull();

                const string testValue = "TestValue";

                var hangFireJob = new HangfireJob(testValue);

                var jobIdString = BackgroundJob.Enqueue <IHangFireTestService>(service =>
                                                                               service.ExecuteHangfireInfiniteJobAsync(hangFireJob));

                CancellationTokenSource cts = new CancellationTokenSource();

                jobIdString.Should().NotBeNull();
                int.TryParse(jobIdString, out var jobId).Should().BeTrue();
                jobId.Should().BeGreaterThan(0);

                cts.CancelAfter(1000);

                var monitoringApi = server.MonitoringApi;

                Func <Task <JobStatus> > fx = async() =>
                                              await JobQueueClient.WaitForJobToComplete(monitoringApi, jobIdString, 500, cts.Token);

                fx.Should().Throw <TaskCanceledException>();

                BackgroundJob.Delete(jobIdString).Should().BeTrue();
            }
        }
Exemplo n.º 2
0
        public async Task QueueHangfire_WaitForJobToComplete_JobNotFound()
        {
            using (var server = new TestBackgroundJobServer(FileSystem, ServiceHost.HangfireTest))
            {
                server.Should().NotBeNull();

                var jobStatus = await JobQueueClient.WaitForJobToComplete(server.MonitoringApi, "-1", 30, CancellationToken.None);

                jobStatus.State.Should().Be(JobState.NotFound);
            }
        }