Fix an issue to support unreliable in GenericTest (#265)

* fix an issue to support unreliable in GenericTest
This commit is contained in:
Daobing Zhu 2021-09-01 17:39:01 +08:00 committed by GitHub
parent bda1e7b85b
commit 077953e2d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -97,10 +97,11 @@ func checkConcurrentAppends(t *testing.T, v string, counts []int) {
}
}
// repartition the servers periodically
func partitioner(t *testing.T, cluster *Cluster, ch chan bool, done *int32, unreliable bool, electionTimeout time.Duration) {
// make network chaos among servers
func networkchaos(t *testing.T, cluster *Cluster, ch chan bool, done *int32, unreliable bool, partitions bool, electionTimeout time.Duration) {
defer func() { ch <- true }()
for atomic.LoadInt32(done) == 0 {
if partitions {
a := make([]int, cluster.count)
for i := 0; i < cluster.count; i++ {
a[i] = (rand.Int() % 2)
@ -120,6 +121,8 @@ func partitioner(t *testing.T, cluster *Cluster, ch chan bool, done *int32, unre
s1: pa[0],
s2: pa[1],
})
}
if unreliable {
cluster.AddFilter(&DropFilter{})
}
@ -236,10 +239,10 @@ func GenericTest(t *testing.T, part string, nclients int, unreliable bool, crash
}
})
if partitions {
if unreliable || partitions {
// Allow the clients to perform some operations without interruption
time.Sleep(300 * time.Millisecond)
go partitioner(t, cluster, ch_partitioner, &done_partitioner, unreliable, electionTimeout)
go networkchaos(t, cluster, ch_partitioner, &done_partitioner, unreliable, partitions, electionTimeout)
}
if confchange {
// Allow the clients to perfrom some operations without interruption
@ -250,7 +253,7 @@ func GenericTest(t *testing.T, part string, nclients int, unreliable bool, crash
atomic.StoreInt32(&done_clients, 1) // tell clients to quit
atomic.StoreInt32(&done_partitioner, 1) // tell partitioner to quit
atomic.StoreInt32(&done_confchanger, 1) // tell confchanger to quit
if partitions {
if unreliable || partitions {
// log.Printf("wait for partitioner\n")
<-ch_partitioner
// reconnect network and submit a request. A client may