Commit e4ff06f7 authored by Nick Craver's avatar Nick Craver

DebugAids/Tests: remove a lot of #if DEBUG differences

parent 2c307067
...@@ -14,7 +14,6 @@ public class AsyncTests : TestBase ...@@ -14,7 +14,6 @@ public class AsyncTests : TestBase
protected override string GetConfiguration() => TestConfig.Current.MasterServerAndPort; protected override string GetConfiguration() => TestConfig.Current.MasterServerAndPort;
#if DEBUG // IRedisServerDebug and AllowConnect are only available if DEBUG is defined
[Fact] [Fact]
public void AsyncTasksReportFailureIfServerUnavailable() public void AsyncTasksReportFailureIfServerUnavailable()
{ {
...@@ -43,7 +42,6 @@ public void AsyncTasksReportFailureIfServerUnavailable() ...@@ -43,7 +42,6 @@ public void AsyncTasksReportFailureIfServerUnavailable()
Assert.StartsWith("No connection is available to service this operation: SADD " + key.ToString(), ex.Message); Assert.StartsWith("No connection is available to service this operation: SADD " + key.ToString(), ex.Message);
} }
} }
#endif
[Fact] [Fact]
public async Task AsyncTimeoutIsNoticed() public async Task AsyncTimeoutIsNoticed()
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
using Xunit; using Xunit;
using Xunit.Abstractions; using Xunit.Abstractions;
using System.Diagnostics; using System.Diagnostics;
using System.Threading;
namespace StackExchange.Redis.Tests namespace StackExchange.Redis.Tests
{ {
...@@ -310,8 +309,6 @@ public async Task TestQuit() ...@@ -310,8 +309,6 @@ public async Task TestQuit()
} }
} }
#if DEBUG
[Fact] [Fact]
public async Task TestSevered() public async Task TestSevered()
{ {
...@@ -332,7 +329,6 @@ public async Task TestSevered() ...@@ -332,7 +329,6 @@ public async Task TestSevered()
Assert.Equal(key, db.StringGet(key)); Assert.Equal(key, db.StringGet(key));
} }
} }
#endif
[Fact] [Fact]
public async Task IncrAsync() public async Task IncrAsync()
......
...@@ -11,7 +11,6 @@ public class ConnectingFailDetection : TestBase ...@@ -11,7 +11,6 @@ public class ConnectingFailDetection : TestBase
protected override string GetConfiguration() => TestConfig.Current.MasterServerAndPort + "," + TestConfig.Current.SlaveServerAndPort; protected override string GetConfiguration() => TestConfig.Current.MasterServerAndPort + "," + TestConfig.Current.SlaveServerAndPort;
#if DEBUG
[Fact] [Fact]
public async Task FastNoticesFailOnConnectingSyncComlpetion() public async Task FastNoticesFailOnConnectingSyncComlpetion()
{ {
...@@ -110,6 +109,5 @@ public async Task FastNoticesFailOnConnectingAsyncComlpetion() ...@@ -110,6 +109,5 @@ public async Task FastNoticesFailOnConnectingAsyncComlpetion()
ClearAmbientFailures(); ClearAmbientFailures();
} }
} }
#endif
} }
} }
...@@ -124,7 +124,7 @@ public void SocketFailureError() ...@@ -124,7 +124,7 @@ public void SocketFailureError()
Assert.False(true); // force fail Assert.False(true); // force fail
} }
} }
#if DEBUG // needs AllowConnect, which is DEBUG only
[Fact] [Fact]
public void AbortOnConnectFailFalseConnectTimeoutError() public void AbortOnConnectFailFalseConnectTimeoutError()
{ {
...@@ -172,7 +172,6 @@ public async Task CheckFailureRecovered() ...@@ -172,7 +172,6 @@ public async Task CheckFailureRecovered()
} }
} }
#endif
[Fact] [Fact]
public void TryGetAzureRoleInstanceIdNoThrow() public void TryGetAzureRoleInstanceIdNoThrow()
{ {
......
...@@ -34,7 +34,6 @@ public async Task ShutdownRaisesConnectionFailedAndRestore() ...@@ -34,7 +34,6 @@ public async Task ShutdownRaisesConnectionFailedAndRestore()
Assert.Equal(0, Interlocked.CompareExchange(ref restored, 0, 0)); Assert.Equal(0, Interlocked.CompareExchange(ref restored, 0, 0));
await Task.Delay(1).ForAwait(); // To make compiler happy in Release await Task.Delay(1).ForAwait(); // To make compiler happy in Release
#if DEBUG
conn.AllowConnect = false; conn.AllowConnect = false;
var server = conn.GetServer(TestConfig.Current.MasterServer, TestConfig.Current.MasterPort); var server = conn.GetServer(TestConfig.Current.MasterServer, TestConfig.Current.MasterPort);
...@@ -50,7 +49,6 @@ public async Task ShutdownRaisesConnectionFailedAndRestore() ...@@ -50,7 +49,6 @@ public async Task ShutdownRaisesConnectionFailedAndRestore()
await Task.Delay(1500).ForAwait(); await Task.Delay(1500).ForAwait();
Assert.Equal(2, Interlocked.CompareExchange(ref failed, 0, 0)); Assert.Equal(2, Interlocked.CompareExchange(ref failed, 0, 0));
Assert.Equal(2, Interlocked.CompareExchange(ref restored, 0, 0)); Assert.Equal(2, Interlocked.CompareExchange(ref restored, 0, 0));
#endif
watch.Stop(); watch.Stop();
} }
} }
......
...@@ -26,7 +26,7 @@ public void NullSnapshot() ...@@ -26,7 +26,7 @@ public void NullSnapshot()
var ex = ExceptionFactory.NoConnectionAvailable(true, true, new RedisCommand(), null, null, null); var ex = ExceptionFactory.NoConnectionAvailable(true, true, new RedisCommand(), null, null, null);
Assert.Null(ex.InnerException); Assert.Null(ex.InnerException);
} }
#if DEBUG // needs debug connection features
[Fact] [Fact]
public void MultipleEndpointsThrowConnectionException() public void MultipleEndpointsThrowConnectionException()
{ {
...@@ -98,6 +98,5 @@ public void ServerTakesPrecendenceOverSnapshot() ...@@ -98,6 +98,5 @@ public void ServerTakesPrecendenceOverSnapshot()
ClearAmbientFailures(); ClearAmbientFailures();
} }
} }
#endif
} }
} }
...@@ -36,6 +36,15 @@ public sealed partial class ConnectionMultiplexer : IConnectionMultiplexer, IDis ...@@ -36,6 +36,15 @@ public sealed partial class ConnectionMultiplexer : IConnectionMultiplexer, IDis
} }
#endif #endif
/// <summary>
/// For debugging: when not enabled, servers cannot connect
/// </summary>
internal volatile bool AllowConnect = true;
/// <summary>
/// For debugging: when not enabled, end-connect is silently ignored (to simulate a long-running connect)
/// </summary>
internal volatile bool IgnoreConnect;
/// <summary> /// <summary>
/// Provides a way of overriding the default Task Factory. If not set, it will use the default Task.Factory. /// Provides a way of overriding the default Task Factory. If not set, it will use the default Task.Factory.
/// Useful when top level code sets it's own factory which may interfere with Redis queries. /// Useful when top level code sets it's own factory which may interfere with Redis queries.
......
...@@ -4,43 +4,6 @@ ...@@ -4,43 +4,6 @@
namespace StackExchange.Redis namespace StackExchange.Redis
{ {
#if DEBUG
public partial class ConnectionMultiplexer
{
private volatile bool allowConnect = true,
ignoreConnect = false;
/// <summary>
/// For debugging; when not enabled, servers cannot connect
/// </summary>
public bool AllowConnect { get { return allowConnect; } set { allowConnect = value; } }
/// <summary>
/// For debugging; when not enabled, end-connect is silently ignored (to simulate a long-running connect)
/// </summary>
public bool IgnoreConnect { get { return ignoreConnect; } set { ignoreConnect = value; } }
}
internal partial class PhysicalConnection
{
partial void ShouldIgnoreConnect(ref bool ignore)
{
ignore = IgnoreConnect;
}
partial void OnDebugAbort()
{
var bridge = BridgeCouldBeNull;
if (bridge == null || !bridge.Multiplexer.AllowConnect)
{
throw new RedisConnectionException(ConnectionFailureType.InternalFailure, "debugging");
}
}
public bool IgnoreConnect => BridgeCouldBeNull?.Multiplexer?.IgnoreConnect ?? false;
}
#endif
internal static class PerfCounterHelper internal static class PerfCounterHelper
{ {
private static readonly object staticLock = new object(); private static readonly object staticLock = new object();
......
...@@ -11,17 +11,6 @@ namespace StackExchange.Redis ...@@ -11,17 +11,6 @@ namespace StackExchange.Redis
/// </summary> /// </summary>
public interface IConnectionMultiplexer public interface IConnectionMultiplexer
{ {
#if DEBUG
/// <summary>
/// For debugging; when not enabled, servers cannot connect
/// </summary>
bool AllowConnect { get; set; }
/// <summary>
/// For debugging; when not enabled, end-connect is silently ignored (to simulate a long-running connect)
/// </summary>
bool IgnoreConnect { get; set; }
#endif
/// <summary> /// <summary>
/// Gets the client-name that will be used on all new connections /// Gets the client-name that will be used on all new connections
/// </summary> /// </summary>
......
...@@ -116,9 +116,8 @@ internal async void BeginConnectAsync(TextWriter log) ...@@ -116,9 +116,8 @@ internal async void BeginConnectAsync(TextWriter log)
// Complete connection // Complete connection
try try
{ {
bool ignoreConnect = false; // If we're told to ignore connect, abort here
ShouldIgnoreConnect(ref ignoreConnect); if (BridgeCouldBeNull?.Multiplexer?.IgnoreConnect ?? false) return;
if (ignoreConnect) return;
await awaitable; // wait for the connect to complete or fail (will throw) await awaitable; // wait for the connect to complete or fail (will throw)
if (timeoutSource != null) if (timeoutSource != null)
...@@ -1261,7 +1260,16 @@ private void MatchResult(RawResult result) ...@@ -1261,7 +1260,16 @@ private void MatchResult(RawResult result)
partial void OnCloseEcho(); partial void OnCloseEcho();
partial void OnCreateEcho(); partial void OnCreateEcho();
partial void OnDebugAbort();
[Conditional("DEBUG")]
private void OnDebugAbort()
{
var bridge = BridgeCouldBeNull;
if (bridge == null || !bridge.Multiplexer.AllowConnect)
{
throw new RedisConnectionException(ConnectionFailureType.InternalFailure, "debugging");
}
}
partial void OnWrapForLogging(ref IDuplexPipe pipe, string name, SocketManager mgr); partial void OnWrapForLogging(ref IDuplexPipe pipe, string name, SocketManager mgr);
......
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