Commit 7cf358ea authored by Nick Craver's avatar Nick Craver

Tests: enforce Naming in Release, and without the attribute

As we go for green on the test suite, we'll want this checked in PRs and such. And in general DEBUG and RELEASE not matching is becoming a pain. Trying to minimize the differences.
parent 6f746c6f
...@@ -185,25 +185,27 @@ public void CheckSyncAsyncMethodsMatch(Type from, Type to) ...@@ -185,25 +185,27 @@ public void CheckSyncAsyncMethodsMatch(Type from, Type to)
Log("Validated: {0} ({1} methods)", from.Name, count); Log("Validated: {0} ({1} methods)", from.Name, count);
} }
private static readonly Type ignoreType = typeof(ConnectionMultiplexer).Assembly.GetType("StackExchange.Redis.IgnoreNamePrefixAttribute");
private void CheckMethod(MethodInfo method, bool isAsync) private void CheckMethod(MethodInfo method, bool isAsync)
{ {
#if DEBUG string shortName = method.Name, fullName = method.DeclaringType.Name + "." + shortName;
bool ignorePrefix = ignoreType != null && Attribute.IsDefined(method, ignoreType);
if (ignorePrefix) switch (shortName)
{
Attribute attrib = Attribute.GetCustomAttribute(method, ignoreType);
if ((bool)attrib.GetType().GetProperty("IgnoreEntireMethod").GetValue(attrib))
{ {
case nameof(IDatabaseAsync.IsConnected):
return; return;
} case nameof(IDatabase.CreateBatch):
} case nameof(IDatabase.CreateTransaction):
string shortName = method.Name, fullName = method.DeclaringType.Name + "." + shortName; case nameof(IDatabase.IdentifyEndpoint):
case nameof(IDatabase.Sort):
case nameof(IDatabase.SortAndStore):
case nameof(IDatabaseAsync.IdentifyEndpointAsync):
case nameof(IDatabaseAsync.SortAsync):
case nameof(IDatabaseAsync.SortAndStoreAsync):
CheckName(method, isAsync); CheckName(method, isAsync);
if (!ignorePrefix) break;
{ default:
Assert.True( CheckName(method, isAsync);
shortName.StartsWith("Debug") var isValid = shortName.StartsWith("Debug")
|| shortName.StartsWith("Execute") || shortName.StartsWith("Execute")
|| shortName.StartsWith("Geo") || shortName.StartsWith("Geo")
|| shortName.StartsWith("Hash") || shortName.StartsWith("Hash")
...@@ -216,8 +218,10 @@ private void CheckMethod(MethodInfo method, bool isAsync) ...@@ -216,8 +218,10 @@ private void CheckMethod(MethodInfo method, bool isAsync)
|| shortName.StartsWith("Script") || shortName.StartsWith("Script")
|| shortName.StartsWith("SortedSet") || shortName.StartsWith("SortedSet")
|| shortName.StartsWith("String") || shortName.StartsWith("String")
|| shortName.StartsWith("Stream") || shortName.StartsWith("Stream");
, fullName + ":Prefix"); Log(fullName + ": " + (isValid ? "valid" : "invalid"));
Assert.True(isValid, fullName + ":Prefix");
break;
} }
Assert.False(shortName.Contains("If"), fullName + ":If"); // should probably be a When option Assert.False(shortName.Contains("If"), fullName + ":If"); // should probably be a When option
...@@ -231,7 +235,6 @@ private void CheckMethod(MethodInfo method, bool isAsync) ...@@ -231,7 +235,6 @@ private void CheckMethod(MethodInfo method, bool isAsync)
{ {
Assert.False(typeof(Task).IsAssignableFrom(returnType), fullName + ":Task"); Assert.False(typeof(Task).IsAssignableFrom(returnType), fullName + ":Task");
} }
#endif
} }
private void CheckName(MemberInfo member, bool isAsync) private void CheckName(MemberInfo member, bool isAsync)
......
...@@ -20,7 +20,6 @@ public interface IDatabase : IRedis, IDatabaseAsync ...@@ -20,7 +20,6 @@ public interface IDatabase : IRedis, IDatabaseAsync
/// </summary> /// </summary>
/// <param name="asyncState">The async object state to be passed into the created <see cref="IBatch"/>.</param> /// <param name="asyncState">The async object state to be passed into the created <see cref="IBatch"/>.</param>
/// <returns>The created batch.</returns> /// <returns>The created batch.</returns>
[IgnoreNamePrefix]
IBatch CreateBatch(object asyncState = null); IBatch CreateBatch(object asyncState = null);
/// <summary> /// <summary>
...@@ -29,7 +28,6 @@ public interface IDatabase : IRedis, IDatabaseAsync ...@@ -29,7 +28,6 @@ public interface IDatabase : IRedis, IDatabaseAsync
/// </summary> /// </summary>
/// <param name="asyncState">The async object state to be passed into the created <see cref="ITransaction"/>.</param> /// <param name="asyncState">The async object state to be passed into the created <see cref="ITransaction"/>.</param>
/// <returns>The created transaction.</returns> /// <returns>The created transaction.</returns>
[IgnoreNamePrefix]
ITransaction CreateTransaction(object asyncState = null); ITransaction CreateTransaction(object asyncState = null);
/// <summary> /// <summary>
...@@ -422,7 +420,6 @@ public interface IDatabase : IRedis, IDatabaseAsync ...@@ -422,7 +420,6 @@ public interface IDatabase : IRedis, IDatabaseAsync
/// <param name="key">The key to check.</param> /// <param name="key">The key to check.</param>
/// <param name="flags">The flags to use for this operation.</param> /// <param name="flags">The flags to use for this operation.</param>
/// <returns>The endpoint serving the key.</returns> /// <returns>The endpoint serving the key.</returns>
[IgnoreNamePrefix]
EndPoint IdentifyEndpoint(RedisKey key = default(RedisKey), CommandFlags flags = CommandFlags.None); EndPoint IdentifyEndpoint(RedisKey key = default(RedisKey), CommandFlags flags = CommandFlags.None);
/// <summary> /// <summary>
...@@ -1073,7 +1070,6 @@ public interface IDatabase : IRedis, IDatabaseAsync ...@@ -1073,7 +1070,6 @@ public interface IDatabase : IRedis, IDatabaseAsync
/// <param name="flags">The flags to use for this operation.</param> /// <param name="flags">The flags to use for this operation.</param>
/// <returns>The sorted elements, or the external values if <c>get</c> is specified.</returns> /// <returns>The sorted elements, or the external values if <c>get</c> is specified.</returns>
/// <remarks>https://redis.io/commands/sort</remarks> /// <remarks>https://redis.io/commands/sort</remarks>
[IgnoreNamePrefix]
RedisValue[] Sort(RedisKey key, long skip = 0, long take = -1, Order order = Order.Ascending, SortType sortType = SortType.Numeric, RedisValue by = default(RedisValue), RedisValue[] get = null, CommandFlags flags = CommandFlags.None); RedisValue[] Sort(RedisKey key, long skip = 0, long take = -1, Order order = Order.Ascending, SortType sortType = SortType.Numeric, RedisValue by = default(RedisValue), RedisValue[] get = null, CommandFlags flags = CommandFlags.None);
/// <summary> /// <summary>
...@@ -1094,7 +1090,6 @@ public interface IDatabase : IRedis, IDatabaseAsync ...@@ -1094,7 +1090,6 @@ public interface IDatabase : IRedis, IDatabaseAsync
/// <param name="flags">The flags to use for this operation.</param> /// <param name="flags">The flags to use for this operation.</param>
/// <returns>The number of elements stored in the new list.</returns> /// <returns>The number of elements stored in the new list.</returns>
/// <remarks>https://redis.io/commands/sort</remarks> /// <remarks>https://redis.io/commands/sort</remarks>
[IgnoreNamePrefix]
long SortAndStore(RedisKey destination, RedisKey key, long skip = 0, long take = -1, Order order = Order.Ascending, SortType sortType = SortType.Numeric, RedisValue by = default(RedisValue), RedisValue[] get = null, CommandFlags flags = CommandFlags.None); long SortAndStore(RedisKey destination, RedisKey key, long skip = 0, long take = -1, Order order = Order.Ascending, SortType sortType = SortType.Numeric, RedisValue by = default(RedisValue), RedisValue[] get = null, CommandFlags flags = CommandFlags.None);
/// <summary> /// <summary>
......
...@@ -16,7 +16,6 @@ public interface IDatabaseAsync : IRedisAsync ...@@ -16,7 +16,6 @@ public interface IDatabaseAsync : IRedisAsync
/// </summary> /// </summary>
/// <param name="key">The key to check for.</param> /// <param name="key">The key to check for.</param>
/// <param name="flags">The flags to use for this operation.</param> /// <param name="flags">The flags to use for this operation.</param>
[IgnoreNamePrefix(true)]
bool IsConnected(RedisKey key, CommandFlags flags = CommandFlags.None); bool IsConnected(RedisKey key, CommandFlags flags = CommandFlags.None);
/// <summary> /// <summary>
...@@ -385,7 +384,6 @@ public interface IDatabaseAsync : IRedisAsync ...@@ -385,7 +384,6 @@ public interface IDatabaseAsync : IRedisAsync
/// <param name="key">The key to check.</param> /// <param name="key">The key to check.</param>
/// <param name="flags">The flags to use for this operation.</param> /// <param name="flags">The flags to use for this operation.</param>
/// <returns>The endpoint serving the key.</returns> /// <returns>The endpoint serving the key.</returns>
[IgnoreNamePrefix]
Task<EndPoint> IdentifyEndpointAsync(RedisKey key = default(RedisKey), CommandFlags flags = CommandFlags.None); Task<EndPoint> IdentifyEndpointAsync(RedisKey key = default(RedisKey), CommandFlags flags = CommandFlags.None);
/// <summary> /// <summary>
...@@ -1012,7 +1010,6 @@ public interface IDatabaseAsync : IRedisAsync ...@@ -1012,7 +1010,6 @@ public interface IDatabaseAsync : IRedisAsync
/// <param name="flags">The flags to use for this operation.</param> /// <param name="flags">The flags to use for this operation.</param>
/// <returns>The sorted elements, or the external values if <c>get</c> is specified.</returns> /// <returns>The sorted elements, or the external values if <c>get</c> is specified.</returns>
/// <remarks>https://redis.io/commands/sort</remarks> /// <remarks>https://redis.io/commands/sort</remarks>
[IgnoreNamePrefix]
Task<RedisValue[]> SortAsync(RedisKey key, long skip = 0, long take = -1, Order order = Order.Ascending, SortType sortType = SortType.Numeric, RedisValue by = default(RedisValue), RedisValue[] get = null, CommandFlags flags = CommandFlags.None); Task<RedisValue[]> SortAsync(RedisKey key, long skip = 0, long take = -1, Order order = Order.Ascending, SortType sortType = SortType.Numeric, RedisValue by = default(RedisValue), RedisValue[] get = null, CommandFlags flags = CommandFlags.None);
/// <summary> /// <summary>
...@@ -1033,7 +1030,6 @@ public interface IDatabaseAsync : IRedisAsync ...@@ -1033,7 +1030,6 @@ public interface IDatabaseAsync : IRedisAsync
/// <param name="flags">The flags to use for this operation.</param> /// <param name="flags">The flags to use for this operation.</param>
/// <returns>The number of elements stored in the new list.</returns> /// <returns>The number of elements stored in the new list.</returns>
/// <remarks>https://redis.io/commands/sort</remarks> /// <remarks>https://redis.io/commands/sort</remarks>
[IgnoreNamePrefix]
Task<long> SortAndStoreAsync(RedisKey destination, RedisKey key, long skip = 0, long take = -1, Order order = Order.Ascending, SortType sortType = SortType.Numeric, RedisValue by = default(RedisValue), RedisValue[] get = null, CommandFlags flags = CommandFlags.None); Task<long> SortAndStoreAsync(RedisKey destination, RedisKey key, long skip = 0, long take = -1, Order order = Order.Ascending, SortType sortType = SortType.Numeric, RedisValue by = default(RedisValue), RedisValue[] get = null, CommandFlags flags = CommandFlags.None);
/// <summary> /// <summary>
......
using System; using System;
using System.Diagnostics; using System.Diagnostics;
namespace StackExchange.Redis namespace StackExchange.Redis
...@@ -16,16 +16,4 @@ public partial interface IRedis : IRedisAsync ...@@ -16,16 +16,4 @@ public partial interface IRedis : IRedisAsync
/// <remarks>https://redis.io/commands/ping</remarks> /// <remarks>https://redis.io/commands/ping</remarks>
TimeSpan Ping(CommandFlags flags = CommandFlags.None); TimeSpan Ping(CommandFlags flags = CommandFlags.None);
} }
[Conditional("DEBUG")]
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
internal class IgnoreNamePrefixAttribute : Attribute
{
public IgnoreNamePrefixAttribute(bool ignoreEntireMethod = false)
{
IgnoreEntireMethod = ignoreEntireMethod;
}
public bool IgnoreEntireMethod { get; }
}
} }
...@@ -15,7 +15,6 @@ public interface ISubscriber : IRedis ...@@ -15,7 +15,6 @@ public interface ISubscriber : IRedis
/// </summary> /// </summary>
/// <param name="channel">The channel to identify the server endpoint by.</param> /// <param name="channel">The channel to identify the server endpoint by.</param>
/// <param name="flags">The command flags to use.</param> /// <param name="flags">The command flags to use.</param>
[IgnoreNamePrefix]
EndPoint IdentifyEndpoint(RedisChannel channel, CommandFlags flags = CommandFlags.None); EndPoint IdentifyEndpoint(RedisChannel channel, CommandFlags flags = CommandFlags.None);
/// <summary> /// <summary>
...@@ -23,7 +22,6 @@ public interface ISubscriber : IRedis ...@@ -23,7 +22,6 @@ public interface ISubscriber : IRedis
/// </summary> /// </summary>
/// <param name="channel">The channel to identify the server endpoint by.</param> /// <param name="channel">The channel to identify the server endpoint by.</param>
/// <param name="flags">The command flags to use.</param> /// <param name="flags">The command flags to use.</param>
[IgnoreNamePrefix]
Task<EndPoint> IdentifyEndpointAsync(RedisChannel channel, CommandFlags flags = CommandFlags.None); Task<EndPoint> IdentifyEndpointAsync(RedisChannel channel, CommandFlags flags = CommandFlags.None);
/// <summary> /// <summary>
...@@ -100,7 +98,6 @@ public interface ISubscriber : IRedis ...@@ -100,7 +98,6 @@ public interface ISubscriber : IRedis
/// the channel is not actively subscribed /// the channel is not actively subscribed
/// </summary> /// </summary>
/// <param name="channel">The channel to check which server endpoint was subscribed on.</param> /// <param name="channel">The channel to check which server endpoint was subscribed on.</param>
[IgnoreNamePrefix]
EndPoint SubscribedEndpoint(RedisChannel channel); EndPoint SubscribedEndpoint(RedisChannel channel);
/// <summary> /// <summary>
......
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