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
be2fb0e5
Commit
be2fb0e5
authored
Jun 03, 2018
by
Nick Craver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tests: ensure setup on each failover run
parent
8c548885
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
108 additions
and
116 deletions
+108
-116
Failover.cs
StackExchange.Redis.Tests/Failover.cs
+108
-116
No files found.
StackExchange.Redis.Tests/Failover.cs
View file @
be2fb0e5
...
@@ -9,7 +9,30 @@ namespace StackExchange.Redis.Tests
...
@@ -9,7 +9,30 @@ namespace StackExchange.Redis.Tests
public
class
Failover
:
TestBase
public
class
Failover
:
TestBase
{
{
protected
override
string
GetConfiguration
()
=>
GetMasterSlaveConfig
().
ToString
();
protected
override
string
GetConfiguration
()
=>
GetMasterSlaveConfig
().
ToString
();
public
Failover
(
ITestOutputHelper
output
)
:
base
(
output
)
{
}
public
Failover
(
ITestOutputHelper
output
)
:
base
(
output
)
{
using
(
var
mutex
=
Create
())
{
var
shouldBeMaster
=
mutex
.
GetServer
(
TestConfig
.
Current
.
FailoverMasterServerAndPort
);
if
(
shouldBeMaster
.
IsSlave
)
{
Output
.
WriteLine
(
shouldBeMaster
.
EndPoint
+
" should be master, fixing..."
);
shouldBeMaster
.
MakeMaster
(
ReplicationChangeOptions
.
SetTiebreaker
);
}
Output
.
WriteLine
(
"Flushing all databases..."
);
shouldBeMaster
.
FlushAllDatabases
(
CommandFlags
.
FireAndForget
);
var
shouldBeReplica
=
mutex
.
GetServer
(
TestConfig
.
Current
.
FailoverSlaveServerAndPort
);
if
(!
shouldBeReplica
.
IsSlave
)
{
Output
.
WriteLine
(
shouldBeReplica
.
EndPoint
+
" should be a slave, fixing..."
);
shouldBeReplica
.
SlaveOf
(
shouldBeMaster
.
EndPoint
);
Thread
.
Sleep
(
2000
);
}
}
}
private
static
ConfigurationOptions
GetMasterSlaveConfig
()
private
static
ConfigurationOptions
GetMasterSlaveConfig
()
{
{
...
@@ -154,10 +177,6 @@ public async Task SubscriptionsSurviveMasterSwitchAsync(bool useSharedSocketMana
...
@@ -154,10 +177,6 @@ public async Task SubscriptionsSurviveMasterSwitchAsync(bool useSharedSocketMana
using
(
var
a
=
Create
(
allowAdmin
:
true
,
useSharedSocketManager
:
useSharedSocketManager
))
using
(
var
a
=
Create
(
allowAdmin
:
true
,
useSharedSocketManager
:
useSharedSocketManager
))
using
(
var
b
=
Create
(
allowAdmin
:
true
,
useSharedSocketManager
:
useSharedSocketManager
))
using
(
var
b
=
Create
(
allowAdmin
:
true
,
useSharedSocketManager
:
useSharedSocketManager
))
{
{
try
{
// Ensure config setup
await
EnsureMasterSlaveSetupAsync
(
a
).
ForAwait
();
RedisChannel
channel
=
Me
();
RedisChannel
channel
=
Me
();
var
subA
=
a
.
GetSubscriber
();
var
subA
=
a
.
GetSubscriber
();
var
subB
=
b
.
GetSubscriber
();
var
subB
=
b
.
GetSubscriber
();
...
@@ -257,33 +276,6 @@ public async Task SubscriptionsSurviveMasterSwitchAsync(bool useSharedSocketMana
...
@@ -257,33 +276,6 @@ public async Task SubscriptionsSurviveMasterSwitchAsync(bool useSharedSocketMana
catch
{
}
catch
{
}
}
}
}
}
finally
{
// Put it back, even if we fail...
await
EnsureMasterSlaveSetupAsync
(
a
);
}
}
}
protected
async
Task
EnsureMasterSlaveSetupAsync
(
ConnectionMultiplexer
mutex
)
{
var
shouldBeMaster
=
mutex
.
GetServer
(
TestConfig
.
Current
.
FailoverMasterServerAndPort
);
if
(
shouldBeMaster
.
IsSlave
)
{
Output
.
WriteLine
(
shouldBeMaster
.
EndPoint
+
" should be master, fixing..."
);
shouldBeMaster
.
MakeMaster
(
ReplicationChangeOptions
.
SetTiebreaker
);
}
Output
.
WriteLine
(
"Flushing all databases..."
);
shouldBeMaster
.
FlushAllDatabases
(
CommandFlags
.
FireAndForget
);
var
shouldBeReplica
=
mutex
.
GetServer
(
TestConfig
.
Current
.
FailoverSlaveServerAndPort
);
if
(!
shouldBeReplica
.
IsSlave
)
{
Output
.
WriteLine
(
shouldBeReplica
.
EndPoint
+
" should be a slave, fixing..."
);
shouldBeReplica
.
SlaveOf
(
shouldBeMaster
.
EndPoint
);
await
Task
.
Delay
(
1000
).
ForAwait
();
}
}
}
}
}
}
}
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