private void UseConnection(Action <RedisConnection> action) { using (var connection = new RedisConnection(RedisUtils.CreateClient())) { action(connection); } }
private static void UseConnection(Action <IRedisClient> action) { using (var redis = RedisUtils.CreateClient()) { action(redis); } }
public void Execute_EnqueuesTimedOutJobs_AndDeletesThemFromFetchedList() { using (var redis = RedisUtils.CreateClient()) { // Arrange redis.AddItemToSet("hangfire:queues", "my-queue"); redis.AddItemToList("hangfire:queue:my-queue:dequeued", "my-job"); redis.SetEntryInHash("hangfire:job:my-job", "Fetched", JobHelper.SerializeDateTime(DateTime.UtcNow.AddDays(-1))); var watcher = CreateWatcher(); // Act watcher.Execute(_cts.Token); // Assert Assert.Equal(0, redis.GetListCount("hangfire:queue:my-queue:dequeued")); var listEntry = redis.DequeueItemFromList("hangfire:queue:my-queue"); Assert.Equal("my-job", listEntry); var job = redis.GetAllEntriesFromHash("hangfire:job:my-job"); Assert.False(job.ContainsKey("Fetched")); } }
private void UseConnections(Action <IRedisClient, RedisConnection> action) { using (var redis = RedisUtils.CreateClient()) using (var connection = new RedisConnection(redis)) { action(redis, connection); } }
public override void Before(MethodInfo methodUnderTest) { Monitor.Enter(GlobalLock); using (var client = RedisUtils.CreateClient()) { client.FlushDb(); } }
public void Execute_MarksDequeuedJobAsChecked_IfItHasNoFetchedFlagSet() { using (var redis = RedisUtils.CreateClient()) { // Arrange redis.AddItemToSet("hangfire:queues", "my-queue"); redis.AddItemToList("hangfire:queue:my-queue:dequeued", "my-job"); var watcher = CreateWatcher(); // Act watcher.Execute(_cts.Token); Assert.NotNull(JobHelper.DeserializeNullableDateTime( redis.GetValueFromHash("hangfire:job:my-job", "Checked"))); } }
public void Execute_DoesNotEnqueueTimedOutByCheckedFlagJob_IfFetchedFlagSet() { using (var redis = RedisUtils.CreateClient()) { // Arrange redis.AddItemToSet("hangfire:queues", "my-queue"); redis.AddItemToList("hangfire:queue:my-queue:dequeued", "my-job"); redis.SetEntryInHash("hangfire:job:my-job", "Checked", JobHelper.SerializeDateTime(DateTime.UtcNow.AddDays(-1))); redis.SetEntryInHash("hangfire:job:my-job", "Fetched", JobHelper.SerializeDateTime(DateTime.UtcNow)); var watcher = CreateWatcher(); // Act watcher.Execute(_cts.Token); // Assert Assert.Equal(1, redis.GetListCount("hangfire:queue:my-queue:dequeued")); } }
public void Execute_EnqueuesCheckedAndTimedOutJob_IfNoFetchedFlagSet() { using (var redis = RedisUtils.CreateClient()) { // Arrange redis.AddItemToSet("hangfire:queues", "my-queue"); redis.AddItemToList("hangfire:queue:my-queue:dequeued", "my-job"); redis.SetEntryInHash("hangfire:job:my-job", "Checked", JobHelper.ToStringTimestamp(DateTime.UtcNow.AddDays(-1))); var watcher = CreateWatcher(); // Act watcher.Execute(_token); // Arrange Assert.Equal(0, redis.GetListCount("hangfire:queue:my-queue:dequeued")); Assert.Equal(1, redis.GetListCount("hangfire:queue:my-queue")); var job = redis.GetAllEntriesFromHash("hangfire:job:my-job"); Assert.False(job.ContainsKey("Checked")); } }
public RedisTest() { _redis = RedisUtils.CreateClient(); }