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(); } }
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); } }
public async Task QueueHangfire_BackgroundServer_Run() { using (var server = new TestBackgroundJobServer(FileSystem, ServiceHost.HangfireTest)) { const string testValue = "TestValue"; var hangFireJob = new HangfireJob(testValue); var jobIdString = BackgroundJob.Enqueue <IHangFireTestService>(service => service.ExecuteHangfireTestJobAsync(hangFireJob)); jobIdString.Should().NotBeNull(); var jobStatus = await JobQueueClient.WaitForJobToComplete(server.MonitoringApi, jobIdString, 30 * 1000, CancellationToken.None); jobStatus.State.Should().Be(JobState.Succeeded); server.DeleteBackgroundJob(jobIdString).Should().BeTrue(); } }
public async Task QueueHangfire_BackgroundServer_Run() { var builder = new ContainerBuilder(); builder.RegisterType <HangFireTestService>().As <IHangFireTestService>().InstancePerLifetimeScope(); GlobalConfiguration.Configuration.UseAutofacActivator(builder.Build()); var storage = new SQLiteStorage(GetConnectionString(FileSystem, ServiceHost.HangfireTest)); GlobalConfiguration.Configuration.UseStorage(storage); using (var server = new BackgroundJobServer()) { server.Should().NotBeNull(); var monitoringApi = storage.GetMonitoringApi(); monitoringApi.Should().NotBeNull().And.Subject.Should().BeAssignableTo <IMonitoringApi>(); const string testValue = "TestValue"; var hangFireJob = new HangfireJob(testValue); var jobIdString = BackgroundJob.Enqueue <IHangFireTestService>(service => service.ExecuteHangfireTestJobAsync(hangFireJob)); jobIdString.Should().NotBeNull(); int.TryParse(jobIdString, out var jobId).Should().BeTrue(); jobId.Should().BeGreaterThan(0); var jobStatus = await JobQueueClient.WaitForJobToComplete(monitoringApi, jobIdString, 30 * 1000, CancellationToken.None); jobStatus.State.Should().Be(JobState.Succeeded); } }