|
@@ -92,7 +92,7 @@ func TestAdd(t *testing.T) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
go es[0].Run()
|
|
go es[0].Run()
|
|
|
- <-es[0].modeC
|
|
|
|
|
|
|
+ waitMode(participantMode, es[0])
|
|
|
|
|
|
|
|
for i := 1; i < tt; i++ {
|
|
for i := 1; i < tt; i++ {
|
|
|
id := int64(i)
|
|
id := int64(i)
|
|
@@ -117,7 +117,7 @@ func TestAdd(t *testing.T) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
go es[i].Run()
|
|
go es[i].Run()
|
|
|
- <-es[i].modeC
|
|
|
|
|
|
|
+ waitMode(participantMode, es[i])
|
|
|
|
|
|
|
|
for j := 0; j <= i; j++ {
|
|
for j := 0; j <= i; j++ {
|
|
|
p := fmt.Sprintf("%s/%d", v2machineKVPrefix, id)
|
|
p := fmt.Sprintf("%s/%d", v2machineKVPrefix, id)
|
|
@@ -189,9 +189,7 @@ func TestRemove(t *testing.T) {
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if g := <-es[i].modeC; g != standbyMode {
|
|
|
|
|
- t.Errorf("#%d on %d: mode = %d, want standby", k, i, g)
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ waitMode(standbyMode, es[i])
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
for i := range es {
|
|
for i := range es {
|
|
@@ -233,12 +231,7 @@ func TestBecomeStandby(t *testing.T) {
|
|
|
t.Fatalf("#%d: remove err = %v", i, err)
|
|
t.Fatalf("#%d: remove err = %v", i, err)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if g := <-es[i].modeC; g != standbyMode {
|
|
|
|
|
- t.Fatalf("#%d: mode = %d, want standby", i, g)
|
|
|
|
|
- }
|
|
|
|
|
- if g := len(es[i].modeC); g != 0 {
|
|
|
|
|
- t.Fatalf("#%d: mode to %d, want remain", i, <-es[i].modeC)
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ waitMode(standbyMode, es[i])
|
|
|
|
|
|
|
|
for k := 0; k < 4; k++ {
|
|
for k := 0; k < 4; k++ {
|
|
|
if es[i].s.leader != noneId {
|
|
if es[i].s.leader != noneId {
|
|
@@ -250,10 +243,6 @@ func TestBecomeStandby(t *testing.T) {
|
|
|
t.Errorf("#%d: lead = %d, want %d", i, g, lead)
|
|
t.Errorf("#%d: lead = %d, want %d", i, g, lead)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if g := len(es[i].modeC); g != 0 {
|
|
|
|
|
- t.Fatalf("#%d: mode to %d, want remain", i, <-es[i].modeC)
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
for i := range hs {
|
|
for i := range hs {
|
|
|
es[len(hs)-i-1].Stop()
|
|
es[len(hs)-i-1].Stop()
|
|
|
}
|
|
}
|
|
@@ -274,10 +263,6 @@ func TestModeSwitch(t *testing.T) {
|
|
|
es, hs := buildCluster(size, false)
|
|
es, hs := buildCluster(size, false)
|
|
|
waitCluster(t, es)
|
|
waitCluster(t, es)
|
|
|
|
|
|
|
|
- if g := <-es[i].modeC; g != participantMode {
|
|
|
|
|
- t.Fatalf("#%d: mode = %d, want participant", i, g)
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
config := config.NewClusterConfig()
|
|
config := config.NewClusterConfig()
|
|
|
config.SyncInterval = 0
|
|
config.SyncInterval = 0
|
|
|
id := int64(i)
|
|
id := int64(i)
|
|
@@ -296,12 +281,7 @@ func TestModeSwitch(t *testing.T) {
|
|
|
t.Fatalf("#%d: remove err = %v", i, err)
|
|
t.Fatalf("#%d: remove err = %v", i, err)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if g := <-es[i].modeC; g != standbyMode {
|
|
|
|
|
- t.Fatalf("#%d: mode = %d, want standby", i, g)
|
|
|
|
|
- }
|
|
|
|
|
- if g := len(es[i].modeC); g != 0 {
|
|
|
|
|
- t.Fatalf("#%d: mode to %d, want remain", i, <-es[i].modeC)
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ waitMode(standbyMode, es[i])
|
|
|
|
|
|
|
|
for k := 0; k < 4; k++ {
|
|
for k := 0; k < 4; k++ {
|
|
|
if es[i].s.leader != noneId {
|
|
if es[i].s.leader != noneId {
|
|
@@ -318,22 +298,13 @@ func TestModeSwitch(t *testing.T) {
|
|
|
t.Fatalf("#%d: setClusterConfig err = %v", i, err)
|
|
t.Fatalf("#%d: setClusterConfig err = %v", i, err)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if g := <-es[i].modeC; g != participantMode {
|
|
|
|
|
- t.Fatalf("#%d: mode = %d, want participant", i, g)
|
|
|
|
|
- }
|
|
|
|
|
- if g := len(es[i].modeC); g != 0 {
|
|
|
|
|
- t.Fatalf("#%d: mode to %d, want remain", i, <-es[i].modeC)
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ waitMode(participantMode, es[i])
|
|
|
|
|
|
|
|
if err := checkParticipant(i, es); err != nil {
|
|
if err := checkParticipant(i, es); err != nil {
|
|
|
t.Errorf("#%d: check alive err = %v", i, err)
|
|
t.Errorf("#%d: check alive err = %v", i, err)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if g := len(es[i].modeC); g != 0 {
|
|
|
|
|
- t.Fatalf("#%d: mode to %d, want remain", i, <-es[i].modeC)
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
for i := range hs {
|
|
for i := range hs {
|
|
|
es[len(hs)-i-1].Stop()
|
|
es[len(hs)-i-1].Stop()
|
|
|
}
|
|
}
|
|
@@ -369,7 +340,7 @@ func buildCluster(number int, tls bool) ([]*Server, []*httptest.Server) {
|
|
|
<-w.EventChan
|
|
<-w.EventChan
|
|
|
}
|
|
}
|
|
|
go es[i].Run()
|
|
go es[i].Run()
|
|
|
- <-es[i].modeC
|
|
|
|
|
|
|
+ waitMode(participantMode, es[i])
|
|
|
}
|
|
}
|
|
|
return es, hs
|
|
return es, hs
|
|
|
}
|
|
}
|
|
@@ -420,6 +391,15 @@ func waitCluster(t *testing.T, es []*Server) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+func waitMode(mode int64, e *Server) {
|
|
|
|
|
+ for {
|
|
|
|
|
+ if e.mode.Get() == mode {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ time.Sleep(10 * time.Millisecond)
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
// checkParticipant checks the i-th server works well as participant.
|
|
// checkParticipant checks the i-th server works well as participant.
|
|
|
func checkParticipant(i int, es []*Server) error {
|
|
func checkParticipant(i int, es []*Server) error {
|
|
|
lead, _ := waitActiveLeader(es)
|
|
lead, _ := waitActiveLeader(es)
|