|
@@ -27,6 +27,7 @@ import (
|
|
|
"os"
|
|
"os"
|
|
|
"reflect"
|
|
"reflect"
|
|
|
"sort"
|
|
"sort"
|
|
|
|
|
+ "strconv"
|
|
|
"strings"
|
|
"strings"
|
|
|
"testing"
|
|
"testing"
|
|
|
"time"
|
|
"time"
|
|
@@ -49,9 +50,18 @@ const (
|
|
|
requestTimeout = 2 * time.Second
|
|
requestTimeout = 2 * time.Second
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
+var (
|
|
|
|
|
+ electionTicks = 10
|
|
|
|
|
+)
|
|
|
|
|
+
|
|
|
func init() {
|
|
func init() {
|
|
|
// open microsecond-level time log for integration test debugging
|
|
// open microsecond-level time log for integration test debugging
|
|
|
log.SetFlags(log.Ltime | log.Lmicroseconds | log.Lshortfile)
|
|
log.SetFlags(log.Ltime | log.Lmicroseconds | log.Lshortfile)
|
|
|
|
|
+ if t := os.Getenv("ETCD_ELECTION_TIMEOUT_TICKS"); t != "" {
|
|
|
|
|
+ if i, err := strconv.ParseInt(t, 10, 64); err == nil {
|
|
|
|
|
+ electionTicks = int(i)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func TestClusterOf1(t *testing.T) { testCluster(t, 1) }
|
|
func TestClusterOf1(t *testing.T) { testCluster(t, 1) }
|
|
@@ -298,8 +308,9 @@ func (c *cluster) RemoveMember(t *testing.T, id uint64) {
|
|
|
select {
|
|
select {
|
|
|
case <-m.s.StopNotify():
|
|
case <-m.s.StopNotify():
|
|
|
m.Terminate(t)
|
|
m.Terminate(t)
|
|
|
- case <-time.After(time.Second):
|
|
|
|
|
- t.Fatalf("failed to remove member %s in one second", m.s.ID())
|
|
|
|
|
|
|
+ // stop delay / election timeout + 1s disk and network delay
|
|
|
|
|
+ case <-time.After(time.Duration(electionTicks)*tickDuration + time.Second):
|
|
|
|
|
+ t.Fatalf("failed to remove member %s in time", m.s.ID())
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -431,6 +442,7 @@ func mustNewMember(t *testing.T, name string) *member {
|
|
|
}
|
|
}
|
|
|
m.NewCluster = true
|
|
m.NewCluster = true
|
|
|
m.Transport = mustNewTransport(t)
|
|
m.Transport = mustNewTransport(t)
|
|
|
|
|
+ m.ElectionTimeoutTicks = electionTicks
|
|
|
return m
|
|
return m
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -460,6 +472,7 @@ func (m *member) Clone(t *testing.T) *member {
|
|
|
panic(err)
|
|
panic(err)
|
|
|
}
|
|
}
|
|
|
mm.Transport = mustNewTransport(t)
|
|
mm.Transport = mustNewTransport(t)
|
|
|
|
|
+ mm.ElectionTimeoutTicks = m.ElectionTimeoutTicks
|
|
|
return mm
|
|
return mm
|
|
|
}
|
|
}
|
|
|
|
|
|