77using System . Runtime . CompilerServices ;
88using System . Threading ;
99using System . Threading . Tasks ;
10+ using StackExchange . Redis . Configuration ;
1011using StackExchange . Redis . Profiling ;
1112using StackExchange . Redis . Tests . Helpers ;
1213using Xunit ;
@@ -17,22 +18,35 @@ public abstract class TestBase : IDisposable
1718{
1819 private ITestOutputHelper Output { get ; }
1920 protected TextWriterOutputHelper Writer { get ; }
20- protected virtual string GetConfiguration ( ) => GetDefaultConfiguration ( ) ;
21+ protected virtual string GetConfiguration ( )
22+ {
23+ if ( _inProcServerFixture != null )
24+ {
25+ return _inProcServerFixture . Configuration ;
26+ }
27+ return GetDefaultConfiguration ( ) ;
28+ }
2129 internal static string GetDefaultConfiguration ( ) => TestConfig . Current . PrimaryServerAndPort ;
2230
23- private readonly SharedConnectionFixture ? _fixture ;
31+ private readonly SharedConnectionFixture ? _sharedConnectionFixture ;
32+ private readonly InProcServerFixture ? _inProcServerFixture ;
2433
25- protected bool SharedFixtureAvailable => _fixture != null && _fixture . IsEnabled && ! HighIntegrity ;
34+ protected bool SharedFixtureAvailable => _sharedConnectionFixture != null && _sharedConnectionFixture . IsEnabled && ! HighIntegrity ;
2635
27- protected TestBase ( ITestOutputHelper output , SharedConnectionFixture ? fixture = null )
36+ protected TestBase ( ITestOutputHelper output , SharedConnectionFixture ? connection = null , InProcServerFixture ? server = null )
2837 {
2938 Output = output ;
3039 Output . WriteFrameworkVersion ( ) ;
3140 Writer = new TextWriterOutputHelper ( output ) ;
32- _fixture = fixture ;
41+ _sharedConnectionFixture = connection ;
42+ _inProcServerFixture = server ;
3343 ClearAmbientFailures ( ) ;
3444 }
3545
46+ protected TestBase ( ITestOutputHelper output , InProcServerFixture fixture ) : this ( output , null , fixture )
47+ {
48+ }
49+
3650 /// <summary>
3751 /// Useful to temporarily get extra worker threads for an otherwise synchronous test case which will 'block' the thread,
3852 /// on a synchronous API like <see cref="Task.Wait"/> or <see cref="Task.Result"/>.
@@ -85,7 +99,7 @@ protected static void CollectGarbage()
8599 [ System . Diagnostics . CodeAnalysis . SuppressMessage ( "Microsoft.Design" , "CA1063:ImplementIDisposableCorrectly" , Justification = "Trust me yo" ) ]
86100 public void Dispose ( )
87101 {
88- _fixture ? . Teardown ( Writer ) ;
102+ _sharedConnectionFixture ? . Teardown ( Writer ) ;
89103 Teardown ( ) ;
90104 Writer . Dispose ( ) ;
91105 GC . SuppressFinalize ( this ) ;
@@ -226,6 +240,8 @@ protected static IServer GetAnyPrimary(IConnectionMultiplexer muxer)
226240
227241 internal virtual bool HighIntegrity => false ;
228242
243+ internal virtual Tunnel ? Tunnel => _inProcServerFixture ? . Tunnel ;
244+
229245 internal virtual IInternalConnectionMultiplexer Create (
230246 string ? clientName = null ,
231247 int ? syncTimeout = null ,
@@ -262,17 +278,18 @@ internal virtual IInternalConnectionMultiplexer Create(
262278
263279 // Share a connection if instructed to and we can - many specifics mean no sharing
264280 bool highIntegrity = HighIntegrity ;
265- if ( shared && expectedFailCount == 0
266- && _fixture != null && _fixture . IsEnabled
281+ var tunnel = Tunnel ;
282+ if ( tunnel is null && shared && expectedFailCount == 0
283+ && _sharedConnectionFixture != null && _sharedConnectionFixture . IsEnabled
267284 && GetConfiguration ( ) == GetDefaultConfiguration ( )
268285 && CanShare ( allowAdmin , password , tieBreaker , fail , disabledCommands , enabledCommands , channelPrefix , proxy , configuration , defaultDatabase , backlogPolicy , highIntegrity ) )
269286 {
270287 configuration = GetConfiguration ( ) ;
271- var fixtureConn = _fixture . GetConnection ( this , protocol . Value , caller : caller ) ;
288+ var fixtureConn = _sharedConnectionFixture . GetConnection ( this , protocol . Value , caller : caller ) ;
272289 // Only return if we match
273290 TestBase . ThrowIfIncorrectProtocol ( fixtureConn , protocol ) ;
274291
275- if ( configuration == _fixture . Configuration )
292+ if ( configuration == _sharedConnectionFixture . Configuration )
276293 {
277294 TestBase . ThrowIfBelowMinVersion ( fixtureConn , require ) ;
278295 return fixtureConn ;
@@ -303,6 +320,7 @@ internal virtual IInternalConnectionMultiplexer Create(
303320 backlogPolicy ,
304321 protocol ,
305322 highIntegrity ,
323+ tunnel ,
306324 caller ) ;
307325
308326 TestBase . ThrowIfIncorrectProtocol ( conn , protocol ) ;
@@ -392,6 +410,7 @@ public static ConnectionMultiplexer CreateDefault(
392410 BacklogPolicy ? backlogPolicy = null ,
393411 RedisProtocol ? protocol = null ,
394412 bool highIntegrity = false ,
413+ Tunnel ? tunnel = null ,
395414 [ CallerMemberName ] string caller = "" )
396415 {
397416 StringWriter ? localLog = null ;
@@ -413,6 +432,7 @@ public static ConnectionMultiplexer CreateDefault(
413432 syncTimeout = int . MaxValue ;
414433 }
415434
435+ config . Tunnel = tunnel ;
416436 if ( channelPrefix is not null ) config . ChannelPrefix = RedisChannel . Literal ( channelPrefix ) ;
417437 if ( tieBreaker is not null ) config . TieBreaker = tieBreaker ;
418438 if ( password is not null ) config . Password = string . IsNullOrEmpty ( password ) ? null : password ;
0 commit comments