@@ -5,13 +5,16 @@ namespace VirtualClient.Actions
55{
66 using System ;
77 using System . Collections . Generic ;
8+ using System . Linq ;
89 using System . Net ;
10+ using System . Text ;
911 using System . Threading ;
1012 using System . Threading . Tasks ;
1113 using Microsoft . Extensions . DependencyInjection ;
1214 using Moq ;
1315 using NUnit . Framework ;
1416 using VirtualClient . Actions . Memtier ;
17+ using VirtualClient . Common ;
1518 using VirtualClient . Common . Telemetry ;
1619 using VirtualClient . Contracts ;
1720
@@ -21,13 +24,19 @@ public class RedisServerExecutorTests
2124 {
2225 private MockFixture fixture ;
2326 private DependencyPath mockRedisPackage ;
27+ private InMemoryProcess memoryProcess ;
2428
2529 [ SetUp ]
2630 public void SetupTests ( )
2731 {
2832 this . fixture = new MockFixture ( ) ;
2933 this . fixture . Setup ( PlatformID . Unix ) ;
30-
34+ this . memoryProcess = new InMemoryProcess
35+ {
36+ ExitCode = 0 ,
37+ OnStart = ( ) => true ,
38+ OnHasExited = ( ) => true
39+ } ;
3140 this . mockRedisPackage = new DependencyPath ( "redis" , this . fixture . GetPackagePath ( "redis" ) ) ;
3241
3342 this . fixture . Parameters = new Dictionary < string , IConvertible > ( )
@@ -83,6 +92,11 @@ public async Task RedisMemtierServerExecutorExecutesExpectedProcessWhenBindingTo
8392
8493 this . fixture . ProcessManager . OnCreateProcess = ( exe , arguments , workingDirectory ) =>
8594 {
95+ if ( arguments . Contains ( "redis-cli INFO SERVER" ) )
96+ {
97+ this . memoryProcess . StandardOutput = new ConcurrentBuffer ( new StringBuilder ( "redis_version:7.0.15" ) ) ;
98+ return this . memoryProcess ;
99+ }
86100 expectedCommands . Remove ( $ "{ exe } { arguments } ") ;
87101 return this . fixture . Process ;
88102 } ;
@@ -113,6 +127,11 @@ public async Task RedisMemtierServerExecutorExecutesExpectedProcessWhenBindingTo
113127
114128 this . fixture . ProcessManager . OnCreateProcess = ( exe , arguments , workingDirectory ) =>
115129 {
130+ if ( arguments . Contains ( "redis-cli INFO SERVER" ) )
131+ {
132+ this . memoryProcess . StandardOutput = new ConcurrentBuffer ( new StringBuilder ( "redis_version:7.0.15" ) ) ;
133+ return this . memoryProcess ;
134+ }
116135 expectedCommands . Remove ( $ "{ exe } { arguments } ") ;
117136 return this . fixture . Process ;
118137 } ;
@@ -140,6 +159,11 @@ public async Task RedisMemtierServerExecutorExecutesExpectedProcessWhenNotBindin
140159
141160 this . fixture . ProcessManager . OnCreateProcess = ( exe , arguments , workingDirectory ) =>
142161 {
162+ if ( arguments . Contains ( "redis-cli INFO SERVER" ) )
163+ {
164+ this . memoryProcess . StandardOutput = new ConcurrentBuffer ( new StringBuilder ( "redis_version:7.0.15" ) ) ;
165+ return this . memoryProcess ;
166+ }
143167 expectedCommands . Remove ( $ "{ exe } { arguments } ") ;
144168 return this . fixture . Process ;
145169 } ;
@@ -149,6 +173,37 @@ public async Task RedisMemtierServerExecutorExecutesExpectedProcessWhenNotBindin
149173 }
150174 }
151175
176+ [ Test ]
177+ public async Task RedisServerExecutorCapturesRedisVersionSuccessfully ( )
178+ {
179+ using ( var executor = new TestRedisServerExecutor ( this . fixture . Dependencies , this . fixture . Parameters ) )
180+ {
181+ this . fixture . ProcessManager . OnCreateProcess = ( command , arguments , workingDirectory ) =>
182+ {
183+ if ( arguments . Contains ( "redis-cli INFO SERVER" ) )
184+ {
185+ this . memoryProcess . StandardOutput = new ConcurrentBuffer ( new StringBuilder ( "redis_version:7.0.15" ) ) ;
186+ }
187+ return this . memoryProcess ;
188+ } ;
189+
190+ // Act
191+ await executor . ExecuteAsync ( CancellationToken . None ) ;
192+
193+ // Assert
194+ var messages = this . fixture . Logger . MessagesLogged ( $ "{ nameof ( TestRedisServerExecutor ) } .RedisVersionCaptured") ;
195+ Assert . IsNotEmpty ( messages , "Expected at least one log message indicating the Redis version was captured2." ) ;
196+ bool versionCapturedCorrectly = messages . Any ( msg =>
197+ {
198+ var eventContext = msg . Item3 as EventContext ;
199+ return eventContext != null &&
200+ eventContext . Properties . ContainsKey ( "redisVersion" ) &&
201+ eventContext . Properties [ "redisVersion" ] . ToString ( ) == "7.0.15" ;
202+ } ) ;
203+ Assert . IsTrue ( versionCapturedCorrectly , "The Redis version '7.0.15' was not captured correctly in the logs." ) ;
204+ }
205+ }
206+
152207 private class TestRedisServerExecutor : RedisServerExecutor
153208 {
154209 public TestRedisServerExecutor ( IServiceCollection services , IDictionary < string , IConvertible > parameters = null )
0 commit comments