@@ -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 > ( )
@@ -62,6 +71,17 @@ public async Task RedisServerExecutorConfirmsTheExpectedPackagesOnInitialization
6271 {
6372 using ( var component = new TestRedisServerExecutor ( this . fixture . Dependencies , this . fixture . Parameters ) )
6473 {
74+ this . fixture . ProcessManager . OnCreateProcess = ( command , arguments , workingDirectory ) =>
75+ {
76+ if ( arguments ? . Contains ( "redis-server" ) == true && arguments ? . Contains ( "--version" ) == true )
77+ {
78+ this . memoryProcess . StandardOutput = new ConcurrentBuffer (
79+ new StringBuilder ( "Redis server v=7.0.15 sha=00000000 malloc=jemalloc-5.1.0 bits=64 build=abc123" )
80+ ) ;
81+ return this . memoryProcess ;
82+ }
83+ return this . memoryProcess ;
84+ } ;
6585 await component . InitializeAsync ( EventContext . None , CancellationToken . None ) ;
6686 this . fixture . PackageManager . Verify ( mgr => mgr . GetPackageAsync ( this . mockRedisPackage . Name , It . IsAny < CancellationToken > ( ) ) ) ;
6787 }
@@ -83,6 +103,13 @@ public async Task RedisMemtierServerExecutorExecutesExpectedProcessWhenBindingTo
83103
84104 this . fixture . ProcessManager . OnCreateProcess = ( exe , arguments , workingDirectory ) =>
85105 {
106+ if ( arguments ? . Contains ( "redis-server" ) == true && arguments ? . Contains ( "--version" ) == true )
107+ {
108+ this . memoryProcess . StandardOutput = new ConcurrentBuffer (
109+ new StringBuilder ( "Redis server v=7.0.15 sha=00000000 malloc=jemalloc-5.1.0 bits=64 build=abc123" )
110+ ) ;
111+ return this . memoryProcess ;
112+ }
86113 expectedCommands . Remove ( $ "{ exe } { arguments } ") ;
87114 return this . fixture . Process ;
88115 } ;
@@ -113,6 +140,13 @@ public async Task RedisMemtierServerExecutorExecutesExpectedProcessWhenBindingTo
113140
114141 this . fixture . ProcessManager . OnCreateProcess = ( exe , arguments , workingDirectory ) =>
115142 {
143+ if ( arguments ? . Contains ( "redis-server" ) == true && arguments ? . Contains ( "--version" ) == true )
144+ {
145+ this . memoryProcess . StandardOutput = new ConcurrentBuffer (
146+ new StringBuilder ( "Redis server v=7.0.15 sha=00000000 malloc=jemalloc-5.1.0 bits=64 build=abc123" )
147+ ) ;
148+ return this . memoryProcess ;
149+ }
116150 expectedCommands . Remove ( $ "{ exe } { arguments } ") ;
117151 return this . fixture . Process ;
118152 } ;
@@ -140,6 +174,13 @@ public async Task RedisMemtierServerExecutorExecutesExpectedProcessWhenNotBindin
140174
141175 this . fixture . ProcessManager . OnCreateProcess = ( exe , arguments , workingDirectory ) =>
142176 {
177+ if ( arguments ? . Contains ( "redis-server" ) == true && arguments ? . Contains ( "--version" ) == true )
178+ {
179+ this . memoryProcess . StandardOutput = new ConcurrentBuffer (
180+ new StringBuilder ( "Redis server v=7.0.15 sha=00000000 malloc=jemalloc-5.1.0 bits=64 build=abc123" )
181+ ) ;
182+ return this . memoryProcess ;
183+ }
143184 expectedCommands . Remove ( $ "{ exe } { arguments } ") ;
144185 return this . fixture . Process ;
145186 } ;
@@ -149,6 +190,38 @@ public async Task RedisMemtierServerExecutorExecutesExpectedProcessWhenNotBindin
149190 }
150191 }
151192
193+ [ Test ]
194+ public async Task RedisServerExecutorCapturesRedisVersionSuccessfully ( )
195+ {
196+ using ( var executor = new TestRedisServerExecutor ( this . fixture . Dependencies , this . fixture . Parameters ) )
197+ {
198+ this . fixture . ProcessManager . OnCreateProcess = ( command , arguments , workingDirectory ) =>
199+ {
200+ if ( arguments ? . Contains ( "redis-server" ) == true && arguments ? . Contains ( "--version" ) == true )
201+ {
202+ this . memoryProcess . StandardOutput = new ConcurrentBuffer (
203+ new StringBuilder ( "Redis server v=7.0.15 sha=00000000 malloc=jemalloc-5.1.0 bits=64 build=abc123" )
204+ ) ;
205+ return this . memoryProcess ;
206+ }
207+ return this . memoryProcess ;
208+ } ;
209+ // Act
210+ await executor . InitializeAsync ( EventContext . None , CancellationToken . None ) ;
211+ // Assert
212+ var messages = this . fixture . Logger . MessagesLogged ( $ "{ nameof ( TestRedisServerExecutor ) } .RedisVersionCaptured") ;
213+ Assert . IsNotEmpty ( messages , "Expected at least one log message indicating the Redis version was captured." ) ;
214+ bool versionCapturedCorrectly = messages . Any ( msg =>
215+ {
216+ var eventContext = msg . Item3 as EventContext ;
217+ return eventContext != null &&
218+ eventContext . Properties . ContainsKey ( "redisVersion" ) &&
219+ eventContext . Properties [ "redisVersion" ] . ToString ( ) == "7.0.15" ;
220+ } ) ;
221+ Assert . IsTrue ( versionCapturedCorrectly , "The Redis version '7.0.15' was not captured correctly in the logs." ) ;
222+ }
223+ }
224+
152225 private class TestRedisServerExecutor : RedisServerExecutor
153226 {
154227 public TestRedisServerExecutor ( IServiceCollection services , IDictionary < string , IConvertible > parameters = null )
0 commit comments