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
15cb2b12
Commit
15cb2b12
authored
Jul 10, 2018
by
Nick Craver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tests: more tuning/concurrency friendly
parent
0d8ebb3b
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
80 additions
and
74 deletions
+80
-74
BasicOps.cs
StackExchange.Redis.Tests/BasicOps.cs
+3
-3
Performance.cs
StackExchange.Redis.Tests/Booksleeve/Performance.cs
+4
-4
PubSub.cs
StackExchange.Redis.Tests/Booksleeve/PubSub.cs
+12
-15
Config.cs
StackExchange.Redis.Tests/Config.cs
+5
-4
ConnectToUnexistingHost.cs
StackExchange.Redis.Tests/ConnectToUnexistingHost.cs
+3
-2
ConnectingFailDetection.cs
StackExchange.Redis.Tests/ConnectingFailDetection.cs
+8
-7
ConnectionFailedErrors.cs
StackExchange.Redis.Tests/ConnectionFailedErrors.cs
+7
-6
ConnectionShutdown.cs
StackExchange.Redis.Tests/ConnectionShutdown.cs
+5
-3
Failover.cs
StackExchange.Redis.Tests/Failover.cs
+3
-3
SO24807536.cs
StackExchange.Redis.Tests/Issues/SO24807536.cs
+3
-2
Profiling.cs
StackExchange.Redis.Tests/Profiling.cs
+2
-2
PubSub.cs
StackExchange.Redis.Tests/PubSub.cs
+19
-19
RealWorld.cs
StackExchange.Redis.Tests/RealWorld.cs
+3
-2
TestInfoReplicationChecks.cs
StackExchange.Redis.Tests/TestInfoReplicationChecks.cs
+3
-2
No files found.
StackExchange.Redis.Tests/BasicOps.cs
View file @
15cb2b12
...
@@ -52,7 +52,7 @@ public void PingMany()
...
@@ -52,7 +52,7 @@ public void PingMany()
using
(
var
muxer
=
Create
())
using
(
var
muxer
=
Create
())
{
{
var
conn
=
muxer
.
GetDatabase
();
var
conn
=
muxer
.
GetDatabase
();
var
tasks
=
new
Task
<
TimeSpan
>[
100
00
];
var
tasks
=
new
Task
<
TimeSpan
>[
100
];
for
(
int
i
=
0
;
i
<
tasks
.
Length
;
i
++)
for
(
int
i
=
0
;
i
<
tasks
.
Length
;
i
++)
{
{
...
@@ -284,7 +284,7 @@ public void GetWithExpiryWrongTypeSync()
...
@@ -284,7 +284,7 @@ public void GetWithExpiryWrongTypeSync()
}
}
[
Fact
]
[
Fact
]
public
void
TestQuit
()
public
async
Task
TestQuit
()
{
{
string
Time
()
=>
DateTime
.
UtcNow
.
ToString
(
"HH:mm:ss.fff"
);
string
Time
()
=>
DateTime
.
UtcNow
.
ToString
(
"HH:mm:ss.fff"
);
SetExpectedAmbientFailureCount
(
1
);
SetExpectedAmbientFailureCount
(
1
);
...
@@ -303,7 +303,7 @@ public void TestQuit()
...
@@ -303,7 +303,7 @@ public void TestQuit()
Assert
.
Throws
<
RedisConnectionException
>(()
=>
Log
(
"Ping time: "
+
db
.
Ping
().
ToString
()));
Assert
.
Throws
<
RedisConnectionException
>(()
=>
Log
(
"Ping time: "
+
db
.
Ping
().
ToString
()));
watch
.
Stop
();
watch
.
Stop
();
Log
(
"Time to notice quit: {0}ms (any order)"
,
watch
.
ElapsedMilliseconds
);
Log
(
"Time to notice quit: {0}ms (any order)"
,
watch
.
ElapsedMilliseconds
);
Thread
.
Sleep
(
20
);
await
Task
.
Delay
(
20
).
ForAwait
(
);
Debug
.
WriteLine
(
"Pinging..."
);
Debug
.
WriteLine
(
"Pinging..."
);
Assert
.
Equal
(
key
,
(
string
)
db
.
StringGet
(
key
));
Assert
.
Equal
(
key
,
(
string
)
db
.
StringGet
(
key
));
}
}
...
...
StackExchange.Redis.Tests/Booksleeve/Performance.cs
View file @
15cb2b12
...
@@ -105,25 +105,25 @@ public async Task BasicStringGetPerf()
...
@@ -105,25 +105,25 @@ public async Task BasicStringGetPerf()
{
{
RedisKey
key
=
Me
();
RedisKey
key
=
Me
();
var
db
=
conn
.
GetDatabase
();
var
db
=
conn
.
GetDatabase
();
await
db
.
StringSetAsync
(
key
,
"some value"
);
await
db
.
StringSetAsync
(
key
,
"some value"
)
.
ForAwait
()
;
// this is just to JIT everything before we try testing
// this is just to JIT everything before we try testing
var
syncVal
=
db
.
StringGet
(
key
);
var
syncVal
=
db
.
StringGet
(
key
);
var
asyncVal
=
await
db
.
StringGetAsync
(
key
);
var
asyncVal
=
await
db
.
StringGetAsync
(
key
)
.
ForAwait
()
;
var
syncTimer
=
Stopwatch
.
StartNew
();
var
syncTimer
=
Stopwatch
.
StartNew
();
syncVal
=
db
.
StringGet
(
key
);
syncVal
=
db
.
StringGet
(
key
);
syncTimer
.
Stop
();
syncTimer
.
Stop
();
var
asyncTimer
=
Stopwatch
.
StartNew
();
var
asyncTimer
=
Stopwatch
.
StartNew
();
asyncVal
=
await
db
.
StringGetAsync
(
key
);
asyncVal
=
await
db
.
StringGetAsync
(
key
)
.
ForAwait
()
;
asyncTimer
.
Stop
();
asyncTimer
.
Stop
();
Log
(
$"Sync:
{
syncTimer
.
ElapsedMilliseconds
}
; Async:
{
asyncTimer
.
ElapsedMilliseconds
}
"
);
Log
(
$"Sync:
{
syncTimer
.
ElapsedMilliseconds
}
; Async:
{
asyncTimer
.
ElapsedMilliseconds
}
"
);
Assert
.
Equal
(
"some value"
,
syncVal
);
Assert
.
Equal
(
"some value"
,
syncVal
);
Assert
.
Equal
(
"some value"
,
asyncVal
);
Assert
.
Equal
(
"some value"
,
asyncVal
);
// let's allow 20% async overhead
// let's allow 20% async overhead
Assert
.
True
(
asyncTimer
.
Elapsed
Ticks
<=
(
syncTimer
.
ElapsedTick
s
*
1.2
M
));
Assert
.
True
(
asyncTimer
.
Elapsed
Milliseconds
<=
(
syncTimer
.
ElapsedMillisecond
s
*
1.2
M
));
}
}
}
}
}
}
...
...
StackExchange.Redis.Tests/Booksleeve/PubSub.cs
View file @
15cb2b12
...
@@ -333,7 +333,7 @@ public void TestPublishWithSubscribers()
...
@@ -333,7 +333,7 @@ public void TestPublishWithSubscribers()
}
}
[
Fact
]
[
Fact
]
public
void
TestMultipleSubscribersGetMessage
()
public
async
Task
TestMultipleSubscribersGetMessage
()
{
{
var
channel
=
Me
();
var
channel
=
Me
();
using
(
var
muxerA
=
GetUnsecuredConnection
())
using
(
var
muxerA
=
GetUnsecuredConnection
())
...
@@ -350,7 +350,7 @@ public void TestMultipleSubscribersGetMessage()
...
@@ -350,7 +350,7 @@ public void TestMultipleSubscribersGetMessage()
listenA
.
Wait
(
tA
);
listenA
.
Wait
(
tA
);
listenB
.
Wait
(
tB
);
listenB
.
Wait
(
tB
);
Assert
.
Equal
(
2
,
pub
.
Publish
(
channel
,
"message"
));
Assert
.
Equal
(
2
,
pub
.
Publish
(
channel
,
"message"
));
AllowReasonableTimeToPublishAndProcess
();
await
AllowReasonableTimeToPublishAndProcess
().
ForAwait
();
Assert
.
Equal
(
1
,
Interlocked
.
CompareExchange
(
ref
gotA
,
0
,
0
));
Assert
.
Equal
(
1
,
Interlocked
.
CompareExchange
(
ref
gotA
,
0
,
0
));
Assert
.
Equal
(
1
,
Interlocked
.
CompareExchange
(
ref
gotB
,
0
,
0
));
Assert
.
Equal
(
1
,
Interlocked
.
CompareExchange
(
ref
gotB
,
0
,
0
));
...
@@ -358,14 +358,14 @@ public void TestMultipleSubscribersGetMessage()
...
@@ -358,14 +358,14 @@ public void TestMultipleSubscribersGetMessage()
tA
=
listenA
.
UnsubscribeAsync
(
channel
);
tA
=
listenA
.
UnsubscribeAsync
(
channel
);
listenA
.
Wait
(
tA
);
listenA
.
Wait
(
tA
);
Assert
.
Equal
(
1
,
pub
.
Publish
(
channel
,
"message"
));
Assert
.
Equal
(
1
,
pub
.
Publish
(
channel
,
"message"
));
AllowReasonableTimeToPublishAndProcess
();
await
AllowReasonableTimeToPublishAndProcess
().
ForAwait
();
Assert
.
Equal
(
1
,
Interlocked
.
CompareExchange
(
ref
gotA
,
0
,
0
));
Assert
.
Equal
(
1
,
Interlocked
.
CompareExchange
(
ref
gotA
,
0
,
0
));
Assert
.
Equal
(
2
,
Interlocked
.
CompareExchange
(
ref
gotB
,
0
,
0
));
Assert
.
Equal
(
2
,
Interlocked
.
CompareExchange
(
ref
gotB
,
0
,
0
));
}
}
}
}
[
Fact
]
[
Fact
]
public
void
Issue38
()
public
async
Task
Issue38
()
{
// https://code.google.com/p/booksleeve/issues/detail?id=38
{
// https://code.google.com/p/booksleeve/issues/detail?id=38
using
(
var
pub
=
GetUnsecuredConnection
(
waitForOpen
:
true
))
using
(
var
pub
=
GetUnsecuredConnection
(
waitForOpen
:
true
))
{
{
...
@@ -387,20 +387,17 @@ public void Issue38()
...
@@ -387,20 +387,17 @@ public void Issue38()
pub
.
WaitAll
(
c
,
d
,
e
,
f
);
pub
.
WaitAll
(
c
,
d
,
e
,
f
);
long
total
=
c
.
Result
+
d
.
Result
+
e
.
Result
+
f
.
Result
;
long
total
=
c
.
Result
+
d
.
Result
+
e
.
Result
+
f
.
Result
;
AllowReasonableTimeToPublishAndProcess
();
await
AllowReasonableTimeToPublishAndProcess
().
ForAwait
();
Assert
.
Equal
(
6
,
total
);
// sent
Assert
.
Equal
(
6
,
total
);
// sent
Assert
.
Equal
(
6
,
Interlocked
.
CompareExchange
(
ref
count
,
0
,
0
));
// received
Assert
.
Equal
(
6
,
Interlocked
.
CompareExchange
(
ref
count
,
0
,
0
));
// received
}
}
}
}
internal
static
void
AllowReasonableTimeToPublishAndProcess
()
internal
static
Task
AllowReasonableTimeToPublishAndProcess
()
=>
Task
.
Delay
(
100
);
{
Thread
.
Sleep
(
100
);
}
[
Fact
]
[
Fact
]
public
void
TestPartialSubscriberGetMessage
()
public
async
Task
TestPartialSubscriberGetMessage
()
{
{
using
(
var
muxerA
=
GetUnsecuredConnection
())
using
(
var
muxerA
=
GetUnsecuredConnection
())
using
(
var
muxerB
=
GetUnsecuredConnection
())
using
(
var
muxerB
=
GetUnsecuredConnection
())
...
@@ -416,7 +413,7 @@ public void TestPartialSubscriberGetMessage()
...
@@ -416,7 +413,7 @@ public void TestPartialSubscriberGetMessage()
listenA
.
Wait
(
tA
);
listenA
.
Wait
(
tA
);
listenB
.
Wait
(
tB
);
listenB
.
Wait
(
tB
);
Assert
.
Equal
(
2
,
pub
.
Publish
(
prefix
+
"channel"
,
"message"
));
Assert
.
Equal
(
2
,
pub
.
Publish
(
prefix
+
"channel"
,
"message"
));
AllowReasonableTimeToPublishAndProcess
();
await
AllowReasonableTimeToPublishAndProcess
().
ForAwait
();
Assert
.
Equal
(
1
,
Interlocked
.
CompareExchange
(
ref
gotA
,
0
,
0
));
Assert
.
Equal
(
1
,
Interlocked
.
CompareExchange
(
ref
gotA
,
0
,
0
));
Assert
.
Equal
(
1
,
Interlocked
.
CompareExchange
(
ref
gotB
,
0
,
0
));
Assert
.
Equal
(
1
,
Interlocked
.
CompareExchange
(
ref
gotB
,
0
,
0
));
...
@@ -424,14 +421,14 @@ public void TestPartialSubscriberGetMessage()
...
@@ -424,14 +421,14 @@ public void TestPartialSubscriberGetMessage()
tB
=
listenB
.
UnsubscribeAsync
(
prefix
+
"chann*"
,
null
);
tB
=
listenB
.
UnsubscribeAsync
(
prefix
+
"chann*"
,
null
);
listenB
.
Wait
(
tB
);
listenB
.
Wait
(
tB
);
Assert
.
Equal
(
1
,
pub
.
Publish
(
prefix
+
"channel"
,
"message"
));
Assert
.
Equal
(
1
,
pub
.
Publish
(
prefix
+
"channel"
,
"message"
));
AllowReasonableTimeToPublishAndProcess
();
await
AllowReasonableTimeToPublishAndProcess
().
ForAwait
();
Assert
.
Equal
(
2
,
Interlocked
.
CompareExchange
(
ref
gotA
,
0
,
0
));
Assert
.
Equal
(
2
,
Interlocked
.
CompareExchange
(
ref
gotA
,
0
,
0
));
Assert
.
Equal
(
1
,
Interlocked
.
CompareExchange
(
ref
gotB
,
0
,
0
));
Assert
.
Equal
(
1
,
Interlocked
.
CompareExchange
(
ref
gotB
,
0
,
0
));
}
}
}
}
[
Fact
]
[
Fact
]
public
void
TestSubscribeUnsubscribeAndSubscribeAgain
()
public
async
Task
TestSubscribeUnsubscribeAndSubscribeAgain
()
{
{
using
(
var
pubMuxer
=
GetUnsecuredConnection
())
using
(
var
pubMuxer
=
GetUnsecuredConnection
())
using
(
var
subMuxer
=
GetUnsecuredConnection
())
using
(
var
subMuxer
=
GetUnsecuredConnection
())
...
@@ -444,7 +441,7 @@ public void TestSubscribeUnsubscribeAndSubscribeAgain()
...
@@ -444,7 +441,7 @@ public void TestSubscribeUnsubscribeAndSubscribeAgain()
var
t2
=
sub
.
SubscribeAsync
(
prefix
+
"ab*"
,
delegate
{
Interlocked
.
Increment
(
ref
y
);
});
var
t2
=
sub
.
SubscribeAsync
(
prefix
+
"ab*"
,
delegate
{
Interlocked
.
Increment
(
ref
y
);
});
sub
.
WaitAll
(
t1
,
t2
);
sub
.
WaitAll
(
t1
,
t2
);
pub
.
Publish
(
prefix
+
"abc"
,
""
);
pub
.
Publish
(
prefix
+
"abc"
,
""
);
AllowReasonableTimeToPublishAndProcess
();
await
AllowReasonableTimeToPublishAndProcess
().
ForAwait
();
Assert
.
Equal
(
1
,
Volatile
.
Read
(
ref
x
));
Assert
.
Equal
(
1
,
Volatile
.
Read
(
ref
x
));
Assert
.
Equal
(
1
,
Volatile
.
Read
(
ref
y
));
Assert
.
Equal
(
1
,
Volatile
.
Read
(
ref
y
));
t1
=
sub
.
UnsubscribeAsync
(
prefix
+
"abc"
,
null
);
t1
=
sub
.
UnsubscribeAsync
(
prefix
+
"abc"
,
null
);
...
@@ -457,7 +454,7 @@ public void TestSubscribeUnsubscribeAndSubscribeAgain()
...
@@ -457,7 +454,7 @@ public void TestSubscribeUnsubscribeAndSubscribeAgain()
t2
=
sub
.
SubscribeAsync
(
prefix
+
"ab*"
,
delegate
{
Interlocked
.
Increment
(
ref
y
);
});
t2
=
sub
.
SubscribeAsync
(
prefix
+
"ab*"
,
delegate
{
Interlocked
.
Increment
(
ref
y
);
});
sub
.
WaitAll
(
t1
,
t2
);
sub
.
WaitAll
(
t1
,
t2
);
pub
.
Publish
(
prefix
+
"abc"
,
""
);
pub
.
Publish
(
prefix
+
"abc"
,
""
);
AllowReasonableTimeToPublishAndProcess
();
await
AllowReasonableTimeToPublishAndProcess
().
ForAwait
();
Assert
.
Equal
(
2
,
Volatile
.
Read
(
ref
x
));
Assert
.
Equal
(
2
,
Volatile
.
Read
(
ref
x
));
Assert
.
Equal
(
2
,
Volatile
.
Read
(
ref
y
));
Assert
.
Equal
(
2
,
Volatile
.
Read
(
ref
y
));
}
}
...
...
StackExchange.Redis.Tests/Config.cs
View file @
15cb2b12
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
using
System.IO
;
using
System.IO
;
using
System.Linq
;
using
System.Linq
;
using
System.Threading
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
Xunit
;
using
Xunit
;
using
Xunit.Abstractions
;
using
Xunit.Abstractions
;
...
@@ -32,7 +33,7 @@ public void TalkToNonsenseServer()
...
@@ -32,7 +33,7 @@ public void TalkToNonsenseServer()
}
}
[
Fact
]
[
Fact
]
public
void
TestManaulHeartbeat
()
public
async
Task
TestManaulHeartbeat
()
{
{
using
(
var
muxer
=
Create
(
keepAlive
:
2
))
using
(
var
muxer
=
Create
(
keepAlive
:
2
))
{
{
...
@@ -42,7 +43,7 @@ public void TestManaulHeartbeat()
...
@@ -42,7 +43,7 @@ public void TestManaulHeartbeat()
var
before
=
muxer
.
OperationCount
;
var
before
=
muxer
.
OperationCount
;
Log
(
"sleeping to test heartbeat..."
);
Log
(
"sleeping to test heartbeat..."
);
Thread
.
Sleep
(
TimeSpan
.
FromSeconds
(
5
)
);
await
Task
.
Delay
(
5000
).
ForAwait
(
);
var
after
=
muxer
.
OperationCount
;
var
after
=
muxer
.
OperationCount
;
...
@@ -232,7 +233,7 @@ public void SlowLog()
...
@@ -232,7 +233,7 @@ public void SlowLog()
}
}
[
Fact
]
[
Fact
]
public
void
TestAutomaticHeartbeat
()
public
async
Task
TestAutomaticHeartbeat
()
{
{
RedisValue
oldTimeout
=
RedisValue
.
Null
;
RedisValue
oldTimeout
=
RedisValue
.
Null
;
using
(
var
configMuxer
=
Create
(
allowAdmin
:
true
))
using
(
var
configMuxer
=
Create
(
allowAdmin
:
true
))
...
@@ -252,7 +253,7 @@ public void TestAutomaticHeartbeat()
...
@@ -252,7 +253,7 @@ public void TestAutomaticHeartbeat()
var
before
=
innerMuxer
.
OperationCount
;
var
before
=
innerMuxer
.
OperationCount
;
Log
(
"sleeping to test heartbeat..."
);
Log
(
"sleeping to test heartbeat..."
);
Thread
.
Sleep
(
TimeSpan
.
FromSeconds
(
8
)
);
await
Task
.
Delay
(
8000
).
ForAwait
(
);
var
after
=
innerMuxer
.
OperationCount
;
var
after
=
innerMuxer
.
OperationCount
;
Assert
.
True
(
after
>=
before
+
4
);
Assert
.
True
(
after
>=
before
+
4
);
...
...
StackExchange.Redis.Tests/ConnectToUnexistingHost.cs
View file @
15cb2b12
using
System.Diagnostics
;
using
System.Diagnostics
;
using
System.Threading
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
Xunit
;
using
Xunit
;
using
Xunit.Abstractions
;
using
Xunit.Abstractions
;
...
@@ -11,7 +12,7 @@ public class ConnectToUnexistingHost : TestBase
...
@@ -11,7 +12,7 @@ public class ConnectToUnexistingHost : TestBase
#if DEBUG
#if DEBUG
[
Fact
]
[
Fact
]
public
void
FailsWithinTimeout
()
public
async
Task
FailsWithinTimeout
()
{
{
const
int
timeout
=
1000
;
const
int
timeout
=
1000
;
var
sw
=
Stopwatch
.
StartNew
();
var
sw
=
Stopwatch
.
StartNew
();
...
@@ -25,7 +26,7 @@ public void FailsWithinTimeout()
...
@@ -25,7 +26,7 @@ public void FailsWithinTimeout()
using
(
var
muxer
=
ConnectionMultiplexer
.
Connect
(
config
,
Writer
))
using
(
var
muxer
=
ConnectionMultiplexer
.
Connect
(
config
,
Writer
))
{
{
Thread
.
Sleep
(
10000
);
await
Task
.
Delay
(
10000
).
ForAwait
(
);
}
}
Assert
.
True
(
false
,
"Connect should fail with RedisConnectionException exception"
);
Assert
.
True
(
false
,
"Connect should fail with RedisConnectionException exception"
);
...
...
StackExchange.Redis.Tests/ConnectingFailDetection.cs
View file @
15cb2b12
using
System.Threading
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
Xunit
;
using
Xunit
;
using
Xunit.Abstractions
;
using
Xunit.Abstractions
;
...
@@ -10,7 +11,7 @@ public class ConnectingFailDetection : TestBase
...
@@ -10,7 +11,7 @@ public class ConnectingFailDetection : TestBase
#if DEBUG
#if DEBUG
[
Fact
]
[
Fact
]
public
void
FastNoticesFailOnConnectingSyncComlpetion
()
public
async
Task
FastNoticesFailOnConnectingSyncComlpetion
()
{
{
try
try
{
{
...
@@ -38,7 +39,7 @@ public void FastNoticesFailOnConnectingSyncComlpetion()
...
@@ -38,7 +39,7 @@ public void FastNoticesFailOnConnectingSyncComlpetion()
// should reconnect within 1 keepalive interval
// should reconnect within 1 keepalive interval
muxer
.
AllowConnect
=
true
;
muxer
.
AllowConnect
=
true
;
Log
(
"Waiting for reconnect"
);
Log
(
"Waiting for reconnect"
);
Thread
.
Sleep
(
2000
);
await
Task
.
Delay
(
2000
).
ForAwait
(
);
Assert
.
True
(
muxer
.
IsConnected
);
Assert
.
True
(
muxer
.
IsConnected
);
}
}
...
@@ -69,7 +70,7 @@ public void ConnectsWhenBeginConnectCompletesSynchronously()
...
@@ -69,7 +70,7 @@ public void ConnectsWhenBeginConnectCompletesSynchronously()
}
}
[
Fact
]
[
Fact
]
public
void
FastNoticesFailOnConnectingAsyncComlpetion
()
public
async
Task
FastNoticesFailOnConnectingAsyncComlpetion
()
{
{
try
try
{
{
...
@@ -97,7 +98,7 @@ public void FastNoticesFailOnConnectingAsyncComlpetion()
...
@@ -97,7 +98,7 @@ public void FastNoticesFailOnConnectingAsyncComlpetion()
// should reconnect within 1 keepalive interval
// should reconnect within 1 keepalive interval
muxer
.
AllowConnect
=
true
;
muxer
.
AllowConnect
=
true
;
Log
(
"Waiting for reconnect"
);
Log
(
"Waiting for reconnect"
);
Thread
.
Sleep
(
2000
);
await
Task
.
Delay
(
2000
).
ForAwait
(
);
Assert
.
True
(
muxer
.
IsConnected
);
Assert
.
True
(
muxer
.
IsConnected
);
}
}
...
@@ -109,7 +110,7 @@ public void FastNoticesFailOnConnectingAsyncComlpetion()
...
@@ -109,7 +110,7 @@ public void FastNoticesFailOnConnectingAsyncComlpetion()
}
}
[
Fact
]
[
Fact
]
public
void
ReconnectsOnStaleConnection
()
public
async
Task
ReconnectsOnStaleConnection
()
{
{
try
try
{
{
...
@@ -121,11 +122,11 @@ public void ReconnectsOnStaleConnection()
...
@@ -121,11 +122,11 @@ public void ReconnectsOnStaleConnection()
Assert
.
True
(
muxer
.
IsConnected
);
Assert
.
True
(
muxer
.
IsConnected
);
PhysicalConnection
.
EmulateStaleConnection
=
true
;
PhysicalConnection
.
EmulateStaleConnection
=
true
;
Thread
.
Sleep
(
500
);
await
Task
.
Delay
(
500
).
ForAwait
(
);
Assert
.
False
(
muxer
.
IsConnected
);
Assert
.
False
(
muxer
.
IsConnected
);
PhysicalConnection
.
EmulateStaleConnection
=
false
;
PhysicalConnection
.
EmulateStaleConnection
=
false
;
Thread
.
Sleep
(
1000
);
await
Task
.
Delay
(
1000
).
ForAwait
(
);
Assert
.
True
(
muxer
.
IsConnected
);
Assert
.
True
(
muxer
.
IsConnected
);
}
}
}
}
...
...
StackExchange.Redis.Tests/ConnectionFailedErrors.cs
View file @
15cb2b12
using
System
;
using
System
;
using
System.Threading
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
Xunit
;
using
Xunit
;
using
Xunit.Abstractions
;
using
Xunit.Abstractions
;
...
@@ -12,7 +13,7 @@ public class ConnectionFailedErrors : TestBase
...
@@ -12,7 +13,7 @@ public class ConnectionFailedErrors : TestBase
[
Theory
]
[
Theory
]
[
InlineData
(
true
)]
[
InlineData
(
true
)]
[
InlineData
(
false
)]
[
InlineData
(
false
)]
public
void
SSLCertificateValidationError
(
bool
isCertValidationSucceeded
)
public
async
Task
SSLCertificateValidationError
(
bool
isCertValidationSucceeded
)
{
{
Skip
.
IfNoConfig
(
nameof
(
TestConfig
.
Config
.
AzureCacheServer
),
TestConfig
.
Current
.
AzureCacheServer
);
Skip
.
IfNoConfig
(
nameof
(
TestConfig
.
Config
.
AzureCacheServer
),
TestConfig
.
Current
.
AzureCacheServer
);
Skip
.
IfNoConfig
(
nameof
(
TestConfig
.
Config
.
AzureCachePassword
),
TestConfig
.
Current
.
AzureCachePassword
);
Skip
.
IfNoConfig
(
nameof
(
TestConfig
.
Config
.
AzureCachePassword
),
TestConfig
.
Current
.
AzureCachePassword
);
...
@@ -42,12 +43,12 @@ public void SSLCertificateValidationError(bool isCertValidationSucceeded)
...
@@ -42,12 +43,12 @@ public void SSLCertificateValidationError(bool isCertValidationSucceeded)
}
}
//wait for a second for connectionfailed event to fire
//wait for a second for connectionfailed event to fire
Thread
.
Sleep
(
1000
);
await
Task
.
Delay
(
1000
).
ForAwait
(
);
}
}
}
}
[
Fact
]
[
Fact
]
public
void
AuthenticationFailureError
()
public
async
Task
AuthenticationFailureError
()
{
{
Skip
.
IfNoConfig
(
nameof
(
TestConfig
.
Config
.
AzureCacheServer
),
TestConfig
.
Current
.
AzureCacheServer
);
Skip
.
IfNoConfig
(
nameof
(
TestConfig
.
Config
.
AzureCacheServer
),
TestConfig
.
Current
.
AzureCacheServer
);
...
@@ -66,7 +67,7 @@ public void AuthenticationFailureError()
...
@@ -66,7 +67,7 @@ public void AuthenticationFailureError()
Assert
.
Equal
(
ConnectionFailureType
.
AuthenticationFailure
,
rde
.
FailureType
);
Assert
.
Equal
(
ConnectionFailureType
.
AuthenticationFailure
,
rde
.
FailureType
);
Assert
.
Equal
(
"Error: NOAUTH Authentication required. Verify if the Redis password provided is correct."
,
rde
.
InnerException
.
Message
);
Assert
.
Equal
(
"Error: NOAUTH Authentication required. Verify if the Redis password provided is correct."
,
rde
.
InnerException
.
Message
);
//wait for a second for connectionfailed event to fire
//wait for a second for connectionfailed event to fire
Thread
.
Sleep
(
1000
);
await
Task
.
Delay
(
1000
).
ForAwait
(
);
}
}
}
}
...
@@ -108,7 +109,7 @@ public void AbortOnConnectFailFalseConnectTimeoutError()
...
@@ -108,7 +109,7 @@ public void AbortOnConnectFailFalseConnectTimeoutError()
}
}
[
Fact
]
[
Fact
]
public
void
CheckFailureRecovered
()
public
async
Task
CheckFailureRecovered
()
{
{
try
try
{
{
...
@@ -125,7 +126,7 @@ public void CheckFailureRecovered()
...
@@ -125,7 +126,7 @@ public void CheckFailureRecovered()
// should reconnect within 1 keepalive interval
// should reconnect within 1 keepalive interval
muxer
.
AllowConnect
=
true
;
muxer
.
AllowConnect
=
true
;
Thread
.
Sleep
(
2000
);
await
Task
.
Delay
(
2000
).
ForAwait
(
);
Assert
.
Null
(
muxer
.
GetServerSnapshot
()[
0
].
LastException
);
Assert
.
Null
(
muxer
.
GetServerSnapshot
()[
0
].
LastException
);
}
}
...
...
StackExchange.Redis.Tests/ConnectionShutdown.cs
View file @
15cb2b12
using
System.Diagnostics
;
using
System.Diagnostics
;
using
System.Threading
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
Xunit
;
using
Xunit
;
using
Xunit.Abstractions
;
using
Xunit.Abstractions
;
...
@@ -11,7 +12,7 @@ public class ConnectionShutdown : TestBase
...
@@ -11,7 +12,7 @@ public class ConnectionShutdown : TestBase
public
ConnectionShutdown
(
ITestOutputHelper
output
)
:
base
(
output
)
{
}
public
ConnectionShutdown
(
ITestOutputHelper
output
)
:
base
(
output
)
{
}
[
Fact
(
Skip
=
"Unfriendly"
)]
[
Fact
(
Skip
=
"Unfriendly"
)]
public
void
ShutdownRaisesConnectionFailedAndRestore
()
public
async
Task
ShutdownRaisesConnectionFailedAndRestore
()
{
{
using
(
var
conn
=
Create
(
allowAdmin
:
true
))
using
(
var
conn
=
Create
(
allowAdmin
:
true
))
{
{
...
@@ -31,6 +32,7 @@ public void ShutdownRaisesConnectionFailedAndRestore()
...
@@ -31,6 +32,7 @@ public void ShutdownRaisesConnectionFailedAndRestore()
db
.
Ping
();
db
.
Ping
();
Assert
.
Equal
(
0
,
Interlocked
.
CompareExchange
(
ref
failed
,
0
,
0
));
Assert
.
Equal
(
0
,
Interlocked
.
CompareExchange
(
ref
failed
,
0
,
0
));
Assert
.
Equal
(
0
,
Interlocked
.
CompareExchange
(
ref
restored
,
0
,
0
));
Assert
.
Equal
(
0
,
Interlocked
.
CompareExchange
(
ref
restored
,
0
,
0
));
await
Task
.
Delay
(
1
).
ForAwait
();
// To make compiler happy in Release
#if DEBUG
#if DEBUG
conn
.
AllowConnect
=
false
;
conn
.
AllowConnect
=
false
;
...
@@ -40,12 +42,12 @@ public void ShutdownRaisesConnectionFailedAndRestore()
...
@@ -40,12 +42,12 @@ public void ShutdownRaisesConnectionFailedAndRestore()
server
.
SimulateConnectionFailure
();
server
.
SimulateConnectionFailure
();
db
.
Ping
(
CommandFlags
.
FireAndForget
);
db
.
Ping
(
CommandFlags
.
FireAndForget
);
Thread
.
Sleep
(
250
);
await
Task
.
Delay
(
250
).
ForAwait
(
);
Assert
.
Equal
(
2
,
Interlocked
.
CompareExchange
(
ref
failed
,
0
,
0
));
Assert
.
Equal
(
2
,
Interlocked
.
CompareExchange
(
ref
failed
,
0
,
0
));
Assert
.
Equal
(
0
,
Interlocked
.
CompareExchange
(
ref
restored
,
0
,
0
));
Assert
.
Equal
(
0
,
Interlocked
.
CompareExchange
(
ref
restored
,
0
,
0
));
conn
.
AllowConnect
=
true
;
conn
.
AllowConnect
=
true
;
db
.
Ping
(
CommandFlags
.
FireAndForget
);
db
.
Ping
(
CommandFlags
.
FireAndForget
);
Thread
.
Sleep
(
1500
);
await
Task
.
Delay
(
1500
).
ForAwait
(
);
Assert
.
Equal
(
2
,
Interlocked
.
CompareExchange
(
ref
failed
,
0
,
0
));
Assert
.
Equal
(
2
,
Interlocked
.
CompareExchange
(
ref
failed
,
0
,
0
));
Assert
.
Equal
(
2
,
Interlocked
.
CompareExchange
(
ref
restored
,
0
,
0
));
Assert
.
Equal
(
2
,
Interlocked
.
CompareExchange
(
ref
restored
,
0
,
0
));
#endif
#endif
...
...
StackExchange.Redis.Tests/Failover.cs
View file @
15cb2b12
...
@@ -50,7 +50,7 @@ public async Task ConfigureAsync()
...
@@ -50,7 +50,7 @@ public async Task ConfigureAsync()
{
{
using
(
var
muxer
=
Create
())
using
(
var
muxer
=
Create
())
{
{
Thread
.
Sleep
(
1000
);
await
Task
.
Delay
(
1000
).
ForAwait
(
);
Log
(
"About to reconfigure....."
);
Log
(
"About to reconfigure....."
);
await
muxer
.
ConfigureAsync
().
ForAwait
();
await
muxer
.
ConfigureAsync
().
ForAwait
();
Log
(
"Reconfigured"
);
Log
(
"Reconfigured"
);
...
@@ -58,11 +58,11 @@ public async Task ConfigureAsync()
...
@@ -58,11 +58,11 @@ public async Task ConfigureAsync()
}
}
[
Fact
]
[
Fact
]
public
void
ConfigureSync
()
public
async
Task
ConfigureSync
()
{
{
using
(
var
muxer
=
Create
())
using
(
var
muxer
=
Create
())
{
{
Thread
.
Sleep
(
1000
);
await
Task
.
Delay
(
1000
).
ForAwait
(
);
Log
(
"About to reconfigure....."
);
Log
(
"About to reconfigure....."
);
muxer
.
Configure
();
muxer
.
Configure
();
Log
(
"Reconfigured"
);
Log
(
"Reconfigured"
);
...
...
StackExchange.Redis.Tests/Issues/SO24807536.cs
View file @
15cb2b12
using
System
;
using
System
;
using
System.Threading
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
Xunit
;
using
Xunit
;
using
Xunit.Abstractions
;
using
Xunit.Abstractions
;
...
@@ -10,7 +11,7 @@ public class SO24807536 : TestBase
...
@@ -10,7 +11,7 @@ public class SO24807536 : TestBase
public
SO24807536
(
ITestOutputHelper
output
)
:
base
(
output
)
{
}
public
SO24807536
(
ITestOutputHelper
output
)
:
base
(
output
)
{
}
[
Fact
]
[
Fact
]
public
void
Exec
()
public
async
Task
Exec
()
{
{
var
key
=
Me
();
var
key
=
Me
();
using
(
var
conn
=
Create
())
using
(
var
conn
=
Create
())
...
@@ -31,7 +32,7 @@ public void Exec()
...
@@ -31,7 +32,7 @@ public void Exec()
Assert
.
Equal
(
"some value"
,
fullWait
.
Result
);
Assert
.
Equal
(
"some value"
,
fullWait
.
Result
);
// wait for expiry
// wait for expiry
Thread
.
Sleep
(
TimeSpan
.
FromSeconds
(
4
)
);
await
Task
.
Delay
(
4000
).
ForAwait
(
);
// test once expired
// test once expired
keyExists
=
cache
.
KeyExists
(
key
);
keyExists
=
cache
.
KeyExists
(
key
);
...
...
StackExchange.Redis.Tests/Profiling.cs
View file @
15cb2b12
...
@@ -280,7 +280,7 @@ private object LeaksCollectedAndRePooled_Initialize(ConnectionMultiplexer conn,
...
@@ -280,7 +280,7 @@ private object LeaksCollectedAndRePooled_Initialize(ConnectionMultiplexer conn,
}
}
[
FactLongRunning
]
[
FactLongRunning
]
public
void
LeaksCollectedAndRePooled
()
public
async
Task
LeaksCollectedAndRePooled
()
{
{
const
int
ThreadCount
=
16
;
const
int
ThreadCount
=
16
;
...
@@ -292,7 +292,7 @@ public void LeaksCollectedAndRePooled()
...
@@ -292,7 +292,7 @@ public void LeaksCollectedAndRePooled()
GC
.
Collect
(
3
,
GCCollectionMode
.
Forced
,
blocking
:
true
);
GC
.
Collect
(
3
,
GCCollectionMode
.
Forced
,
blocking
:
true
);
GC
.
WaitForPendingFinalizers
();
GC
.
WaitForPendingFinalizers
();
Thread
.
Sleep
(
TimeSpan
.
FromMinutes
(
1.01
)
);
await
Task
.
Delay
(
TimeSpan
.
FromMinutes
(
1.01
)).
ForAwait
(
);
conn
.
FinishProfiling
(
anyContext
);
conn
.
FinishProfiling
(
anyContext
);
// make sure we haven't left anything in the active contexts dictionary
// make sure we haven't left anything in the active contexts dictionary
...
...
StackExchange.Redis.Tests/PubSub.cs
View file @
15cb2b12
...
@@ -12,7 +12,7 @@ public class PubSub : TestBase
...
@@ -12,7 +12,7 @@ public class PubSub : TestBase
public
PubSub
(
ITestOutputHelper
output
)
:
base
(
output
)
{
}
public
PubSub
(
ITestOutputHelper
output
)
:
base
(
output
)
{
}
[
Fact
]
[
Fact
]
public
void
ExplicitPublishMode
()
public
async
Task
ExplicitPublishMode
()
{
{
using
(
var
mx
=
Create
(
channelPrefix
:
"foo:"
))
using
(
var
mx
=
Create
(
channelPrefix
:
"foo:"
))
{
{
...
@@ -23,16 +23,16 @@ public void ExplicitPublishMode()
...
@@ -23,16 +23,16 @@ public void ExplicitPublishMode()
pub
.
Subscribe
(
new
RedisChannel
(
"ab*d"
,
RedisChannel
.
PatternMode
.
Auto
),
(
x
,
y
)
=>
Interlocked
.
Increment
(
ref
c
));
pub
.
Subscribe
(
new
RedisChannel
(
"ab*d"
,
RedisChannel
.
PatternMode
.
Auto
),
(
x
,
y
)
=>
Interlocked
.
Increment
(
ref
c
));
pub
.
Subscribe
(
"abc*"
,
(
x
,
y
)
=>
Interlocked
.
Increment
(
ref
d
));
pub
.
Subscribe
(
"abc*"
,
(
x
,
y
)
=>
Interlocked
.
Increment
(
ref
d
));
Thread
.
Sleep
(
1000
);
await
Task
.
Delay
(
4100
).
ForAwait
(
);
pub
.
Publish
(
"abcd"
,
"efg"
);
pub
.
Publish
(
"abcd"
,
"efg"
);
Thread
.
Sleep
(
500
);
await
Task
.
Delay
(
500
).
ForAwait
(
);
Assert
.
Equal
(
0
,
Thread
.
VolatileRead
(
ref
a
));
Assert
.
Equal
(
0
,
Thread
.
VolatileRead
(
ref
a
));
Assert
.
Equal
(
1
,
Thread
.
VolatileRead
(
ref
b
));
Assert
.
Equal
(
1
,
Thread
.
VolatileRead
(
ref
b
));
Assert
.
Equal
(
1
,
Thread
.
VolatileRead
(
ref
c
));
Assert
.
Equal
(
1
,
Thread
.
VolatileRead
(
ref
c
));
Assert
.
Equal
(
1
,
Thread
.
VolatileRead
(
ref
d
));
Assert
.
Equal
(
1
,
Thread
.
VolatileRead
(
ref
d
));
pub
.
Publish
(
"*bcd"
,
"efg"
);
pub
.
Publish
(
"*bcd"
,
"efg"
);
Thread
.
Sleep
(
500
);
await
Task
.
Delay
(
500
).
ForAwait
(
);
Assert
.
Equal
(
1
,
Thread
.
VolatileRead
(
ref
a
));
Assert
.
Equal
(
1
,
Thread
.
VolatileRead
(
ref
a
));
//Assert.Equal(1, Thread.VolatileRead(ref b));
//Assert.Equal(1, Thread.VolatileRead(ref b));
//Assert.Equal(1, Thread.VolatileRead(ref c));
//Assert.Equal(1, Thread.VolatileRead(ref c));
...
@@ -48,13 +48,13 @@ public void ExplicitPublishMode()
...
@@ -48,13 +48,13 @@ public void ExplicitPublishMode()
[
InlineData
(
null
,
true
,
"d"
)]
[
InlineData
(
null
,
true
,
"d"
)]
[
InlineData
(
""
,
true
,
"e"
)]
[
InlineData
(
""
,
true
,
"e"
)]
[
InlineData
(
"Foo:"
,
true
,
"f"
)]
[
InlineData
(
"Foo:"
,
true
,
"f"
)]
public
void
TestBasicPubSub
(
string
channelPrefix
,
bool
wildCard
,
string
breaker
)
public
async
Task
TestBasicPubSub
(
string
channelPrefix
,
bool
wildCard
,
string
breaker
)
{
{
using
(
var
muxer
=
Create
(
channelPrefix
:
channelPrefix
))
using
(
var
muxer
=
Create
(
channelPrefix
:
channelPrefix
))
{
{
var
pub
=
GetAnyMaster
(
muxer
);
var
pub
=
GetAnyMaster
(
muxer
);
var
sub
=
muxer
.
GetSubscriber
();
var
sub
=
muxer
.
GetSubscriber
();
Ping
(
muxer
,
pub
,
sub
);
await
PingAsync
(
muxer
,
pub
,
sub
).
ForAwait
(
);
HashSet
<
string
>
received
=
new
HashSet
<
string
>();
HashSet
<
string
>
received
=
new
HashSet
<
string
>();
int
secondHandler
=
0
;
int
secondHandler
=
0
;
string
subChannel
=
(
wildCard
?
"a*c"
:
"abc"
)
+
breaker
;
string
subChannel
=
(
wildCard
?
"a*c"
:
"abc"
)
+
breaker
;
...
@@ -84,7 +84,7 @@ public void TestBasicPubSub(string channelPrefix, bool wildCard, string breaker)
...
@@ -84,7 +84,7 @@ public void TestBasicPubSub(string channelPrefix, bool wildCard, string breaker)
Assert
.
Equal
(
0
,
Thread
.
VolatileRead
(
ref
secondHandler
));
Assert
.
Equal
(
0
,
Thread
.
VolatileRead
(
ref
secondHandler
));
var
count
=
sub
.
Publish
(
pubChannel
,
"def"
);
var
count
=
sub
.
Publish
(
pubChannel
,
"def"
);
Ping
(
muxer
,
pub
,
sub
,
3
);
await
PingAsync
(
muxer
,
pub
,
sub
,
3
).
ForAwait
(
);
lock
(
received
)
lock
(
received
)
{
{
...
@@ -95,7 +95,7 @@ public void TestBasicPubSub(string channelPrefix, bool wildCard, string breaker)
...
@@ -95,7 +95,7 @@ public void TestBasicPubSub(string channelPrefix, bool wildCard, string breaker)
// unsubscribe from first; should still see second
// unsubscribe from first; should still see second
sub
.
Unsubscribe
(
subChannel
,
handler1
);
sub
.
Unsubscribe
(
subChannel
,
handler1
);
count
=
sub
.
Publish
(
pubChannel
,
"ghi"
);
count
=
sub
.
Publish
(
pubChannel
,
"ghi"
);
Ping
(
muxer
,
pub
,
sub
);
await
PingAsync
(
muxer
,
pub
,
sub
).
ForAwait
(
);
lock
(
received
)
lock
(
received
)
{
{
Assert
.
Single
(
received
);
Assert
.
Single
(
received
);
...
@@ -106,7 +106,7 @@ public void TestBasicPubSub(string channelPrefix, bool wildCard, string breaker)
...
@@ -106,7 +106,7 @@ public void TestBasicPubSub(string channelPrefix, bool wildCard, string breaker)
// unsubscribe from second; should see nothing this time
// unsubscribe from second; should see nothing this time
sub
.
Unsubscribe
(
subChannel
,
handler2
);
sub
.
Unsubscribe
(
subChannel
,
handler2
);
count
=
sub
.
Publish
(
pubChannel
,
"ghi"
);
count
=
sub
.
Publish
(
pubChannel
,
"ghi"
);
Ping
(
muxer
,
pub
,
sub
);
await
PingAsync
(
muxer
,
pub
,
sub
).
ForAwait
(
);
lock
(
received
)
lock
(
received
)
{
{
Assert
.
Single
(
received
);
Assert
.
Single
(
received
);
...
@@ -117,7 +117,7 @@ public void TestBasicPubSub(string channelPrefix, bool wildCard, string breaker)
...
@@ -117,7 +117,7 @@ public void TestBasicPubSub(string channelPrefix, bool wildCard, string breaker)
}
}
[
Fact
]
[
Fact
]
public
void
TestBasicPubSubFireAndForget
()
public
async
Task
TestBasicPubSubFireAndForget
()
{
{
using
(
var
muxer
=
Create
())
using
(
var
muxer
=
Create
())
{
{
...
@@ -127,7 +127,7 @@ public void TestBasicPubSubFireAndForget()
...
@@ -127,7 +127,7 @@ public void TestBasicPubSubFireAndForget()
RedisChannel
key
=
Guid
.
NewGuid
().
ToString
();
RedisChannel
key
=
Guid
.
NewGuid
().
ToString
();
HashSet
<
string
>
received
=
new
HashSet
<
string
>();
HashSet
<
string
>
received
=
new
HashSet
<
string
>();
int
secondHandler
=
0
;
int
secondHandler
=
0
;
Ping
(
muxer
,
pub
,
sub
);
await
PingAsync
(
muxer
,
pub
,
sub
).
ForAwait
(
);
sub
.
Subscribe
(
key
,
(
channel
,
payload
)
=>
sub
.
Subscribe
(
key
,
(
channel
,
payload
)
=>
{
{
lock
(
received
)
lock
(
received
)
...
@@ -146,9 +146,9 @@ public void TestBasicPubSubFireAndForget()
...
@@ -146,9 +146,9 @@ public void TestBasicPubSubFireAndForget()
Assert
.
Empty
(
received
);
Assert
.
Empty
(
received
);
}
}
Assert
.
Equal
(
0
,
Thread
.
VolatileRead
(
ref
secondHandler
));
Assert
.
Equal
(
0
,
Thread
.
VolatileRead
(
ref
secondHandler
));
Ping
(
muxer
,
pub
,
sub
);
await
PingAsync
(
muxer
,
pub
,
sub
).
ForAwait
(
);
var
count
=
sub
.
Publish
(
key
,
"def"
,
CommandFlags
.
FireAndForget
);
var
count
=
sub
.
Publish
(
key
,
"def"
,
CommandFlags
.
FireAndForget
);
Ping
(
muxer
,
pub
,
sub
);
await
PingAsync
(
muxer
,
pub
,
sub
).
ForAwait
(
);
lock
(
received
)
lock
(
received
)
{
{
...
@@ -159,7 +159,7 @@ public void TestBasicPubSubFireAndForget()
...
@@ -159,7 +159,7 @@ public void TestBasicPubSubFireAndForget()
sub
.
Unsubscribe
(
key
);
sub
.
Unsubscribe
(
key
);
count
=
sub
.
Publish
(
key
,
"ghi"
,
CommandFlags
.
FireAndForget
);
count
=
sub
.
Publish
(
key
,
"ghi"
,
CommandFlags
.
FireAndForget
);
Ping
(
muxer
,
pub
,
sub
);
await
PingAsync
(
muxer
,
pub
,
sub
).
ForAwait
(
);
lock
(
received
)
lock
(
received
)
{
{
...
@@ -169,7 +169,7 @@ public void TestBasicPubSubFireAndForget()
...
@@ -169,7 +169,7 @@ public void TestBasicPubSubFireAndForget()
}
}
}
}
private
static
void
Ping
(
ConnectionMultiplexer
muxer
,
IServer
pub
,
ISubscriber
sub
,
int
times
=
1
)
private
static
async
Task
PingAsync
(
ConnectionMultiplexer
muxer
,
IServer
pub
,
ISubscriber
sub
,
int
times
=
1
)
{
{
while
(
times
--
>
0
)
while
(
times
--
>
0
)
{
{
...
@@ -177,14 +177,14 @@ private static void Ping(ConnectionMultiplexer muxer, IServer pub, ISubscriber s
...
@@ -177,14 +177,14 @@ private static void Ping(ConnectionMultiplexer muxer, IServer pub, ISubscriber s
// way to prove that is to use TPL objects
// way to prove that is to use TPL objects
var
t1
=
sub
.
PingAsync
();
var
t1
=
sub
.
PingAsync
();
var
t2
=
pub
.
PingAsync
();
var
t2
=
pub
.
PingAsync
();
Thread
.
Sleep
(
100
);
// especially useful when testing any-order mode
await
Task
.
Delay
(
100
).
ForAwait
(
);
// especially useful when testing any-order mode
if
(!
Task
.
WaitAll
(
new
[]
{
t1
,
t2
},
muxer
.
TimeoutMilliseconds
*
2
))
throw
new
TimeoutException
();
if
(!
Task
.
WaitAll
(
new
[]
{
t1
,
t2
},
muxer
.
TimeoutMilliseconds
*
2
))
throw
new
TimeoutException
();
}
}
}
}
[
Fact
]
[
Fact
]
public
void
TestPatternPubSub
()
public
async
Task
TestPatternPubSub
()
{
{
using
(
var
muxer
=
Create
())
using
(
var
muxer
=
Create
())
{
{
...
@@ -212,7 +212,7 @@ public void TestPatternPubSub()
...
@@ -212,7 +212,7 @@ public void TestPatternPubSub()
Assert
.
Equal
(
0
,
Thread
.
VolatileRead
(
ref
secondHandler
));
Assert
.
Equal
(
0
,
Thread
.
VolatileRead
(
ref
secondHandler
));
var
count
=
sub
.
Publish
(
"abc"
,
"def"
);
var
count
=
sub
.
Publish
(
"abc"
,
"def"
);
Ping
(
muxer
,
pub
,
sub
);
await
PingAsync
(
muxer
,
pub
,
sub
).
ForAwait
(
);
lock
(
received
)
lock
(
received
)
{
{
...
@@ -223,7 +223,7 @@ public void TestPatternPubSub()
...
@@ -223,7 +223,7 @@ public void TestPatternPubSub()
sub
.
Unsubscribe
(
"a*c"
);
sub
.
Unsubscribe
(
"a*c"
);
count
=
sub
.
Publish
(
"abc"
,
"ghi"
);
count
=
sub
.
Publish
(
"abc"
,
"ghi"
);
Ping
(
muxer
,
pub
,
sub
);
await
PingAsync
(
muxer
,
pub
,
sub
).
ForAwait
(
);
lock
(
received
)
lock
(
received
)
{
{
...
...
StackExchange.Redis.Tests/RealWorld.cs
View file @
15cb2b12
using
System.Threading
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
Xunit
;
using
Xunit
;
using
Xunit.Abstractions
;
using
Xunit.Abstractions
;
...
@@ -9,7 +10,7 @@ public class RealWorld : TestBase
...
@@ -9,7 +10,7 @@ public class RealWorld : TestBase
public
RealWorld
(
ITestOutputHelper
output
)
:
base
(
output
)
{
}
public
RealWorld
(
ITestOutputHelper
output
)
:
base
(
output
)
{
}
[
Fact
]
[
Fact
]
public
void
WhyDoesThisNotWork
()
public
async
Task
WhyDoesThisNotWork
()
{
{
Log
(
"first:"
);
Log
(
"first:"
);
var
config
=
ConfigurationOptions
.
Parse
(
"localhost:6379,localhost:6380,name=Core (Q&A),tiebreaker=:RedisMaster,abortConnect=False"
);
var
config
=
ConfigurationOptions
.
Parse
(
"localhost:6379,localhost:6380,name=Core (Q&A),tiebreaker=:RedisMaster,abortConnect=False"
);
...
@@ -21,7 +22,7 @@ public void WhyDoesThisNotWork()
...
@@ -21,7 +22,7 @@ public void WhyDoesThisNotWork()
{
{
Log
(
""
);
Log
(
""
);
Log
(
"pausing..."
);
Log
(
"pausing..."
);
Thread
.
Sleep
(
200
);
await
Task
.
Delay
(
200
).
ForAwait
(
);
Log
(
"second:"
);
Log
(
"second:"
);
bool
result
=
conn
.
Configure
(
Writer
);
bool
result
=
conn
.
Configure
(
Writer
);
...
...
StackExchange.Redis.Tests/TestInfoReplicationChecks.cs
View file @
15cb2b12
using
System
;
using
System
;
using
System.Threading
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
Xunit
;
using
Xunit
;
using
Xunit.Abstractions
;
using
Xunit.Abstractions
;
...
@@ -11,14 +12,14 @@ public class TestInfoReplicationChecks : TestBase
...
@@ -11,14 +12,14 @@ public class TestInfoReplicationChecks : TestBase
public
TestInfoReplicationChecks
(
ITestOutputHelper
output
)
:
base
(
output
)
{
}
public
TestInfoReplicationChecks
(
ITestOutputHelper
output
)
:
base
(
output
)
{
}
[
Fact
]
[
Fact
]
public
void
Exec
()
public
async
Task
Exec
()
{
{
using
(
var
conn
=
Create
())
using
(
var
conn
=
Create
())
{
{
var
parsed
=
ConfigurationOptions
.
Parse
(
conn
.
Configuration
);
var
parsed
=
ConfigurationOptions
.
Parse
(
conn
.
Configuration
);
Assert
.
Equal
(
2
,
parsed
.
ConfigCheckSeconds
);
Assert
.
Equal
(
2
,
parsed
.
ConfigCheckSeconds
);
var
before
=
conn
.
GetCounters
();
var
before
=
conn
.
GetCounters
();
Thread
.
Sleep
(
TimeSpan
.
FromSeconds
(
7
)
);
await
Task
.
Delay
(
7000
).
ForAwait
(
);
var
after
=
conn
.
GetCounters
();
var
after
=
conn
.
GetCounters
();
int
done
=
(
int
)(
after
.
Interactive
.
CompletedSynchronously
-
before
.
Interactive
.
CompletedSynchronously
);
int
done
=
(
int
)(
after
.
Interactive
.
CompletedSynchronously
-
before
.
Interactive
.
CompletedSynchronously
);
Assert
.
True
(
done
>=
2
);
Assert
.
True
(
done
>=
2
);
...
...
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