Skip to content

Commit 11c8784

Browse files
committed
some clean up and test execution optimization
1 parent 325ad13 commit 11c8784

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

tests/NRedisStack.Tests/RedisFixture.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,12 @@ public class RedisFixture : IDisposable
5252
public bool isEnterprise = Environment.GetEnvironmentVariable("IS_ENTERPRISE") == "true";
5353
public bool isOSSCluster;
5454

55+
private ConnectionMultiplexer redis;
56+
private ConfigurationOptions defaultConfig;
57+
5558
public RedisFixture()
5659
{
57-
ConfigurationOptions clusterConfig = new ConfigurationOptions
60+
defaultConfig = new ConfigurationOptions
5861
{
5962
AsyncTimeout = 10000,
6063
SyncTimeout = 10000
@@ -93,16 +96,21 @@ public RedisFixture()
9396
isOSSCluster = true;
9497
}
9598
}
96-
97-
Redis = GetConnectionById(clusterConfig, defaultEndpointId);
9899
}
99100

100101
public void Dispose()
101102
{
102103
Redis.Close();
103104
}
104105

105-
public ConnectionMultiplexer Redis { get; }
106+
public ConnectionMultiplexer Redis
107+
{
108+
get
109+
{
110+
redis = redis ?? GetConnectionById(defaultConfig, defaultEndpointId);
111+
return redis;
112+
}
113+
}
106114

107115
public ConnectionMultiplexer GetConnectionById(ConfigurationOptions configurationOptions, string id)
108116
{

tests/NRedisStack.Tests/SkipIfRedisAttribute.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ public class SkipIfRedisAttribute : FactAttribute
2121
private readonly Comparison _comparison;
2222
private readonly List<Is> _environments = new List<Is>();
2323

24+
private static Version serverVersion = null;
25+
2426
public SkipIfRedisAttribute(
2527
Is environment,
2628
Comparison comparison = Comparison.LessThan,
@@ -95,7 +97,7 @@ public override string? Skip
9597
}
9698
// Version check (if Is.Standalone/Is.OSSCluster is set then )
9799

98-
var serverVersion = redisFixture.Redis.GetServer(redisFixture.Redis.GetEndPoints()[0]).Version;
100+
serverVersion = serverVersion ?? redisFixture.Redis.GetServer(redisFixture.Redis.GetEndPoints()[0]).Version;
99101
var targetVersion = new Version(_targetVersion);
100102
int comparisonResult = serverVersion.CompareTo(targetVersion);
101103

tests/NRedisStack.Tests/TokenBasedAuthentication/AuthenticationTests.cs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,12 @@ public AuthenticationTests(RedisFixture redisFixture) : base(redisFixture) { }
1818
[TargetEnvironment("standalone-entraid-acl")]
1919
public void TestTokenBasedAuthentication()
2020
{
21-
Assert.True(new FaultInjectorClient().TriggerActionAsync("enable_entraid", new Dictionary<string, object>()).Wait(5000), "Entraid could not be enabled this time!!!");
22-
// NOTE: ConnectionMultiplexer instances should be as long-lived as possible. Ideally a single ConnectionMultiplexer per cache is reused over the lifetime of the client application process.
23-
ConnectionMultiplexer? connectionMultiplexer = null;
24-
// StringWriter connectionLog = new();
2521

2622
var configurationOptions = new ConfigurationOptions().ConfigureForAzureWithTokenCredentialAsync(new DefaultAzureCredential()).Result!;
2723
configurationOptions.Ssl = false;
2824
configurationOptions.AbortOnConnectFail = true; // Fail fast for the purposes of this sample. In production code, this should remain false to retry connections on startup
2925

30-
connectionMultiplexer = redisFixture.GetConnectionById(configurationOptions, "standalone-entraid-acl");
26+
ConnectionMultiplexer?connectionMultiplexer = redisFixture.GetConnectionById(configurationOptions, "standalone-entraid-acl");
3127

3228
IDatabase db = connectionMultiplexer.GetDatabase();
3329

@@ -53,11 +49,5 @@ public void TestTokenBasedAuthentication()
5349
Assert.Equal(1, res1.TotalResults);
5450
Assert.Equal(value, res1.Documents[0][field]);
5551
}
56-
57-
[Fact]
58-
public void DummyTest()
59-
{
60-
Assert.True(true);
61-
}
6252
}
6353
}

0 commit comments

Comments
 (0)