Skip to content

Commit

Permalink
Add extra debug information for Redis tests on timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
Turnerj committed Mar 2, 2021
1 parent 67deced commit fe16ffe
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
21 changes: 18 additions & 3 deletions tests/CacheTower.Tests/Extensions/Redis/RedisLockExtensionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,12 @@ await extension.WithRefreshAsync("TestKey",
() => new ValueTask<CacheEntry<int>>(cacheEntry), new CacheSettings(TimeSpan.FromDays(1)));

var succeedingTask = await Task.WhenAny(completionSource.Task, Task.Delay(TimeSpan.FromSeconds(10)));
Assert.AreEqual(completionSource.Task, succeedingTask, "Subscriber response took too long");
if (!succeedingTask.Equals(completionSource.Task))
{
RedisHelper.DebugInfo(connection);
Assert.Fail("Subscriber response took too long");
}

Assert.IsTrue(completionSource.Task.Result, "Subscribers were not notified about the refreshed value");
}

Expand Down Expand Up @@ -142,7 +147,12 @@ public async Task ObservedLockSingle()
await connection.GetSubscriber().PublishAsync("CacheTower.CacheLock", "TestKey");

var succeedingTask = await Task.WhenAny(refreshTask, Task.Delay(TimeSpan.FromSeconds(10)));
Assert.AreEqual(refreshTask, succeedingTask, "Refresh has timed out - something has gone very wrong");
if (!succeedingTask.Equals(refreshTask))
{
RedisHelper.DebugInfo(connection);
Assert.Fail("Refresh has timed out - something has gone very wrong");
}

cacheStackMock.Verify(c => c.GetAsync<int>("TestKey"), Times.Exactly(2), "Two checks to the cache stack are expected");
}

Expand Down Expand Up @@ -189,7 +199,12 @@ public async Task ObservedLockMultiple()

var whenAllRefreshesTask = Task.WhenAll(refreshTask1, refreshTask2);
var succeedingTask = await Task.WhenAny(whenAllRefreshesTask, Task.Delay(TimeSpan.FromSeconds(10)));
Assert.AreEqual(whenAllRefreshesTask, succeedingTask, "Refresh has timed out - something has gone very wrong");
if (!succeedingTask.Equals(whenAllRefreshesTask))
{
RedisHelper.DebugInfo(connection);
Assert.Fail("Refresh has timed out - something has gone very wrong");
}

cacheStackMock.Verify(c => c.GetAsync<int>("TestKey"), Times.Exactly(4), "Two checks to the cache stack are expected");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,12 @@ public async Task RemoteEvictionOccursOnLocalEviction()
await extensionOne.OnCacheEvictionAsync("TestKey");

var succeedingTask = await Task.WhenAny(completionSource.Task, Task.Delay(TimeSpan.FromSeconds(10)));
Assert.AreEqual(completionSource.Task, succeedingTask, "Subscriber response took too long");
if (!succeedingTask.Equals(completionSource.Task))
{
RedisHelper.DebugInfo(connection);
Assert.Fail("Subscriber response took too long");
}

Assert.IsTrue(completionSource.Task.Result, "Subscribers were not notified about the refreshed value");

await Task.Delay(500);
Expand Down Expand Up @@ -159,7 +164,12 @@ public async Task RemoteFlush()
await extensionOne.OnCacheFlushAsync();

var succeedingTask = await Task.WhenAny(completionSource.Task, Task.Delay(TimeSpan.FromSeconds(10)));
Assert.AreEqual(completionSource.Task, succeedingTask, "Subscriber response took too long");
if (!succeedingTask.Equals(completionSource.Task))
{
RedisHelper.DebugInfo(connection);
Assert.Fail("Subscriber response took too long");
}

Assert.IsTrue(completionSource.Task.Result, "Subscribers were not notified about the flush");

await Task.Delay(500);
Expand Down
7 changes: 7 additions & 0 deletions tests/CacheTower.Tests/Utils/RedisHelper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Threading.Tasks;
using StackExchange.Redis;
Expand All @@ -24,5 +25,11 @@ public static void FlushDatabase()
{
GetConnection().GetServer(Endpoint).FlushDatabase();
}

public static void DebugInfo(IConnectionMultiplexer connection)
{
Debug.WriteLine(connection.GetStatus());
Debug.WriteLine(connection.GetCounters().ToString());
}
}
}

0 comments on commit fe16ffe

Please sign in to comment.