Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
autoradio
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ale
autoradio
Commits
b5bbadcc
Commit
b5bbadcc
authored
10 years ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
fix masterelection_test to force master transitions
parent
f97437ba
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
masterelection/masterelection_test.go
+28
-6
28 additions, 6 deletions
masterelection/masterelection_test.go
with
28 additions
and
6 deletions
masterelection/masterelection_test.go
+
28
−
6
View file @
b5bbadcc
...
...
@@ -2,7 +2,9 @@ package masterelection
import
(
"fmt"
"log"
"math/rand"
"os"
"testing"
"time"
...
...
@@ -26,7 +28,9 @@ func countMasters(nodes []*MasterElection) int {
func
verifyMasterData
(
t
*
testing
.
T
,
nodes
[]
*
MasterElection
)
{
tmp
:=
make
(
map
[
string
]
struct
{})
for
_
,
n
:=
range
nodes
{
tmp
[
n
.
GetMasterData
()]
=
struct
{}{}
if
n
!=
nil
{
tmp
[
n
.
GetMasterData
()]
=
struct
{}{}
}
}
if
len
(
tmp
)
!=
1
{
t
.
Errorf
(
"master data propagation error: >1 values: %v"
,
tmp
)
...
...
@@ -49,18 +53,36 @@ func TestMasterElection(t *testing.T) {
fmt
.
Sprintf
(
"%d"
,
i
),
1
,
nil
)
m
.
Log
Prefix
=
fmt
.
Sprintf
(
"node%d: masterelection"
,
i
+
1
)
m
.
Log
=
log
.
New
(
os
.
Stderr
,
fmt
.
Sprintf
(
"node%d: masterelection
:
"
,
i
+
1
)
,
0
)
go
m
.
Run
(
stopCh
)
nodes
=
append
(
nodes
,
m
)
stop
=
append
(
stop
,
stopCh
)
}
// Force master transitions by shutting down the nodes one by
// one as the become the master, and verify that there is a
// single master among the remaining ones.
for
i
:=
0
;
i
<
n
;
i
++
{
time
.
Sleep
(
100
*
time
.
Millisecond
)
if
nm
:=
countMasters
(
nodes
[
i
:
len
(
nodes
)]);
nm
!=
1
{
t
.
Errorf
(
"@%d: masters=%d (expected <= 1)"
,
i
,
nm
)
masterIdx
:=
-
1
numMasters
:=
0
for
i
,
m
:=
range
nodes
{
if
m
==
nil
{
continue
}
if
m
.
IsMaster
()
{
numMasters
++
masterIdx
=
i
}
}
verifyMasterData
(
t
,
nodes
[
i
:
len
(
nodes
)])
close
(
stop
[
i
])
if
numMasters
!=
1
{
t
.
Fatalf
(
"masters=%d (expected 1): %#v"
,
numMasters
,
nodes
)
}
verifyMasterData
(
t
,
nodes
)
close
(
stop
[
masterIdx
])
nodes
[
masterIdx
]
=
nil
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment