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
protected override string GetConfiguration() => TestConfig.Current.MasterServerAndPort;
#if DEBUG // IRedisServerDebug and AllowConnect are only available if DEBUG is defined
[Fact]
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);
}
}
#endif
[Fact]
public async Task AsyncTimeoutIsNoticed()
......
......@@ -4,7 +4,6 @@
using Xunit;
using Xunit.Abstractions;
using System.Diagnostics;
using System.Threading;
namespace StackExchange.Redis.Tests
{
......@@ -310,8 +309,6 @@ public async Task TestQuit()
}
}
#if DEBUG
[Fact]
public async Task TestSevered()
{
......@@ -332,7 +329,6 @@ public async Task TestSevered()
Assert.Equal(key, db.StringGet(key));
}
}
#endif
[Fact]
public async Task IncrAsync()
......
......@@ -11,7 +11,6 @@ public class ConnectingFailDetection : TestBase
protected override string GetConfiguration() => TestConfig.Current.MasterServerAndPort + "," + TestConfig.Current.SlaveServerAndPort;
#if DEBUG
[Fact]
public async Task FastNoticesFailOnConnectingSyncComlpetion()
{
......@@ -110,6 +109,5 @@ public async Task FastNoticesFailOnConnectingAsyncComlpetion()
ClearAmbientFailures();
}
}
#endif
}
}
......@@ -124,7 +124,7 @@ public void SocketFailureError()
Assert.False(true); // force fail
}
}
#if DEBUG // needs AllowConnect, which is DEBUG only
[Fact]
public void AbortOnConnectFailFalseConnectTimeoutError()
{
......@@ -172,7 +172,6 @@ public async Task CheckFailureRecovered()
}
}
#endif
[Fact]
public void TryGetAzureRoleInstanceIdNoThrow()
{
......
......@@ -34,7 +34,6 @@ public async Task ShutdownRaisesConnectionFailedAndRestore()
Assert.Equal(0, Interlocked.CompareExchange(ref restored, 0, 0));
await Task.Delay(1).ForAwait(); // To make compiler happy in Release
#if DEBUG
conn.AllowConnect = false;
var server = conn.GetServer(TestConfig.Current.MasterServer, TestConfig.Current.MasterPort);
......@@ -50,7 +49,6 @@ public async Task ShutdownRaisesConnectionFailedAndRestore()
await Task.Delay(1500).ForAwait();
Assert.Equal(2, Interlocked.CompareExchange(ref failed, 0, 0));
Assert.Equal(2, Interlocked.CompareExchange(ref restored, 0, 0));
#endif
watch.Stop();
}
}
......
......@@ -26,7 +26,7 @@ public void NullSnapshot()
var ex = ExceptionFactory.NoConnectionAvailable(true, true, new RedisCommand(), null, null, null);
Assert.Null(ex.InnerException);
}
#if DEBUG // needs debug connection features
[Fact]
public void MultipleEndpointsThrowConnectionException()
{
......@@ -98,6 +98,5 @@ public void ServerTakesPrecendenceOverSnapshot()
ClearAmbientFailures();
}
}
#endif
}
}
......@@ -36,6 +36,15 @@ public sealed partial class ConnectionMultiplexer : IConnectionMultiplexer, IDis
}
#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>
/// 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.
......
......@@ -4,43 +4,6 @@
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
{
private static readonly object staticLock = new object();
......
......@@ -11,17 +11,6 @@ namespace StackExchange.Redis
/// </summary>
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>
/// Gets the client-name that will be used on all new connections
/// </summary>
......
......@@ -116,9 +116,8 @@ internal async void BeginConnectAsync(TextWriter log)
// Complete connection
try
{
bool ignoreConnect = false;
ShouldIgnoreConnect(ref ignoreConnect);
if (ignoreConnect) return;
// If we're told to ignore connect, abort here
if (BridgeCouldBeNull?.Multiplexer?.IgnoreConnect ?? false) return;
await awaitable; // wait for the connect to complete or fail (will throw)
if (timeoutSource != null)
......@@ -1261,7 +1260,16 @@ private void MatchResult(RawResult result)
partial void OnCloseEcho();
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);
......
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