Skip to content

Commit

Permalink
Upgrade test infrastructure and use --wait for docker health
Browse files Browse the repository at this point in the history
  • Loading branch information
NickCraver committed Aug 17, 2024
1 parent f4b7800 commit e1c7640
Show file tree
Hide file tree
Showing 16 changed files with 33 additions and 26 deletions.
16 changes: 8 additions & 8 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@

<!-- Packages only used in the solution, upgrade at will -->
<PackageVersion Include="BenchmarkDotNet" Version="0.13.1" />
<PackageVersion Include="GitHubActionsTestLogger" Version="2.0.0-alpha" />
<PackageVersion Include="GitHubActionsTestLogger" Version="2.4.1" />
<PackageVersion Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="3.3.4" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.0" />
<PackageVersion Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.2" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="1.1.1" />
<PackageVersion Include="Nerdbank.GitVersioning" Version="3.4.255" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.1" />
<PackageVersion Include="NSubstitute" Version="5.0.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
<PackageVersion Include="Nerdbank.GitVersioning" Version="3.6.141" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<PackageVersion Include="NSubstitute" Version="5.1.0" />
<PackageVersion Include="StackExchange.Redis" Version="2.6.96" />
<PackageVersion Include="StyleCop.Analyzers" Version="1.2.0-beta.556" />
<!-- For binding redirect testing, main package gets this transitively -->
<PackageVersion Include="System.IO.Pipelines" Version="5.0.1" />
<PackageVersion Include="System.Runtime.Caching" Version="5.0.0" />
<PackageVersion Include="xunit" Version="2.5.0" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.0" />
<PackageVersion Include="xunit" Version="2.9.0" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public sealed class AzureMaintenanceEvent : ServerMaintenanceEvent
{
private const string PubSubChannelName = "AzureRedisEvents";

internal AzureMaintenanceEvent(string azureEvent)
internal AzureMaintenanceEvent(string? azureEvent)
{
if (azureEvent == null)
{
Expand Down
2 changes: 1 addition & 1 deletion src/StackExchange.Redis/ResultProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ internal sealed class ScriptLoadProcessor : ResultProcessor<byte[]>

private static readonly Regex sha1 = new Regex("^[0-9a-f]{40}$", RegexOptions.Compiled | RegexOptions.IgnoreCase);

internal static bool IsSHA1(string script) => script is not null && script.Length == SHA1Length && sha1.IsMatch(script);
internal static bool IsSHA1(string? script) => script is not null && script.Length == SHA1Length && sha1.IsMatch(script);

internal const int Sha1HashLength = 20;
internal static byte[] ParseSHA1(byte[] value)
Expand Down
6 changes: 3 additions & 3 deletions tests/RedisConfigs/.docker/Envoy/envoy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ static_resources:
enable_redirection: true
prefix_routes:
catch_all_route:
cluster: standalone_redis
cluster: cluster_redis
clusters:
- name: standalone_redis
- name: cluster_redis
connect_timeout: 1s
type: STRICT_DNS
dns_lookup_family: V4_ONLY
load_assignment:
cluster_name: standalone_redis
cluster_name: cluster_redis
endpoints:
- lb_endpoints:
- endpoint:
Expand Down
2 changes: 2 additions & 0 deletions tests/RedisConfigs/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ services:
context: .docker/Envoy
image: stackexchange/redis-tests-envoy:latest
platform: linux
healthcheck:
test: ["CMD-SHELL", "redis-cli -p 7015 ping | grep PONG"]
ports:
- 7015:7015
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public AzureMaintenanceEventTests(ITestOutputHelper output) : base(output) { }
[InlineData("NonSSLPort |", AzureNotificationType.Unknown, null, false, null, 0, 0)]
[InlineData("StartTimeInUTC|thisisthestart", AzureNotificationType.Unknown, null, false, null, 0, 0)]
[InlineData(null, AzureNotificationType.Unknown, null, false, null, 0, 0)]
public void TestAzureMaintenanceEventStrings(string message, AzureNotificationType expectedEventType, string expectedStart, bool expectedIsReplica, string expectedIP, int expectedSSLPort, int expectedNonSSLPort)
public void TestAzureMaintenanceEventStrings(string? message, AzureNotificationType expectedEventType, string? expectedStart, bool expectedIsReplica, string? expectedIP, int expectedSSLPort, int expectedNonSSLPort)
{
DateTime? expectedStartTimeUtc = null;
if (expectedStart != null && DateTime.TryParseExact(expectedStart, "s", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out DateTime startTimeUtc))
Expand Down
2 changes: 1 addition & 1 deletion tests/StackExchange.Redis.Tests/ClusterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ public void TransactionWithSameSlotKeys()
[InlineData(null, 100)]
[InlineData("abc", 10)]
[InlineData("abc", 100)]
public void Keys(string pattern, int pageSize)
public void Keys(string? pattern, int pageSize)
{
using var conn = Create(allowAdmin: true);

Expand Down
2 changes: 1 addition & 1 deletion tests/StackExchange.Redis.Tests/Issues/Issue2653.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ public class Issue2653
[InlineData("abc.def", "abc.def")]
[InlineData("abc d \t ef", "abc-d-ef")]
[InlineData(" abc\r\ndef\n", "abc-def")]
public void CheckLibraySanitization(string input, string expected)
public void CheckLibraySanitization(string? input, string expected)
=> Assert.Equal(expected, ServerEndPoint.ClientInfoSanitize(input));
}
2 changes: 1 addition & 1 deletion tests/StackExchange.Redis.Tests/PubSubTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ await UntilConditionAsync(
[InlineData(null, true, "d")]
[InlineData("", true, "e")]
[InlineData("Foo:", true, "f")]
public async Task TestBasicPubSub(string channelPrefix, bool wildCard, string breaker)
public async Task TestBasicPubSub(string? channelPrefix, bool wildCard, string breaker)
{
using var conn = Create(channelPrefix: channelPrefix, shared: false, log: Writer);

Expand Down
4 changes: 2 additions & 2 deletions tests/StackExchange.Redis.Tests/RespProtocolTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public async Task ConnectWithBrokenHello(string command, bool isResp3)
[InlineData("return { map = { a = 1, b = 2, c = 3 } }", RedisProtocol.Resp3, ResultType.Array, ResultType.Map, MAP_ABC, 6)]
[InlineData("return { set = { a = 1, b = 2, c = 3 } }", RedisProtocol.Resp3, ResultType.Array, ResultType.Set, SET_ABC, 6)]
[InlineData("return { double = 42 }", RedisProtocol.Resp3, ResultType.SimpleString, ResultType.Double, 42.0, 6)]
public async Task CheckLuaResult(string script, RedisProtocol protocol, ResultType resp2, ResultType resp3, object expected, int serverMin = 1)
public async Task CheckLuaResult(string script, RedisProtocol protocol, ResultType resp2, ResultType resp3, object? expected, int? serverMin = 1)
{
// note Lua does not appear to return RESP3 types in any scenarios
var muxer = Create(protocol: protocol);
Expand Down Expand Up @@ -313,7 +313,7 @@ public async Task CheckLuaResult(string script, RedisProtocol protocol, ResultTy
[InlineData("debug", RedisProtocol.Resp2, ResultType.Integer, ResultType.Integer, false, "protocol", "false")]
[InlineData("debug", RedisProtocol.Resp3, ResultType.Integer, ResultType.Boolean, false, "protocol", "false")]

public async Task CheckCommandResult(string command, RedisProtocol protocol, ResultType resp2, ResultType resp3, object expected, params object[] args)
public async Task CheckCommandResult(string command, RedisProtocol protocol, ResultType resp2, ResultType resp3, object? expected, params object[] args)
{
var muxer = Create(protocol: protocol);
var ep = muxer.GetServerEndPoint(muxer.GetEndPoints().Single());
Expand Down
2 changes: 1 addition & 1 deletion tests/StackExchange.Redis.Tests/ScriptingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@ public void ScriptWithKeyPrefixCompare()
[InlineData("$29c3804401b0727f70f73d4415e162400cbe57b", false)]
[InlineData("829c3804401b0727f70f73d4415e162400cbe57", false)]
[InlineData("829c3804401b0727f70f73d4415e162400cbe57bb", false)]
public void Sha1Detection(string candidate, bool isSha)
public void Sha1Detection(string? candidate, bool isSha)
{
Assert.Equal(isSha, ResultProcessor.ScriptLoadProcessor.IsSHA1(candidate));
}
Expand Down
2 changes: 1 addition & 1 deletion tests/StackExchange.Redis.Tests/SentinelFailoverTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class SentinelFailoverTests : SentinelBase
{
public SentinelFailoverTests(ITestOutputHelper output) : base(output) { }

[Fact]
[FactLongRunning]
public async Task ManagedPrimaryConnectionEndToEndWithFailoverTest()
{
var connectionString = $"{TestConfig.Current.SentinelServer}:{TestConfig.Current.SentinelPortA},serviceName={ServiceOptions.ServiceName},allowAdmin=true";
Expand Down
2 changes: 2 additions & 0 deletions tests/StackExchange.Redis.Tests/ServerSnapshotTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class ServerSnapshotTests
[Fact]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Assertions", "xUnit2012:Do not use boolean check to check if a value exists in a collection", Justification = "Explicit testing")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Assertions", "xUnit2013:Do not use equality check to check for collection size.", Justification = "Explicit testing")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Assertions", "xUnit2029:Do not use Empty() to check if a value does not exist in a collection", Justification = "Explicit testing")]
public void EmptyBehaviour()
{
var snapshot = ServerSnapshot.Empty;
Expand Down Expand Up @@ -52,6 +53,7 @@ public void EmptyBehaviour()
[InlineData(5, 3)]
[InlineData(5, 5)]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Assertions", "xUnit2012:Do not use boolean check to check if a value exists in a collection", Justification = "Explicit testing")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Assertions", "xUnit2029:Do not use Empty() to check if a value does not exist in a collection", Justification = "Explicit testing")]
public void NonEmptyBehaviour(int count, int replicaCount)
{
var snapshot = ServerSnapshot.Empty;
Expand Down
8 changes: 4 additions & 4 deletions tests/StackExchange.Redis.Tests/TransactionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public async Task BasicTranWithExistsCondition(bool demandKeyExists, bool keyExi
[InlineData("x", null, false, true)]
[InlineData(null, "y", false, true)]
[InlineData(null, null, false, false)]
public async Task BasicTranWithEqualsCondition(string expected, string value, bool expectEqual, bool expectTranResult)
public async Task BasicTranWithEqualsCondition(string? expected, string? value, bool expectEqual, bool expectTranResult)
{
using var conn = Create();

Expand Down Expand Up @@ -179,7 +179,7 @@ public async Task BasicTranWithHashExistsCondition(bool demandKeyExists, bool ke
[InlineData("x", null, false, true)]
[InlineData(null, "y", false, true)]
[InlineData(null, null, false, false)]
public async Task BasicTranWithHashEqualsCondition(string expected, string value, bool expectEqual, bool expectedTranResult)
public async Task BasicTranWithHashEqualsCondition(string? expected, string? value, bool expectEqual, bool expectedTranResult)
{
using var conn = Create();

Expand Down Expand Up @@ -290,7 +290,7 @@ public async Task BasicTranWithListExistsCondition(bool demandKeyExists, bool ke
[InlineData("x", null, false, true)]
[InlineData(null, "y", false, true)]
[InlineData(null, null, false, false)]
public async Task BasicTranWithListEqualsCondition(string expected, string value, bool expectEqual, bool expectTranResult)
public async Task BasicTranWithListEqualsCondition(string? expected, string? value, bool expectEqual, bool expectTranResult)
{
using var conn = Create();

Expand Down Expand Up @@ -357,7 +357,7 @@ public enum ComparisonType
[InlineData("", ComparisonType.GreaterThan, 0L, false)]
[InlineData(null, ComparisonType.GreaterThan, 1L, false)]
[InlineData(null, ComparisonType.GreaterThan, 0L, false)]
public async Task BasicTranWithStringLengthCondition(string value, ComparisonType type, long length, bool expectTranResult)
public async Task BasicTranWithStringLengthCondition(string? value, ComparisonType type, long length, bool expectTranResult)
{
using var conn = Create();

Expand Down
2 changes: 1 addition & 1 deletion tests/StackExchange.Redis.Tests/WithKeyPrefixTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void NullPrefixIsError_String()
[InlineData("abc")]
[InlineData("")]
[InlineData(null)]
public void NullDatabaseIsError(string prefix)
public void NullDatabaseIsError(string? prefix)
{
Assert.Throws<ArgumentNullException>(() =>
{
Expand Down
3 changes: 3 additions & 0 deletions tests/StackExchange.Redis.Tests/xunit.runner.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"methodDisplay": "classAndMethod",
"maxParallelThreads": 16,
"parallelizeAssembly": true,
"parallelizeTestCollections": true,
"parallelAlgorithm": "aggressive",
"diagnosticMessages": false,
"longRunningTestSeconds": 60
}

0 comments on commit e1c7640

Please sign in to comment.