-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #304 from dmitry-vychikov/feature/first-class-queue
First class queue support
- Loading branch information
Showing
4 changed files
with
69 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
tests/Hangfire.PostgreSql.Tests/FirstClassQueueFeatureSupportTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System.Threading; | ||
using Hangfire.PostgreSql.Tests.Utils; | ||
using Hangfire.Storage; | ||
using Hangfire.Storage.Monitoring; | ||
using Xunit; | ||
|
||
namespace Hangfire.PostgreSql.Tests; | ||
|
||
public class FirstClassQueueFeatureSupportTests | ||
{ | ||
public FirstClassQueueFeatureSupportTests() | ||
{ | ||
JobStorage.Current = new PostgreSqlStorage(ConnectionUtils.GetConnectionString()); | ||
} | ||
|
||
[Fact] | ||
public void HasFlag_ShouldReturnTrue_ForJobQueueProperty() | ||
{ | ||
bool supportJobQueueProperty = JobStorage.Current.HasFeature(JobStorageFeatures.JobQueueProperty); | ||
Assert.True(supportJobQueueProperty); | ||
} | ||
|
||
[Fact] | ||
[CleanDatabase] | ||
public void EnqueueJobWithSpecificQueue_ShouldEnqueueCorrectlyAndJobMustBeProcessedInThatQueue() | ||
{ | ||
BackgroundJob.Enqueue<TestJobs>("critical", job => job.Run("critical")); | ||
BackgroundJob.Enqueue<TestJobs>("offline", job => job.Run("offline")); | ||
|
||
BackgroundJobServer server = new(new BackgroundJobServerOptions() { | ||
Queues = new[] { "critical" }, | ||
}); | ||
|
||
Thread.Sleep(200); | ||
|
||
IMonitoringApi monitoringApi = JobStorage.Current.GetMonitoringApi(); | ||
|
||
JobList<EnqueuedJobDto> jobsInCriticalQueue = monitoringApi.EnqueuedJobs("critical", 0, 10); | ||
JobList<EnqueuedJobDto> jobsInOfflineQueue = monitoringApi.EnqueuedJobs("offline", 0, 10); | ||
|
||
Assert.Empty(jobsInCriticalQueue); //Job from 'critical' queue must be processed by the server | ||
Assert.NotEmpty(jobsInOfflineQueue); //Job from 'offline' queue must be left untouched because no server is processing it | ||
} | ||
} |