11using System ;
2+ using System . Diagnostics ;
23using System . Threading . Tasks ;
34using Xunit ;
45
@@ -7,22 +8,35 @@ namespace StackExchange.Redis.Tests;
78[ RunPerProtocol ]
89public class KeyIdleTests ( ITestOutputHelper output , SharedConnectionFixture fixture ) : TestBase ( output , fixture )
910{
11+ // Target the standalone secure server (6381) rather than the default primary (6379).
12+ // OBJECT IDLETIME is reset via the value's LRU access clock, but Redis deliberately
13+ // suppresses that update while a save/AOF/replication-sync child is active (copy-on-write
14+ // avoidance). The default primary has a replica attached, and every replica full-sync forks
15+ // such a child; if one overlaps a touch/read in these tests, the idle time isn't reset and the
16+ // test flakes (observed on Windows CI). 6381 has no replica and no persistence, so no fork ever
17+ // suppresses the reset and the behaviour is deterministic. Overriding GetConfiguration here also
18+ // opts these tests out of the shared connection fixture, giving each a dedicated 6381 connection.
19+ protected override string GetConfiguration ( )
20+ => TestConfig . Current . SecureServerAndPort + ",password=" + TestConfig . Current . SecurePassword ;
21+
1022 [ Fact ]
1123 public async Task IdleTime ( )
1224 {
25+ SkipOnWindowsRelease ( "WSL exacerbates replication time" ) ;
1326 await using var conn = Create ( ) ;
1427
1528 RedisKey key = Me ( ) ;
1629 var db = conn . GetDatabase ( ) ;
1730 db . KeyDelete ( key , CommandFlags . FireAndForget ) ;
1831 db . StringSet ( key , "new value" , flags : CommandFlags . FireAndForget ) ;
32+ var timer = Stopwatch . StartNew ( ) ;
1933 await Task . Delay ( 2000 ) . ForAwait ( ) ;
2034 var idleTime = db . KeyIdleTime ( key ) ;
21- Assert . True ( idleTime > TimeSpan . Zero ) ;
35+ Assert . True ( idleTime > TimeSpan . Zero , $ "First check: { idleTime } should be > 0; elapsed: { timer . ElapsedMilliseconds } ms" ) ;
2236
2337 db . StringSet ( key , "new value2" , flags : CommandFlags . FireAndForget ) ;
2438 var idleTime2 = db . KeyIdleTime ( key ) ;
25- Assert . True ( idleTime2 < idleTime ) ;
39+ Assert . True ( idleTime2 < idleTime , $ "Second check: { idleTime2 } should be < { idleTime } ; elapsed: { timer . ElapsedMilliseconds } ms" ) ;
2640
2741 db . KeyDelete ( key ) ;
2842 var idleTime3 = db . KeyIdleTime ( key ) ;
@@ -32,18 +46,20 @@ public async Task IdleTime()
3246 [ Fact ]
3347 public async Task TouchIdleTime ( )
3448 {
49+ SkipOnWindowsRelease ( "WSL exacerbates replication time" ) ;
3550 await using var conn = Create ( require : RedisFeatures . v3_2_1 ) ;
3651
3752 RedisKey key = Me ( ) ;
3853 var db = conn . GetDatabase ( ) ;
3954 db . KeyDelete ( key , CommandFlags . FireAndForget ) ;
4055 db . StringSet ( key , "new value" , flags : CommandFlags . FireAndForget ) ;
56+ var timer = Stopwatch . StartNew ( ) ;
4157 await Task . Delay ( 2000 ) . ForAwait ( ) ;
4258 var idleTime = db . KeyIdleTime ( key ) ;
43- Assert . True ( idleTime > TimeSpan . Zero , "First check" ) ;
59+ Assert . True ( idleTime > TimeSpan . Zero , $ "First check: { idleTime } should be > 0; elapsed: { timer . ElapsedMilliseconds } ms ") ;
4460
45- Assert . True ( db . KeyTouch ( key ) , "Second check" ) ;
61+ Assert . True ( db . KeyTouch ( key ) , $ "Second check: should be True; elapsed: { timer . ElapsedMilliseconds } ms ") ;
4662 var idleTime1 = db . KeyIdleTime ( key ) ;
47- Assert . True ( idleTime1 < idleTime , "Third check" ) ;
63+ Assert . True ( idleTime1 < idleTime , $ "Third check: { idleTime1 } should be < { idleTime } ; elapsed: { timer . ElapsedMilliseconds } ms ") ;
4864 }
4965}
0 commit comments