Commit 5e5ffdca authored by Nick Craver's avatar Nick Craver

Tests: clean up debugging aids

parent da69bff8
...@@ -7,26 +7,20 @@ ...@@ -7,26 +7,20 @@
namespace StackExchange.Redis namespace StackExchange.Redis
{ {
#if DEBUG #if DEBUG
internal partial class ResultBox
partial class ResultBox
{ {
internal static long allocations; internal static long allocations;
public static long GetAllocationCount() => Interlocked.Read(ref allocations);
public static long GetAllocationCount() static partial void OnAllocated() => Interlocked.Increment(ref allocations);
{
return Interlocked.Read(ref allocations);
}
static partial void OnAllocated()
{
Interlocked.Increment(ref allocations);
}
} }
partial interface IServer
public partial interface IServer
{ {
/// <summary> /// <summary>
/// Show what is in the pending (unsent) queue /// Show what is in the pending (unsent) queue
/// </summary> /// </summary>
string ListPending(int maxCount); string ListPending(int maxCount);
/// <summary> /// <summary>
/// Get the value of key. If the key does not exist the special value nil is returned. An error is returned if the value stored at key is not a string, because GET only handles string values. /// Get the value of key. If the key does not exist the special value nil is returned. An error is returned if the value stored at key is not a string, because GET only handles string values.
/// </summary> /// </summary>
...@@ -58,7 +52,8 @@ partial interface IServer ...@@ -58,7 +52,8 @@ partial interface IServer
/// <remarks>http://redis.io/commands/client-pause</remarks> /// <remarks>http://redis.io/commands/client-pause</remarks>
void Hang(TimeSpan duration, CommandFlags flags = CommandFlags.None); void Hang(TimeSpan duration, CommandFlags flags = CommandFlags.None);
} }
partial interface IRedis
public partial interface IRedis
{ {
/// <summary> /// <summary>
/// The CLIENT GETNAME returns the name of the current connection as set by CLIENT SETNAME. Since every new connection starts without an associated name, if no name was assigned a null string is returned. /// The CLIENT GETNAME returns the name of the current connection as set by CLIENT SETNAME. Since every new connection starts without an associated name, if no name was assigned a null string is returned.
...@@ -74,7 +69,7 @@ partial interface IRedis ...@@ -74,7 +69,7 @@ partial interface IRedis
void Quit(CommandFlags flags = CommandFlags.None); void Quit(CommandFlags flags = CommandFlags.None);
} }
partial interface IRedisAsync public partial interface IRedisAsync
{ {
/// <summary> /// <summary>
/// The CLIENT GETNAME returns the name of the current connection as set by CLIENT SETNAME. Since every new connection starts without an associated name, if no name was assigned a null string is returned. /// The CLIENT GETNAME returns the name of the current connection as set by CLIENT SETNAME. Since every new connection starts without an associated name, if no name was assigned a null string is returned.
...@@ -83,7 +78,8 @@ partial interface IRedisAsync ...@@ -83,7 +78,8 @@ partial interface IRedisAsync
/// <returns>The connection name, or a null string if no name is set.</returns> /// <returns>The connection name, or a null string if no name is set.</returns>
Task<string> ClientGetNameAsync(CommandFlags flags = CommandFlags.None); Task<string> ClientGetNameAsync(CommandFlags flags = CommandFlags.None);
} }
partial class RedisBase
internal partial class RedisBase
{ {
string IRedis.ClientGetName(CommandFlags flags) string IRedis.ClientGetName(CommandFlags flags)
{ {
...@@ -98,9 +94,8 @@ Task<string> IRedisAsync.ClientGetNameAsync(CommandFlags flags) ...@@ -98,9 +94,8 @@ Task<string> IRedisAsync.ClientGetNameAsync(CommandFlags flags)
} }
} }
partial class ServerEndPoint internal partial class ServerEndPoint
{ {
internal void SimulateConnectionFailure() internal void SimulateConnectionFailure()
{ {
var tmp = interactive; var tmp = interactive;
...@@ -108,6 +103,7 @@ internal void SimulateConnectionFailure() ...@@ -108,6 +103,7 @@ internal void SimulateConnectionFailure()
tmp = subscription; tmp = subscription;
tmp?.SimulateConnectionFailure(); tmp?.SimulateConnectionFailure();
} }
internal string ListPending(int maxCount) internal string ListPending(int maxCount)
{ {
var sb = new StringBuilder(); var sb = new StringBuilder();
...@@ -119,22 +115,18 @@ internal string ListPending(int maxCount) ...@@ -119,22 +115,18 @@ internal string ListPending(int maxCount)
} }
} }
partial class RedisServer internal partial class RedisServer
{ {
void IServer.SimulateConnectionFailure() void IServer.SimulateConnectionFailure() => server.SimulateConnectionFailure();
{ string IServer.ListPending(int maxCount) => server.ListPending(maxCount);
server.SimulateConnectionFailure();
}
string IServer.ListPending(int maxCount)
{
return server.ListPending(maxCount);
}
void IServer.Crash() void IServer.Crash()
{ {
// using DB-0 because we also use "DEBUG OBJECT", which is db-centric // using DB-0 because we also use "DEBUG OBJECT", which is db-centric
var msg = Message.Create(0, CommandFlags.FireAndForget, RedisCommand.DEBUG, RedisLiterals.SEGFAULT); var msg = Message.Create(0, CommandFlags.FireAndForget, RedisCommand.DEBUG, RedisLiterals.SEGFAULT);
ExecuteSync(msg, ResultProcessor.DemandOK); ExecuteSync(msg, ResultProcessor.DemandOK);
} }
void IServer.Hang(TimeSpan duration, CommandFlags flags) void IServer.Hang(TimeSpan duration, CommandFlags flags)
{ {
var msg = Message.Create(-1, flags, RedisCommand.CLIENT, RedisLiterals.PAUSE, (long)duration.TotalMilliseconds); var msg = Message.Create(-1, flags, RedisCommand.CLIENT, RedisLiterals.PAUSE, (long)duration.TotalMilliseconds);
...@@ -142,7 +134,7 @@ void IServer.Hang(TimeSpan duration, CommandFlags flags) ...@@ -142,7 +134,7 @@ void IServer.Hang(TimeSpan duration, CommandFlags flags)
} }
} }
partial class CompletionManager internal partial class CompletionManager
{ {
private static long asyncCompletionWorkerCount; private static long asyncCompletionWorkerCount;
...@@ -156,7 +148,7 @@ internal static long GetAsyncCompletionWorkerCount() ...@@ -156,7 +148,7 @@ internal static long GetAsyncCompletionWorkerCount()
} }
} }
partial class ConnectionMultiplexer public partial class ConnectionMultiplexer
{ {
/// <summary> /// <summary>
/// Gets how many result-box instances were allocated /// Gets how many result-box instances were allocated
...@@ -184,7 +176,7 @@ public static long GetAsyncCompletionWorkerCount() ...@@ -184,7 +176,7 @@ public static long GetAsyncCompletionWorkerCount()
public bool IgnoreConnect { get { return ignoreConnect; } set { ignoreConnect = value; } } public bool IgnoreConnect { get { return ignoreConnect; } set { ignoreConnect = value; } }
} }
partial class SocketManager public partial class SocketManager
{ {
partial void ShouldIgnoreConnect(ISocketCallback callback, ref bool ignore) partial void ShouldIgnoreConnect(ISocketCallback callback, ref bool ignore)
{ {
...@@ -201,12 +193,13 @@ partial class SocketManager ...@@ -201,12 +193,13 @@ partial class SocketManager
completionType = SocketManager.ConnectCompletionType; completionType = SocketManager.ConnectCompletionType;
} }
} }
partial interface ISocketCallback
internal partial interface ISocketCallback
{ {
bool IgnoreConnect { get; } bool IgnoreConnect { get; }
} }
partial class MessageQueue internal partial class MessageQueue
{ {
internal void ListPending(StringBuilder sb, int maxCount) internal void ListPending(StringBuilder sb, int maxCount)
{ {
...@@ -228,7 +221,7 @@ internal void ListPending(StringBuilder sb, int maxCount) ...@@ -228,7 +221,7 @@ internal void ListPending(StringBuilder sb, int maxCount)
} }
} }
partial class PhysicalBridge internal partial class PhysicalBridge
{ {
internal void SimulateConnectionFailure() internal void SimulateConnectionFailure()
{ {
...@@ -238,13 +231,14 @@ internal void SimulateConnectionFailure() ...@@ -238,13 +231,14 @@ internal void SimulateConnectionFailure()
} }
physical?.RecordConnectionFailed(ConnectionFailureType.SocketFailure); physical?.RecordConnectionFailed(ConnectionFailureType.SocketFailure);
} }
internal void ListPending(StringBuilder sb, int maxCount) internal void ListPending(StringBuilder sb, int maxCount)
{ {
queue.ListPending(sb, maxCount); queue.ListPending(sb, maxCount);
} }
} }
partial class PhysicalConnection internal partial class PhysicalConnection
{ {
partial void OnDebugAbort() partial void OnDebugAbort()
{ {
...@@ -259,14 +253,8 @@ partial class PhysicalConnection ...@@ -259,14 +253,8 @@ partial class PhysicalConnection
private static volatile bool emulateStaleConnection; private static volatile bool emulateStaleConnection;
public static bool EmulateStaleConnection public static bool EmulateStaleConnection
{ {
get get => emulateStaleConnection;
{ set => emulateStaleConnection = value;
return emulateStaleConnection;
}
set
{
emulateStaleConnection = value;
}
} }
partial void DebugEmulateStaleConnection(ref int firstUnansweredWrite) partial void DebugEmulateStaleConnection(ref int firstUnansweredWrite)
...@@ -301,9 +289,9 @@ public enum CompletionType ...@@ -301,9 +289,9 @@ public enum CompletionType
internal static class PerfCounterHelper internal static class PerfCounterHelper
{ {
static object staticLock = new object(); private static readonly object staticLock = new object();
static volatile PerformanceCounter _cpu; private static volatile PerformanceCounter _cpu;
static volatile bool _disabled; private static volatile bool _disabled;
public static bool TryGetSystemCPU(out float value) public static bool TryGetSystemCPU(out float value)
{ {
...@@ -341,14 +329,12 @@ public static bool TryGetSystemCPU(out float value) ...@@ -341,14 +329,12 @@ public static bool TryGetSystemCPU(out float value)
value = _cpu.NextValue(); value = _cpu.NextValue();
return true; return true;
} }
return false; return false;
} }
} }
internal class CompletionTypeHelper internal static class CompletionTypeHelper
{ {
public static void RunWithCompletionType(Func<AsyncCallback, IAsyncResult> beginAsync, AsyncCallback callback, CompletionType completionType) public static void RunWithCompletionType(Func<AsyncCallback, IAsyncResult> beginAsync, AsyncCallback callback, CompletionType completionType)
{ {
AsyncCallback proxyCallback; AsyncCallback proxyCallback;
...@@ -379,15 +365,13 @@ public static void RunWithCompletionType(Func<AsyncCallback, IAsyncResult> begin ...@@ -379,15 +365,13 @@ public static void RunWithCompletionType(Func<AsyncCallback, IAsyncResult> begin
switch (completionType) switch (completionType)
{ {
case CompletionType.Async: case CompletionType.Async:
ThreadPool.QueueUserWorkItem((s) => { callback(result); }); ThreadPool.QueueUserWorkItem((s) => callback(result));
break; break;
case CompletionType.Any: case CompletionType.Any:
case CompletionType.Sync: case CompletionType.Sync:
callback(result); callback(result);
break; break;
} }
return;
} }
} }
#endif #endif
...@@ -419,7 +403,6 @@ partial class ConnectionMultiplexer ...@@ -419,7 +403,6 @@ partial class ConnectionMultiplexer
} }
#endif #endif
#if LOGOUTPUT #if LOGOUTPUT
partial class ConnectionMultiplexer partial class ConnectionMultiplexer
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment