Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
StackExchange.Redis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tsai
StackExchange.Redis
Commits
2a5c4f7a
Commit
2a5c4f7a
authored
Aug 31, 2018
by
Marc Gravell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
optional reusable connection fixture for sharing a muxer between tests
parent
5e6f36d2
Changes
36
Show whitespace changes
Inline
Side-by-side
Showing
36 changed files
with
555 additions
and
89 deletions
+555
-89
ConnectionMultiplexer.cs
src/StackExchange.Redis/ConnectionMultiplexer.cs
+16
-1
IConnectionMultiplexer.cs
src/StackExchange.Redis/Interfaces/IConnectionMultiplexer.cs
+17
-6
AdhocTests.cs
tests/StackExchange.Redis.Tests/AdhocTests.cs
+2
-1
AggresssiveTests.cs
tests/StackExchange.Redis.Tests/AggresssiveTests.cs
+1
-1
BasicOps.cs
tests/StackExchange.Redis.Tests/BasicOps.cs
+31
-3
Batches.cs
tests/StackExchange.Redis.Tests/Batches.cs
+2
-1
Bits.cs
tests/StackExchange.Redis.Tests/Bits.cs
+2
-1
Constraints.cs
tests/StackExchange.Redis.Tests/Constraints.cs
+2
-1
Databases.cs
tests/StackExchange.Redis.Tests/Databases.cs
+2
-1
Execute.cs
tests/StackExchange.Redis.Tests/Execute.cs
+2
-1
Expiry.cs
tests/StackExchange.Redis.Tests/Expiry.cs
+2
-1
Failover.cs
tests/StackExchange.Redis.Tests/Failover.cs
+2
-2
FloatingPoint.cs
tests/StackExchange.Redis.Tests/FloatingPoint.cs
+2
-1
GeoTests.cs
tests/StackExchange.Redis.Tests/GeoTests.cs
+2
-1
Hashes.cs
tests/StackExchange.Redis.Tests/Hashes.cs
+2
-1
Skip.cs
tests/StackExchange.Redis.Tests/Helpers/Skip.cs
+2
-2
TestConfig.cs
tests/StackExchange.Redis.Tests/Helpers/TestConfig.cs
+1
-1
HyperLogLog.cs
tests/StackExchange.Redis.Tests/HyperLogLog.cs
+2
-1
Keys.cs
tests/StackExchange.Redis.Tests/Keys.cs
+2
-1
Lex.cs
tests/StackExchange.Redis.Tests/Lex.cs
+2
-1
Lists.cs
tests/StackExchange.Redis.Tests/Lists.cs
+2
-1
Locking.cs
tests/StackExchange.Redis.Tests/Locking.cs
+2
-2
MultiAdd.cs
tests/StackExchange.Redis.Tests/MultiAdd.cs
+2
-1
PreserveOrder.cs
tests/StackExchange.Redis.Tests/PreserveOrder.cs
+2
-1
Profiling.cs
tests/StackExchange.Redis.Tests/Profiling.cs
+4
-4
PubSub.cs
tests/StackExchange.Redis.Tests/PubSub.cs
+7
-6
PubSubCommand.cs
tests/StackExchange.Redis.Tests/PubSubCommand.cs
+2
-1
Scans.cs
tests/StackExchange.Redis.Tests/Scans.cs
+3
-2
Scripting.cs
tests/StackExchange.Redis.Tests/Scripting.cs
+6
-5
Sets.cs
tests/StackExchange.Redis.Tests/Sets.cs
+2
-1
SharedConnectionFixture.cs
tests/StackExchange.Redis.Tests/SharedConnectionFixture.cs
+340
-0
Streams.cs
tests/StackExchange.Redis.Tests/Streams.cs
+2
-1
Strings.cs
tests/StackExchange.Redis.Tests/Strings.cs
+2
-1
TestBase.cs
tests/StackExchange.Redis.Tests/TestBase.cs
+79
-32
Transactions.cs
tests/StackExchange.Redis.Tests/Transactions.cs
+2
-1
WithKeyPrefixTests.cs
tests/StackExchange.Redis.Tests/WithKeyPrefixTests.cs
+2
-1
No files found.
src/StackExchange.Redis/ConnectionMultiplexer.cs
View file @
2a5c4f7a
...
...
@@ -18,7 +18,7 @@ namespace StackExchange.Redis
/// <summary>
/// Represents an inter-related group of connections to redis servers
/// </summary>
public
sealed
partial
class
ConnectionMultiplexer
:
I
ConnectionMultiplexer
,
IDisposable
public
sealed
partial
class
ConnectionMultiplexer
:
I
InternalConnectionMultiplexer
// implies : IConnectionMultiplexer and :
IDisposable
{
private
const
string
timeoutHelpLink
=
"https://stackexchange.github.io/StackExchange.Redis/Timeouts"
;
...
...
@@ -36,10 +36,23 @@ public sealed partial class ConnectionMultiplexer : IConnectionMultiplexer, IDis
}
#endif
bool
IInternalConnectionMultiplexer
.
AllowConnect
{
get
=>
AllowConnect
;
set
=>
AllowConnect
=
value
;
}
bool
IInternalConnectionMultiplexer
.
IgnoreConnect
{
get
=>
IgnoreConnect
;
set
=>
IgnoreConnect
=
value
;
}
/// <summary>
/// For debugging: when not enabled, servers cannot connect
/// </summary>
internal
volatile
bool
AllowConnect
=
true
;
/// <summary>
/// For debugging: when not enabled, end-connect is silently ignored (to simulate a long-running connect)
/// </summary>
...
...
@@ -903,6 +916,8 @@ private static ConnectionMultiplexer ConnectImpl(object configuration, TextWrite
private
string
failureMessage
;
private
readonly
Hashtable
servers
=
new
Hashtable
();
private
volatile
ServerSnapshot
_serverSnapshot
=
ServerSnapshot
.
Empty
;
ReadOnlySpan
<
ServerEndPoint
>
IInternalConnectionMultiplexer
.
GetServerSnapshot
()
=>
GetServerSnapshot
();
internal
ReadOnlySpan
<
ServerEndPoint
>
GetServerSnapshot
()
=>
_serverSnapshot
.
Span
;
private
sealed
class
ServerSnapshot
{
...
...
src/StackExchange.Redis/Interfaces/IConnectionMultiplexer.cs
View file @
2a5c4f7a
...
...
@@ -6,10 +6,19 @@
namespace
StackExchange.Redis
{
internal
interface
IInternalConnectionMultiplexer
:
IConnectionMultiplexer
{
bool
AllowConnect
{
get
;
set
;
}
bool
IgnoreConnect
{
get
;
set
;
}
ReadOnlySpan
<
ServerEndPoint
>
GetServerSnapshot
();
}
/// <summary>
/// Represents the abstract multiplexer API
/// </summary>
public
interface
IConnectionMultiplexer
public
interface
IConnectionMultiplexer
:
IDisposable
{
/// <summary>
/// Gets the client-name that will be used on all new connections
...
...
@@ -220,11 +229,6 @@ public interface IConnectionMultiplexer
/// <param name="allowCommandsToComplete">Whether to allow in-queue commadns to complete first.</param>
Task
CloseAsync
(
bool
allowCommandsToComplete
=
true
);
/// <summary>
/// Release all resources associated with this object
/// </summary>
void
Dispose
();
/// <summary>
/// Obtains the log of unusual busy patterns
/// </summary>
...
...
@@ -254,5 +258,12 @@ public interface IConnectionMultiplexer
/// </summary>
/// <param name="key">The key to get a the slot for.</param>
int
GetHashSlot
(
RedisKey
key
);
/// <summary>
/// Write the configuration of all servers to an output stream
/// </summary>
/// <param name="destination">The destination stream to write the export to.</param>
/// <param name="options">The options to use for this export.</param>
void
ExportConfiguration
(
Stream
destination
,
ExportOptions
options
=
ExportOptions
.
All
);
}
}
tests/StackExchange.Redis.Tests/AdhocTests.cs
View file @
2a5c4f7a
...
...
@@ -3,9 +3,10 @@
namespace
StackExchange.Redis.Tests
{
[
Collection
(
SharedConnectionFixture
.
Key
)]
public
class
AdhocTests
:
TestBase
{
public
AdhocTests
(
ITestOutputHelper
output
)
:
base
(
output
)
{
}
public
AdhocTests
(
ITestOutputHelper
output
,
SharedConnectionFixture
fixture
)
:
base
(
output
,
fixture
)
{
}
[
Fact
]
public
void
TestAdhocCommandsAPI
()
...
...
tests/StackExchange.Redis.Tests/AggresssiveTests.cs
View file @
2a5c4f7a
...
...
@@ -16,7 +16,7 @@ public async Task ParallelTransactionsWithConditions()
{
const
int
Muxers
=
4
,
Workers
=
20
,
PerThread
=
250
;
var
muxers
=
new
ConnectionMultiplexer
[
Muxers
];
var
muxers
=
new
I
ConnectionMultiplexer
[
Muxers
];
try
{
for
(
int
i
=
0
;
i
<
Muxers
;
i
++)
...
...
tests/StackExchange.Redis.Tests/BasicOps.cs
View file @
2a5c4f7a
using
System
;
using
System.Diagnostics
;
using
System.Threading.Tasks
;
using
StackExchange.Redis.KeyspaceIsolation
;
using
Xunit
;
using
Xunit.Abstractions
;
using
System.Diagnostics
;
namespace
StackExchange.Redis.Tests
{
[
Collection
(
SharedConnectionFixture
.
Key
)]
public
class
BasicOpsTests
:
TestBase
{
public
BasicOpsTests
(
ITestOutputHelper
output
)
:
base
(
output
)
{
}
public
BasicOpsTests
(
ITestOutputHelper
output
,
SharedConnectionFixture
fixture
)
:
base
(
output
,
fixture
)
{
}
[
Fact
]
public
async
Task
PingOnce
()
...
...
@@ -35,7 +36,7 @@ public void RapidDispose()
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
using
(
var
secondary
=
Create
(
fail
:
true
))
using
(
var
secondary
=
Create
(
fail
:
true
,
shared
:
false
))
{
secondary
.
GetDatabase
().
StringIncrement
(
key
,
flags
:
CommandFlags
.
FireAndForget
);
}
...
...
@@ -398,6 +399,33 @@ private void Incr(IDatabase database, RedisKey key, int delta, ref int total)
total
+=
delta
;
}
[
Fact
]
public
void
ShouldUseSharedMuxer
()
{
if
(
SharedFixtureAvailable
)
{
using
(
var
a
=
Create
())
{
Assert
.
IsNotType
<
ConnectionMultiplexer
>(
a
);
using
(
var
b
=
Create
())
{
Assert
.
Same
(
a
,
b
);
}
}
}
else
{
using
(
var
a
=
Create
())
{
Assert
.
IsType
<
ConnectionMultiplexer
>(
a
);
using
(
var
b
=
Create
())
{
Assert
.
NotSame
(
a
,
b
);
}
}
}
}
[
Fact
]
public
async
Task
Delete
()
{
...
...
tests/StackExchange.Redis.Tests/Batches.cs
View file @
2a5c4f7a
...
...
@@ -6,9 +6,10 @@
namespace
StackExchange.Redis.Tests
{
[
Collection
(
SharedConnectionFixture
.
Key
)]
public
class
Batches
:
TestBase
{
public
Batches
(
ITestOutputHelper
output
)
:
base
(
output
)
{
}
public
Batches
(
ITestOutputHelper
output
,
SharedConnectionFixture
fixture
)
:
base
(
output
,
fixture
)
{
}
[
Fact
]
public
void
TestBatchNotSent
()
...
...
tests/StackExchange.Redis.Tests/Bits.cs
View file @
2a5c4f7a
...
...
@@ -3,9 +3,10 @@
namespace
StackExchange.Redis.Tests
{
[
Collection
(
SharedConnectionFixture
.
Key
)]
public
class
Bits
:
TestBase
{
public
Bits
(
ITestOutputHelper
output
)
:
base
(
output
)
{
}
public
Bits
(
ITestOutputHelper
output
,
SharedConnectionFixture
fixture
)
:
base
(
output
,
fixture
)
{
}
[
Fact
]
public
void
BasicOps
()
...
...
tests/StackExchange.Redis.Tests/Constraints.cs
View file @
2a5c4f7a
...
...
@@ -4,9 +4,10 @@
namespace
StackExchange.Redis.Tests
{
[
Collection
(
SharedConnectionFixture
.
Key
)]
public
class
Constraints
:
TestBase
{
public
Constraints
(
ITestOutputHelper
output
)
:
base
(
output
)
{
}
public
Constraints
(
ITestOutputHelper
output
,
SharedConnectionFixture
fixture
)
:
base
(
output
,
fixture
)
{
}
[
Fact
]
public
void
ValueEquals
()
...
...
tests/StackExchange.Redis.Tests/Databases.cs
View file @
2a5c4f7a
...
...
@@ -4,9 +4,10 @@
namespace
StackExchange.Redis.Tests
{
[
Collection
(
SharedConnectionFixture
.
Key
)]
public
class
Databases
:
TestBase
{
public
Databases
(
ITestOutputHelper
output
)
:
base
(
output
)
{
}
public
Databases
(
ITestOutputHelper
output
,
SharedConnectionFixture
fixture
)
:
base
(
output
,
fixture
)
{
}
[
Fact
]
public
async
Task
CountKeys
()
...
...
tests/StackExchange.Redis.Tests/Execute.cs
View file @
2a5c4f7a
...
...
@@ -5,9 +5,10 @@
namespace
StackExchange.Redis.Tests
{
[
Collection
(
SharedConnectionFixture
.
Key
)]
public
class
ExecuteTests
:
TestBase
{
public
ExecuteTests
(
ITestOutputHelper
output
)
:
base
(
output
)
{
}
public
ExecuteTests
(
ITestOutputHelper
output
,
SharedConnectionFixture
fixture
)
:
base
(
output
,
fixture
)
{
}
[
Fact
]
public
async
Task
DBExecute
()
...
...
tests/StackExchange.Redis.Tests/Expiry.cs
View file @
2a5c4f7a
...
...
@@ -5,9 +5,10 @@
namespace
StackExchange.Redis.Tests
{
[
Collection
(
SharedConnectionFixture
.
Key
)]
public
class
Expiry
:
TestBase
{
public
Expiry
(
ITestOutputHelper
output
)
:
base
(
output
)
{
}
public
Expiry
(
ITestOutputHelper
output
,
SharedConnectionFixture
fixture
)
:
base
(
output
,
fixture
)
{
}
private
static
string
[]
GetMap
(
bool
disablePTimes
)
=>
disablePTimes
?
(
new
[]
{
"pexpire"
,
"pexpireat"
,
"pttl"
})
:
null
;
...
...
tests/StackExchange.Redis.Tests/Failover.cs
View file @
2a5c4f7a
...
...
@@ -199,8 +199,8 @@ public async Task SubscriptionsSurviveMasterSwitchAsync()
Skip
.
Inconclusive
(
"TODO: Fix race in broadcast reconfig a zero latency."
);
}
using
(
var
a
=
Create
(
allowAdmin
:
true
))
using
(
var
b
=
Create
(
allowAdmin
:
true
))
using
(
var
a
=
Create
(
allowAdmin
:
true
,
shared
:
false
))
using
(
var
b
=
Create
(
allowAdmin
:
true
,
shared
:
false
))
{
RedisChannel
channel
=
Me
();
var
subA
=
a
.
GetSubscriber
();
...
...
tests/StackExchange.Redis.Tests/FloatingPoint.cs
View file @
2a5c4f7a
...
...
@@ -5,9 +5,10 @@
namespace
StackExchange.Redis.Tests
{
[
Collection
(
SharedConnectionFixture
.
Key
)]
public
class
FloatingPoint
:
TestBase
{
public
FloatingPoint
(
ITestOutputHelper
output
)
:
base
(
output
)
{
}
public
FloatingPoint
(
ITestOutputHelper
output
,
SharedConnectionFixture
fixture
)
:
base
(
output
,
fixture
)
{
}
private
static
bool
Within
(
double
x
,
double
y
,
double
delta
)
{
...
...
tests/StackExchange.Redis.Tests/GeoTests.cs
View file @
2a5c4f7a
...
...
@@ -5,9 +5,10 @@
namespace
StackExchange.Redis.Tests
{
[
Collection
(
SharedConnectionFixture
.
Key
)]
public
class
GeoTests
:
TestBase
{
public
GeoTests
(
ITestOutputHelper
output
)
:
base
(
output
)
{
}
public
GeoTests
(
ITestOutputHelper
output
,
SharedConnectionFixture
fixture
)
:
base
(
output
,
fixture
)
{
}
public
static
GeoEntry
palermo
=
new
GeoEntry
(
13.361389
,
38.115556
,
"Palermo"
),
...
...
tests/StackExchange.Redis.Tests/Hashes.cs
View file @
2a5c4f7a
...
...
@@ -9,9 +9,10 @@
namespace
StackExchange.Redis.Tests
{
[
Collection
(
SharedConnectionFixture
.
Key
)]
public
class
Hashes
:
TestBase
// https://redis.io/commands#hash
{
public
Hashes
(
ITestOutputHelper
output
)
:
base
(
output
)
{
}
public
Hashes
(
ITestOutputHelper
output
,
SharedConnectionFixture
fixture
)
:
base
(
output
,
fixture
)
{
}
[
Fact
]
public
async
Task
TestIncrBy
()
...
...
tests/StackExchange.Redis.Tests/Helpers/Skip.cs
View file @
2a5c4f7a
...
...
@@ -23,7 +23,7 @@ public static void IfNoConfig(string prop, List<string> values)
}
}
public
static
void
IfMissingFeature
(
ConnectionMultiplexer
conn
,
string
feature
,
Func
<
RedisFeatures
,
bool
>
check
)
public
static
void
IfMissingFeature
(
I
ConnectionMultiplexer
conn
,
string
feature
,
Func
<
RedisFeatures
,
bool
>
check
)
{
var
features
=
conn
.
GetServer
(
conn
.
GetEndPoints
()[
0
]).
Features
;
if
(!
check
(
features
))
...
...
@@ -35,7 +35,7 @@ public static void IfMissingFeature(ConnectionMultiplexer conn, string feature,
}
}
internal
static
void
IfMissingDatabase
(
ConnectionMultiplexer
conn
,
int
dbId
)
internal
static
void
IfMissingDatabase
(
I
ConnectionMultiplexer
conn
,
int
dbId
)
{
var
dbCount
=
conn
.
GetServer
(
conn
.
GetEndPoints
()[
0
]).
DatabaseCount
;
if
(
dbId
>=
dbCount
)
throw
new
SkipTestException
(
$"Database '
{
dbId
}
' is not supported on this server."
);
...
...
tests/StackExchange.Redis.Tests/Helpers/TestConfig.cs
View file @
2a5c4f7a
...
...
@@ -12,7 +12,7 @@ public static class TestConfig
public
static
Config
Current
{
get
;
}
private
static
int
_db
=
17
;
public
static
int
GetDedicatedDB
(
ConnectionMultiplexer
conn
=
null
)
public
static
int
GetDedicatedDB
(
I
ConnectionMultiplexer
conn
=
null
)
{
int
db
=
Interlocked
.
Increment
(
ref
_db
);
if
(
conn
!=
null
)
Skip
.
IfMissingDatabase
(
conn
,
db
);
...
...
tests/StackExchange.Redis.Tests/HyperLogLog.cs
View file @
2a5c4f7a
...
...
@@ -3,9 +3,10 @@
namespace
StackExchange.Redis.Tests
{
[
Collection
(
SharedConnectionFixture
.
Key
)]
public
class
HyperLogLog
:
TestBase
{
public
HyperLogLog
(
ITestOutputHelper
output
)
:
base
(
output
)
{
}
public
HyperLogLog
(
ITestOutputHelper
output
,
SharedConnectionFixture
fixture
)
:
base
(
output
,
fixture
)
{
}
[
Fact
]
public
void
SingleKeyLength
()
...
...
tests/StackExchange.Redis.Tests/Keys.cs
View file @
2a5c4f7a
...
...
@@ -7,9 +7,10 @@
namespace
StackExchange.Redis.Tests
{
[
Collection
(
SharedConnectionFixture
.
Key
)]
public
class
Keys
:
TestBase
{
public
Keys
(
ITestOutputHelper
output
)
:
base
(
output
)
{
}
public
Keys
(
ITestOutputHelper
output
,
SharedConnectionFixture
fixture
)
:
base
(
output
,
fixture
)
{
}
[
Fact
]
public
void
TestScan
()
...
...
tests/StackExchange.Redis.Tests/Lex.cs
View file @
2a5c4f7a
...
...
@@ -3,9 +3,10 @@
namespace
StackExchange.Redis.Tests
{
[
Collection
(
SharedConnectionFixture
.
Key
)]
public
class
Lex
:
TestBase
{
public
Lex
(
ITestOutputHelper
output
)
:
base
(
output
)
{
}
public
Lex
(
ITestOutputHelper
output
,
SharedConnectionFixture
fixture
)
:
base
(
output
,
fixture
)
{
}
[
Fact
]
public
void
QueryRangeAndLengthByLex
()
...
...
tests/StackExchange.Redis.Tests/Lists.cs
View file @
2a5c4f7a
...
...
@@ -4,9 +4,10 @@
namespace
StackExchange.Redis.Tests
{
[
Collection
(
SharedConnectionFixture
.
Key
)]
public
class
Lists
:
TestBase
{
public
Lists
(
ITestOutputHelper
output
)
:
base
(
output
)
{
}
public
Lists
(
ITestOutputHelper
output
,
SharedConnectionFixture
fixture
)
:
base
(
output
,
fixture
)
{
}
[
Fact
]
public
void
Ranges
()
...
...
tests/StackExchange.Redis.Tests/Locking.cs
View file @
2a5c4f7a
...
...
@@ -76,7 +76,7 @@ public void TestOpCountByVersionLocal_UpLevel()
}
}
private
void
TestLockOpCountByVersion
(
ConnectionMultiplexer
conn
,
int
expectedOps
,
bool
existFirst
)
private
void
TestLockOpCountByVersion
(
I
ConnectionMultiplexer
conn
,
int
expectedOps
,
bool
existFirst
)
{
const
int
LockDuration
=
30
;
RedisKey
Key
=
Me
();
...
...
@@ -103,7 +103,7 @@ private void TestLockOpCountByVersion(ConnectionMultiplexer conn, int expectedOp
// note we get a ping from GetCounters
}
private
ConnectionMultiplexer
Create
(
TestMode
mode
)
private
I
ConnectionMultiplexer
Create
(
TestMode
mode
)
{
switch
(
mode
)
{
...
...
tests/StackExchange.Redis.Tests/MultiAdd.cs
View file @
2a5c4f7a
...
...
@@ -4,9 +4,10 @@
namespace
StackExchange.Redis.Tests
{
[
Collection
(
SharedConnectionFixture
.
Key
)]
public
class
MultiAdd
:
TestBase
{
public
MultiAdd
(
ITestOutputHelper
output
)
:
base
(
output
)
{
}
public
MultiAdd
(
ITestOutputHelper
output
,
SharedConnectionFixture
fixture
)
:
base
(
output
,
fixture
)
{
}
[
Fact
]
public
void
AddSortedSetEveryWay
()
...
...
tests/StackExchange.Redis.Tests/PreserveOrder.cs
View file @
2a5c4f7a
...
...
@@ -7,9 +7,10 @@
namespace
StackExchange.Redis.Tests
{
[
Collection
(
SharedConnectionFixture
.
Key
)]
public
class
PreserveOrder
:
TestBase
{
public
PreserveOrder
(
ITestOutputHelper
output
)
:
base
(
output
)
{
}
public
PreserveOrder
(
ITestOutputHelper
output
,
SharedConnectionFixture
fixture
)
:
base
(
output
,
fixture
)
{
}
[
Fact
]
public
void
Execute
()
...
...
tests/StackExchange.Redis.Tests/Profiling.cs
View file @
2a5c4f7a
...
...
@@ -73,7 +73,7 @@ public void Simple()
}
}
private
static
void
AssertProfiledCommandValues
(
IProfiledCommand
command
,
ConnectionMultiplexer
conn
,
int
dbId
)
private
static
void
AssertProfiledCommandValues
(
IProfiledCommand
command
,
I
ConnectionMultiplexer
conn
,
int
dbId
)
{
Assert
.
Equal
(
dbId
,
command
.
Db
);
Assert
.
Equal
(
conn
.
GetEndPoints
()[
0
],
command
.
EndPoint
);
...
...
@@ -275,7 +275,7 @@ public void ProfilingMD_Ex1()
{
using
(
var
c
=
Create
())
{
ConnectionMultiplexer
conn
=
c
;
I
ConnectionMultiplexer
conn
=
c
;
var
session
=
new
ProfilingSession
();
var
prefix
=
Me
();
...
...
@@ -317,7 +317,7 @@ public void ProfilingMD_Ex2()
{
using
(
var
c
=
Create
())
{
ConnectionMultiplexer
conn
=
c
;
I
ConnectionMultiplexer
conn
=
c
;
var
profiler
=
new
PerThreadProfiler
();
var
prefix
=
Me
();
...
...
@@ -362,7 +362,7 @@ public async Task ProfilingMD_Ex2_Async()
{
using
(
var
c
=
Create
())
{
ConnectionMultiplexer
conn
=
c
;
I
ConnectionMultiplexer
conn
=
c
;
var
profiler
=
new
AsyncLocalProfiler
();
var
prefix
=
Me
();
...
...
tests/StackExchange.Redis.Tests/PubSub.cs
View file @
2a5c4f7a
...
...
@@ -10,9 +10,10 @@
namespace
StackExchange.Redis.Tests
{
[
Collection
(
SharedConnectionFixture
.
Key
)]
public
class
PubSub
:
TestBase
{
public
PubSub
(
ITestOutputHelper
output
)
:
base
(
output
)
{
}
public
PubSub
(
ITestOutputHelper
output
,
SharedConnectionFixture
fixture
)
:
base
(
output
,
fixture
)
{
}
[
Fact
]
public
async
Task
ExplicitPublishMode
()
...
...
@@ -172,7 +173,7 @@ public async Task TestBasicPubSubFireAndForget()
}
}
private
static
async
Task
PingAsync
(
ConnectionMultiplexer
muxer
,
IServer
pub
,
ISubscriber
sub
,
int
times
=
1
)
private
static
async
Task
PingAsync
(
I
ConnectionMultiplexer
muxer
,
IServer
pub
,
ISubscriber
sub
,
int
times
=
1
)
{
while
(
times
--
>
0
)
{
...
...
@@ -558,8 +559,8 @@ public async Task PubSubGetAllCorrectOrder_OnMessage_Async()
public
async
Task
TestPublishWithSubscribers
()
{
var
channel
=
Me
();
using
(
var
muxerA
=
Create
())
using
(
var
muxerB
=
Create
())
using
(
var
muxerA
=
Create
(
shared
:
false
))
using
(
var
muxerB
=
Create
(
shared
:
false
))
using
(
var
conn
=
Create
())
{
var
listenA
=
muxerA
.
GetSubscriber
();
...
...
@@ -578,8 +579,8 @@ public async Task TestPublishWithSubscribers()
public
async
Task
TestMultipleSubscribersGetMessage
()
{
var
channel
=
Me
();
using
(
var
muxerA
=
Create
())
using
(
var
muxerB
=
Create
())
using
(
var
muxerA
=
Create
(
shared
:
false
))
using
(
var
muxerB
=
Create
(
shared
:
false
))
using
(
var
conn
=
Create
())
{
var
listenA
=
muxerA
.
GetSubscriber
();
...
...
tests/StackExchange.Redis.Tests/PubSubCommand.cs
View file @
2a5c4f7a
...
...
@@ -4,9 +4,10 @@
namespace
StackExchange.Redis.Tests
{
[
Collection
(
SharedConnectionFixture
.
Key
)]
public
class
PubSubCommand
:
TestBase
{
public
PubSubCommand
(
ITestOutputHelper
output
)
:
base
(
output
)
{
}
public
PubSubCommand
(
ITestOutputHelper
output
,
SharedConnectionFixture
fixture
)
:
base
(
output
,
fixture
)
{
}
[
Fact
]
public
void
SubscriberCount
()
...
...
tests/StackExchange.Redis.Tests/Scans.cs
View file @
2a5c4f7a
...
...
@@ -6,9 +6,10 @@
namespace
StackExchange.Redis.Tests
{
[
Collection
(
SharedConnectionFixture
.
Key
)]
public
class
Scans
:
TestBase
{
public
Scans
(
ITestOutputHelper
output
)
:
base
(
output
)
{
}
public
Scans
(
ITestOutputHelper
output
,
SharedConnectionFixture
fixture
)
:
base
(
output
,
fixture
)
{
}
[
Theory
]
[
InlineData
(
true
)]
...
...
@@ -339,7 +340,7 @@ public void HashScanThresholds()
}
}
private
bool
GotCursors
(
ConnectionMultiplexer
conn
,
RedisKey
key
,
int
count
)
private
bool
GotCursors
(
I
ConnectionMultiplexer
conn
,
RedisKey
key
,
int
count
)
{
var
db
=
conn
.
GetDatabase
();
db
.
KeyDelete
(
key
,
CommandFlags
.
FireAndForget
);
...
...
tests/StackExchange.Redis.Tests/Scripting.cs
View file @
2a5c4f7a
...
...
@@ -8,11 +8,12 @@
namespace
StackExchange.Redis.Tests
{
[
Collection
(
SharedConnectionFixture
.
Key
)]
public
class
Scripting
:
TestBase
{
public
Scripting
(
ITestOutputHelper
output
)
:
base
(
output
)
{
}
public
Scripting
(
ITestOutputHelper
output
,
SharedConnectionFixture
fixture
)
:
base
(
output
,
fixture
)
{
}
private
ConnectionMultiplexer
GetScriptConn
(
bool
allowAdmin
=
false
)
private
I
ConnectionMultiplexer
GetScriptConn
(
bool
allowAdmin
=
false
)
{
int
syncTimeout
=
5000
;
if
(
Debugger
.
IsAttached
)
syncTimeout
=
500000
;
...
...
@@ -596,7 +597,7 @@ public void LuaScriptWithKeys()
var
p
=
new
{
key
=
(
RedisKey
)
key
,
value
=
123
};
script
.
Evaluate
(
db
,
p
,
flags
:
CommandFlags
.
FireAndForget
);
script
.
Evaluate
(
db
,
p
);
var
val
=
db
.
StringGet
(
key
);
Assert
.
Equal
(
123
,
(
int
)
val
);
...
...
@@ -804,7 +805,7 @@ public void IServerLuaScriptConvenienceMethods()
var
prepared
=
server
.
ScriptLoad
(
script
);
db
.
ScriptEvaluate
(
prepared
,
new
{
key
=
(
RedisKey
)
key
,
value
=
"value3"
}
,
flags
:
CommandFlags
.
FireAndForget
);
db
.
ScriptEvaluate
(
prepared
,
new
{
key
=
(
RedisKey
)
key
,
value
=
"value3"
});
var
val
=
db
.
StringGet
(
key
);
Assert
.
Equal
(
"value3"
,
val
);
}
...
...
@@ -842,7 +843,7 @@ public void LuaScriptWithWrappedDatabase()
db
.
KeyDelete
(
key
,
CommandFlags
.
FireAndForget
);
var
prepared
=
LuaScript
.
Prepare
(
Script
);
wrappedDb
.
ScriptEvaluate
(
prepared
,
new
{
key
=
(
RedisKey
)
key
,
value
=
123
}
,
flags
:
CommandFlags
.
FireAndForget
);
wrappedDb
.
ScriptEvaluate
(
prepared
,
new
{
key
=
(
RedisKey
)
key
,
value
=
123
});
var
val1
=
wrappedDb
.
StringGet
(
key
);
Assert
.
Equal
(
123
,
(
int
)
val1
);
...
...
tests/StackExchange.Redis.Tests/Sets.cs
View file @
2a5c4f7a
...
...
@@ -6,9 +6,10 @@
namespace
StackExchange.Redis.Tests
{
[
Collection
(
SharedConnectionFixture
.
Key
)]
public
class
Sets
:
TestBase
{
public
Sets
(
ITestOutputHelper
output
)
:
base
(
output
)
{
}
public
Sets
(
ITestOutputHelper
output
,
SharedConnectionFixture
fixture
)
:
base
(
output
,
fixture
)
{
}
[
Fact
]
public
void
SScan
()
...
...
tests/StackExchange.Redis.Tests/SharedConnectionFixture.cs
0 → 100644
View file @
2a5c4f7a
using
System
;
using
System.Collections.Generic
;
using
System.IO
;
using
System.Linq
;
using
System.Net
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
StackExchange.Redis.Profiling
;
using
Xunit
;
namespace
StackExchange.Redis.Tests
{
public
class
SharedConnectionFixture
:
IDisposable
{
public
bool
IsEnabled
=>
true
;
// set to false to disable globally
public
const
string
Key
=
"Shared Muxer"
;
private
readonly
ConnectionMultiplexer
_actualConnection
;
internal
IInternalConnectionMultiplexer
Connection
{
get
;
}
public
string
Configuration
{
get
;
}
public
SharedConnectionFixture
()
{
Configuration
=
TestBase
.
GetDefaultConfiguration
();
_actualConnection
=
TestBase
.
CreateDefault
(
output
:
null
,
clientName
:
nameof
(
SharedConnectionFixture
),
configuration
:
Configuration
,
allowAdmin
:
true
);
_actualConnection
.
InternalError
+=
OnInternalError
;
_actualConnection
.
ConnectionFailed
+=
OnConnectionFailed
;
Connection
=
new
NonDisposingConnection
(
_actualConnection
);
}
private
class
NonDisposingConnection
:
IInternalConnectionMultiplexer
{
public
bool
AllowConnect
{
get
=>
_inner
.
AllowConnect
;
set
=>
_inner
.
AllowConnect
=
value
;
}
public
bool
IgnoreConnect
{
get
=>
_inner
.
IgnoreConnect
;
set
=>
_inner
.
IgnoreConnect
=
value
;
}
public
ReadOnlySpan
<
ServerEndPoint
>
GetServerSnapshot
()
=>
_inner
.
GetServerSnapshot
();
private
readonly
IInternalConnectionMultiplexer
_inner
;
public
NonDisposingConnection
(
IInternalConnectionMultiplexer
inner
)
=>
_inner
=
inner
;
public
string
ClientName
=>
_inner
.
ClientName
;
public
string
Configuration
=>
_inner
.
Configuration
;
public
int
TimeoutMilliseconds
=>
_inner
.
TimeoutMilliseconds
;
public
long
OperationCount
=>
_inner
.
OperationCount
;
#pragma warning disable CS0618
public
bool
PreserveAsyncOrder
{
get
=>
_inner
.
PreserveAsyncOrder
;
set
=>
_inner
.
PreserveAsyncOrder
=
value
;
}
#pragma warning restore CS0618
public
bool
IsConnected
=>
_inner
.
IsConnected
;
public
bool
IsConnecting
=>
_inner
.
IsConnecting
;
public
bool
IncludeDetailInExceptions
{
get
=>
_inner
.
IncludeDetailInExceptions
;
set
=>
_inner
.
IncludeDetailInExceptions
=
value
;
}
public
int
StormLogThreshold
{
get
=>
_inner
.
StormLogThreshold
;
set
=>
_inner
.
StormLogThreshold
=
value
;
}
public
event
EventHandler
<
RedisErrorEventArgs
>
ErrorMessage
{
add
{
_inner
.
ErrorMessage
+=
value
;
}
remove
{
_inner
.
ErrorMessage
-=
value
;
}
}
public
event
EventHandler
<
ConnectionFailedEventArgs
>
ConnectionFailed
{
add
{
_inner
.
ConnectionFailed
+=
value
;
}
remove
{
_inner
.
ConnectionFailed
-=
value
;
}
}
public
event
EventHandler
<
InternalErrorEventArgs
>
InternalError
{
add
{
_inner
.
InternalError
+=
value
;
}
remove
{
_inner
.
InternalError
-=
value
;
}
}
public
event
EventHandler
<
ConnectionFailedEventArgs
>
ConnectionRestored
{
add
{
_inner
.
ConnectionRestored
+=
value
;
}
remove
{
_inner
.
ConnectionRestored
-=
value
;
}
}
public
event
EventHandler
<
EndPointEventArgs
>
ConfigurationChanged
{
add
{
_inner
.
ConfigurationChanged
+=
value
;
}
remove
{
_inner
.
ConfigurationChanged
-=
value
;
}
}
public
event
EventHandler
<
EndPointEventArgs
>
ConfigurationChangedBroadcast
{
add
{
_inner
.
ConfigurationChangedBroadcast
+=
value
;
}
remove
{
_inner
.
ConfigurationChangedBroadcast
-=
value
;
}
}
public
event
EventHandler
<
HashSlotMovedEventArgs
>
HashSlotMoved
{
add
{
_inner
.
HashSlotMoved
+=
value
;
}
remove
{
_inner
.
HashSlotMoved
-=
value
;
}
}
public
void
Close
(
bool
allowCommandsToComplete
=
true
)
{
_inner
.
Close
(
allowCommandsToComplete
);
}
public
Task
CloseAsync
(
bool
allowCommandsToComplete
=
true
)
{
return
_inner
.
CloseAsync
(
allowCommandsToComplete
);
}
public
bool
Configure
(
TextWriter
log
=
null
)
{
return
_inner
.
Configure
(
log
);
}
public
Task
<
bool
>
ConfigureAsync
(
TextWriter
log
=
null
)
{
return
_inner
.
ConfigureAsync
(
log
);
}
public
void
Dispose
()
{
}
// DO NOT call _inner.Dispose();
public
ServerCounters
GetCounters
()
{
return
_inner
.
GetCounters
();
}
public
IDatabase
GetDatabase
(
int
db
=
-
1
,
object
asyncState
=
null
)
{
return
_inner
.
GetDatabase
(
db
,
asyncState
);
}
public
EndPoint
[]
GetEndPoints
(
bool
configuredOnly
=
false
)
{
return
_inner
.
GetEndPoints
(
configuredOnly
);
}
public
int
GetHashSlot
(
RedisKey
key
)
{
return
_inner
.
GetHashSlot
(
key
);
}
public
IServer
GetServer
(
string
host
,
int
port
,
object
asyncState
=
null
)
{
return
_inner
.
GetServer
(
host
,
port
,
asyncState
);
}
public
IServer
GetServer
(
string
hostAndPort
,
object
asyncState
=
null
)
{
return
_inner
.
GetServer
(
hostAndPort
,
asyncState
);
}
public
IServer
GetServer
(
IPAddress
host
,
int
port
)
{
return
_inner
.
GetServer
(
host
,
port
);
}
public
IServer
GetServer
(
EndPoint
endpoint
,
object
asyncState
=
null
)
{
return
_inner
.
GetServer
(
endpoint
,
asyncState
);
}
public
string
GetStatus
()
{
return
_inner
.
GetStatus
();
}
public
void
GetStatus
(
TextWriter
log
)
{
_inner
.
GetStatus
(
log
);
}
public
string
GetStormLog
()
{
return
_inner
.
GetStormLog
();
}
public
ISubscriber
GetSubscriber
(
object
asyncState
=
null
)
{
return
_inner
.
GetSubscriber
(
asyncState
);
}
public
int
HashSlot
(
RedisKey
key
)
{
return
_inner
.
HashSlot
(
key
);
}
public
long
PublishReconfigure
(
CommandFlags
flags
=
CommandFlags
.
None
)
{
return
_inner
.
PublishReconfigure
(
flags
);
}
public
Task
<
long
>
PublishReconfigureAsync
(
CommandFlags
flags
=
CommandFlags
.
None
)
{
return
_inner
.
PublishReconfigureAsync
(
flags
);
}
public
void
RegisterProfiler
(
Func
<
ProfilingSession
>
profilingSessionProvider
)
{
_inner
.
RegisterProfiler
(
profilingSessionProvider
);
}
public
void
ResetStormLog
()
{
_inner
.
ResetStormLog
();
}
public
void
Wait
(
Task
task
)
{
_inner
.
Wait
(
task
);
}
public
T
Wait
<
T
>(
Task
<
T
>
task
)
{
return
_inner
.
Wait
(
task
);
}
public
void
WaitAll
(
params
Task
[]
tasks
)
{
_inner
.
WaitAll
(
tasks
);
}
public
void
ExportConfiguration
(
Stream
destination
,
ExportOptions
options
=
ExportOptions
.
All
)
=>
_inner
.
ExportConfiguration
(
destination
,
options
);
}
public
void
Dispose
()
=>
_actualConnection
.
Dispose
();
protected
void
OnInternalError
(
object
sender
,
InternalErrorEventArgs
e
)
{
Interlocked
.
Increment
(
ref
privateFailCount
);
lock
(
privateExceptions
)
{
privateExceptions
.
Add
(
TestBase
.
Time
()
+
": Internal error: "
+
e
.
Origin
+
", "
+
EndPointCollection
.
ToString
(
e
.
EndPoint
)
+
"/"
+
e
.
ConnectionType
);
}
}
protected
void
OnConnectionFailed
(
object
sender
,
ConnectionFailedEventArgs
e
)
{
Interlocked
.
Increment
(
ref
privateFailCount
);
lock
(
privateExceptions
)
{
privateExceptions
.
Add
(
$"
{
TestBase
.
Time
()}
: Connection failed (
{
e
.
FailureType
}
):
{
EndPointCollection
.
ToString
(
e
.
EndPoint
)}
/
{
e
.
ConnectionType
}
:
{
e
.
Exception
}
"
);
}
}
private
readonly
List
<
string
>
privateExceptions
=
new
List
<
string
>();
private
int
privateFailCount
;
public
void
Teardown
(
TextWriter
output
)
{
var
privateFailCount
=
Interlocked
.
Exchange
(
ref
this
.
privateFailCount
,
0
);
if
(
privateFailCount
!=
0
)
{
lock
(
privateExceptions
)
{
foreach
(
var
item
in
privateExceptions
.
Take
(
5
))
{
TestBase
.
LogNoTime
(
output
,
item
);
}
privateExceptions
.
Clear
();
}
Assert
.
True
(
false
,
$"There were
{
privateFailCount
}
private ambient exceptions."
);
}
TestBase
.
Log
(
output
,
$"Service Counts: (Scheduler) Queue:
{
SocketManager
.
Shared
?.
SchedulerPool
?.
TotalServicedByQueue
.
ToString
()}
, Pool:
{
SocketManager
.
Shared
?.
SchedulerPool
?.
TotalServicedByPool
.
ToString
()}
, (Completion) Queue:
{
SocketManager
.
Shared
?.
CompletionPool
?.
TotalServicedByQueue
.
ToString
()}
, Pool:
{
SocketManager
.
Shared
?.
CompletionPool
?.
TotalServicedByPool
.
ToString
()}
"
);
}
}
// https://stackoverflow.com/questions/13829737/xunit-net-run-code-once-before-and-after-all-tests
[
CollectionDefinition
(
SharedConnectionFixture
.
Key
)]
public
class
ConnectionCollection
:
ICollectionFixture
<
SharedConnectionFixture
>
{
// This class has no code, and is never created. Its purpose is simply
// to be the place to apply [CollectionDefinition] and all the
// ICollectionFixture<> interfaces.
}
}
tests/StackExchange.Redis.Tests/Streams.cs
View file @
2a5c4f7a
...
...
@@ -6,9 +6,10 @@
namespace
StackExchange.Redis.Tests
{
[
Collection
(
SharedConnectionFixture
.
Key
)]
public
class
Streams
:
TestBase
{
public
Streams
(
ITestOutputHelper
output
)
:
base
(
output
)
{
}
public
Streams
(
ITestOutputHelper
output
,
SharedConnectionFixture
fixture
)
:
base
(
output
,
fixture
)
{
}
[
Fact
]
public
void
IsStreamType
()
...
...
tests/StackExchange.Redis.Tests/Strings.cs
View file @
2a5c4f7a
...
...
@@ -7,9 +7,10 @@
namespace
StackExchange.Redis.Tests
{
[
Collection
(
SharedConnectionFixture
.
Key
)]
public
class
Strings
:
TestBase
// https://redis.io/commands#string
{
public
Strings
(
ITestOutputHelper
output
)
:
base
(
output
)
{
}
public
Strings
(
ITestOutputHelper
output
,
SharedConnectionFixture
fixture
)
:
base
(
output
,
fixture
)
{
}
[
Fact
]
public
async
Task
Append
()
...
...
tests/StackExchange.Redis.Tests/TestBase.cs
View file @
2a5c4f7a
using
StackExchange.Redis.Tests.Helpers
;
using
System
;
using
System
;
using
System.Collections.Generic
;
using
System.Diagnostics
;
using
System.IO
;
...
...
@@ -7,9 +6,9 @@
using
System.Net
;
using
System.Runtime
;
using
System.Runtime.CompilerServices
;
using
System.Runtime.InteropServices
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
StackExchange.Redis.Tests.Helpers
;
using
Xunit
;
using
Xunit.Abstractions
;
...
...
@@ -20,27 +19,35 @@ public abstract class TestBase : IDisposable
private
ITestOutputHelper
Output
{
get
;
}
protected
TextWriterOutputHelper
Writer
{
get
;
}
protected
static
bool
RunningInCI
{
get
;
}
=
Environment
.
GetEnvironmentVariable
(
"APPVEYOR"
)
!=
null
;
protected
virtual
string
GetConfiguration
()
=>
TestConfig
.
Current
.
MasterServerAndPort
;
protected
virtual
string
GetConfiguration
()
=>
GetDefaultConfiguration
();
internal
static
string
GetDefaultConfiguration
()
=>
TestConfig
.
Current
.
MasterServerAndPort
;
protected
TestBase
(
ITestOutputHelper
output
)
private
readonly
SharedConnectionFixture
_fixture
;
protected
bool
SharedFixtureAvailable
=>
_fixture
!=
null
&&
_fixture
.
IsEnabled
;
protected
TestBase
(
ITestOutputHelper
output
,
SharedConnectionFixture
fixture
=
null
)
{
Output
=
output
;
Output
.
WriteFrameworkVersion
();
Writer
=
new
TextWriterOutputHelper
(
output
,
TestConfig
.
Current
.
LogToConsole
);
_fixture
=
fixture
;
ClearAmbientFailures
();
}
protected
void
LogNoTime
(
string
message
)
protected
void
LogNoTime
(
string
message
)
=>
LogNoTime
(
Writer
,
message
);
internal
static
void
LogNoTime
(
TextWriter
output
,
string
message
)
{
O
utput
.
WriteLine
(
message
);
o
utput
.
WriteLine
(
message
);
if
(
TestConfig
.
Current
.
LogToConsole
)
{
Console
.
WriteLine
(
message
);
}
}
protected
void
Log
(
string
message
)
protected
void
Log
(
string
message
)
=>
Log
(
Writer
,
message
);
public
static
void
Log
(
TextWriter
output
,
string
message
)
{
Output
.
WriteLine
(
Time
()
+
": "
+
message
);
output
?
.
WriteLine
(
Time
()
+
": "
+
message
);
if
(
TestConfig
.
Current
.
LogToConsole
)
{
Console
.
WriteLine
(
message
);
...
...
@@ -65,6 +72,7 @@ protected void CollectGarbage()
[
System
.
Diagnostics
.
CodeAnalysis
.
SuppressMessage
(
"Microsoft.Design"
,
"CA1063:ImplementIDisposableCorrectly"
)]
public
void
Dispose
()
{
_fixture
?.
Teardown
(
Writer
);
Teardown
();
}
...
...
@@ -175,7 +183,7 @@ public void Teardown()
Log
(
$"Service Counts: (Scheduler) Queue:
{
SocketManager
.
Shared
?.
SchedulerPool
?.
TotalServicedByQueue
.
ToString
()}
, Pool:
{
SocketManager
.
Shared
?.
SchedulerPool
?.
TotalServicedByPool
.
ToString
()}
, (Completion) Queue:
{
SocketManager
.
Shared
?.
CompletionPool
?.
TotalServicedByQueue
.
ToString
()}
, Pool:
{
SocketManager
.
Shared
?.
CompletionPool
?.
TotalServicedByPool
.
ToString
()}
"
);
}
protected
IServer
GetServer
(
ConnectionMultiplexer
muxer
)
protected
IServer
GetServer
(
I
ConnectionMultiplexer
muxer
)
{
EndPoint
[]
endpoints
=
muxer
.
GetEndPoints
();
IServer
result
=
null
;
...
...
@@ -190,7 +198,7 @@ protected IServer GetServer(ConnectionMultiplexer muxer)
return
result
;
}
protected
IServer
GetAnyMaster
(
ConnectionMultiplexer
muxer
)
protected
IServer
GetAnyMaster
(
I
ConnectionMultiplexer
muxer
)
{
foreach
(
var
endpoint
in
muxer
.
GetEndPoints
())
{
...
...
@@ -200,13 +208,54 @@ protected IServer GetAnyMaster(ConnectionMultiplexer muxer)
throw
new
InvalidOperationException
(
"Requires a master endpoint (found none)"
);
}
protected
virtual
ConnectionMultiplexer
Create
(
internal
virtual
IInternalConnectionMultiplexer
Create
(
string
clientName
=
null
,
int
?
syncTimeout
=
null
,
bool
?
allowAdmin
=
null
,
int
?
keepAlive
=
null
,
int
?
connectTimeout
=
null
,
string
password
=
null
,
string
tieBreaker
=
null
,
TextWriter
log
=
null
,
bool
fail
=
true
,
string
[]
disabledCommands
=
null
,
string
[]
enabledCommands
=
null
,
bool
checkConnect
=
true
,
string
failMessage
=
null
,
string
channelPrefix
=
null
,
Proxy
?
proxy
=
null
,
string
configuration
=
null
,
bool
logTransactionData
=
true
,
bool
shared
=
true
,
[
CallerMemberName
]
string
caller
=
null
)
{
if
(
Output
==
null
)
{
Assert
.
True
(
false
,
"Failure: Be sure to call the TestBase constuctor like this: BasicOpsTests(ITestOutputHelper output) : base(output) { }"
);
}
if
(
shared
&&
_fixture
!=
null
&&
_fixture
.
IsEnabled
&&
enabledCommands
==
null
&&
disabledCommands
==
null
&&
fail
&&
channelPrefix
==
null
&&
proxy
==
null
&&
configuration
==
null
&&
password
==
null
&&
tieBreaker
==
null
&&
(
allowAdmin
==
null
||
allowAdmin
==
true
)
&&
expectedFailCount
==
0
)
{
configuration
=
GetConfiguration
();
if
(
configuration
==
_fixture
.
Configuration
)
{
// only if the
return
_fixture
.
Connection
;
}
}
var
muxer
=
CreateDefault
(
Writer
,
clientName
,
syncTimeout
,
allowAdmin
,
keepAlive
,
connectTimeout
,
password
,
tieBreaker
,
log
,
fail
,
disabledCommands
,
enabledCommands
,
checkConnect
,
failMessage
,
channelPrefix
,
proxy
,
configuration
??
GetConfiguration
(),
logTransactionData
,
caller
);
muxer
.
InternalError
+=
OnInternalError
;
muxer
.
ConnectionFailed
+=
OnConnectionFailed
;
return
muxer
;
}
public
static
ConnectionMultiplexer
CreateDefault
(
TextWriter
output
,
string
clientName
=
null
,
int
?
syncTimeout
=
null
,
bool
?
allowAdmin
=
null
,
int
?
keepAlive
=
null
,
int
?
connectTimeout
=
null
,
string
password
=
null
,
string
tieBreaker
=
null
,
TextWriter
log
=
null
,
bool
fail
=
true
,
string
[]
disabledCommands
=
null
,
string
[]
enabledCommands
=
null
,
bool
checkConnect
=
true
,
string
failMessage
=
null
,
string
channelPrefix
=
null
,
Proxy
?
proxy
=
null
,
string
configuration
=
null
,
bool
logTransactionData
=
true
,
[
CallerMemberName
]
string
caller
=
null
)
{
StringWriter
localLog
=
null
;
...
...
@@ -216,7 +265,6 @@ protected IServer GetAnyMaster(ConnectionMultiplexer muxer)
}
try
{
configuration
=
configuration
??
GetConfiguration
();
var
config
=
ConfigurationOptions
.
Parse
(
configuration
);
if
(
disabledCommands
!=
null
&&
disabledCommands
.
Length
!=
0
)
{
...
...
@@ -258,11 +306,10 @@ protected IServer GetAnyMaster(ConnectionMultiplexer muxer)
throw
new
TimeoutException
(
"Connect timeout"
);
}
watch
.
Stop
();
if
(
Output
=
=
null
)
if
(
output
!
=
null
)
{
Assert
.
True
(
false
,
"Failure: Be sure to call the TestBase constuctor like this: BasicOpsTests(ITestOutputHelper output) : base(output) { }
"
);
Log
(
output
,
"Connect took: "
+
watch
.
ElapsedMilliseconds
+
"ms
"
);
}
Log
(
"Connect took: "
+
watch
.
ElapsedMilliseconds
+
"ms"
);
var
muxer
=
task
.
Result
;
if
(
checkConnect
&&
(
muxer
==
null
||
!
muxer
.
IsConnected
))
{
...
...
@@ -270,30 +317,30 @@ protected IServer GetAnyMaster(ConnectionMultiplexer muxer)
Assert
.
False
(
fail
,
failMessage
+
"Server is not available"
);
Skip
.
Inconclusive
(
failMessage
+
"Server is not available"
);
}
muxer
.
InternalError
+=
OnInternalError
;
muxer
.
ConnectionFailed
+=
OnConnectionFailed
;
if
(
output
!=
null
)
{
muxer
.
MessageFaulted
+=
(
msg
,
ex
,
origin
)
=>
{
Writer
?.
WriteLine
(
$"Faulted from '
{
origin
}
': '
{
msg
}
' - '
{(
ex
==
null
?
"(null)"
:
ex
.
Message
)}
'"
);
output
?.
WriteLine
(
$"Faulted from '
{
origin
}
': '
{
msg
}
' - '
{(
ex
==
null
?
"(null)"
:
ex
.
Message
)}
'"
);
if
(
ex
!=
null
&&
ex
.
Data
.
Contains
(
"got"
))
{
Writer
?.
WriteLine
(
$"Got: '
{
ex
.
Data
[
"got"
]}
'"
);
output
?.
WriteLine
(
$"Got: '
{
ex
.
Data
[
"got"
]}
'"
);
}
};
muxer
.
Connecting
+=
(
e
,
t
)
=>
Writer
.
WriteLine
(
$"Connecting to
{
Format
.
ToString
(
e
)}
as
{
t
}
"
);
muxer
.
Connecting
+=
(
e
,
t
)
=>
output
?
.
WriteLine
(
$"Connecting to
{
Format
.
ToString
(
e
)}
as
{
t
}
"
);
if
(
logTransactionData
)
{
muxer
.
TransactionLog
+=
msg
=>
Writer
.
WriteLine
(
"tran: "
+
msg
);
muxer
.
TransactionLog
+=
msg
=>
output
?.
WriteLine
(
"tran: "
+
msg
);
}
muxer
.
InfoMessage
+=
msg
=>
output
?.
WriteLine
(
msg
);
muxer
.
Resurrecting
+=
(
e
,
t
)
=>
output
?.
WriteLine
(
$"Resurrecting
{
Format
.
ToString
(
e
)}
as
{
t
}
"
);
muxer
.
Closing
+=
complete
=>
output
?.
WriteLine
(
complete
?
"Closed"
:
"Closing..."
);
}
muxer
.
InfoMessage
+=
msg
=>
Writer
.
WriteLine
(
msg
);
muxer
.
Resurrecting
+=
(
e
,
t
)
=>
Writer
.
WriteLine
(
$"Resurrecting
{
Format
.
ToString
(
e
)}
as
{
t
}
"
);
muxer
.
Closing
+=
complete
=>
Writer
.
WriteLine
(
complete
?
"Closed"
:
"Closing..."
);
return
muxer
;
}
catch
{
if
(
localLog
!=
null
)
O
utput
?.
WriteLine
(
localLog
.
ToString
());
if
(
localLog
!=
null
)
o
utput
?.
WriteLine
(
localLog
.
ToString
());
throw
;
}
}
...
...
tests/StackExchange.Redis.Tests/Transactions.cs
View file @
2a5c4f7a
...
...
@@ -10,9 +10,10 @@
namespace
StackExchange.Redis.Tests
{
[
Collection
(
SharedConnectionFixture
.
Key
)]
public
class
Transactions
:
TestBase
{
public
Transactions
(
ITestOutputHelper
output
)
:
base
(
output
)
{
}
public
Transactions
(
ITestOutputHelper
output
,
SharedConnectionFixture
fixture
)
:
base
(
output
,
fixture
)
{
}
[
Fact
]
public
void
BasicEmptyTran
()
...
...
tests/StackExchange.Redis.Tests/WithKeyPrefixTests.cs
View file @
2a5c4f7a
...
...
@@ -5,9 +5,10 @@
namespace
StackExchange.Redis.Tests
{
[
Collection
(
SharedConnectionFixture
.
Key
)]
public
class
WithKeyPrefixTests
:
TestBase
{
public
WithKeyPrefixTests
(
ITestOutputHelper
output
)
:
base
(
output
)
{
}
public
WithKeyPrefixTests
(
ITestOutputHelper
output
,
SharedConnectionFixture
fixture
)
:
base
(
output
,
fixture
)
{
}
[
Fact
]
public
void
BlankPrefixYieldsSame_Bytes
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment