mirror of
https://github.com/talent-plan/tinykv.git
synced 2024-12-27 13:20:24 +08:00
Fix an issue to support unreliable in GenericTest (#265)
* fix an issue to support unreliable in GenericTest
This commit is contained in:
parent
bda1e7b85b
commit
077953e2d7
@ -97,29 +97,32 @@ func checkConcurrentAppends(t *testing.T, v string, counts []int) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// repartition the servers periodically
|
// make network chaos among servers
|
||||||
func partitioner(t *testing.T, cluster *Cluster, ch chan bool, done *int32, unreliable bool, electionTimeout time.Duration) {
|
func networkchaos(t *testing.T, cluster *Cluster, ch chan bool, done *int32, unreliable bool, partitions bool, electionTimeout time.Duration) {
|
||||||
defer func() { ch <- true }()
|
defer func() { ch <- true }()
|
||||||
for atomic.LoadInt32(done) == 0 {
|
for atomic.LoadInt32(done) == 0 {
|
||||||
a := make([]int, cluster.count)
|
if partitions {
|
||||||
for i := 0; i < cluster.count; i++ {
|
a := make([]int, cluster.count)
|
||||||
a[i] = (rand.Int() % 2)
|
for i := 0; i < cluster.count; i++ {
|
||||||
}
|
a[i] = (rand.Int() % 2)
|
||||||
pa := make([][]uint64, 2)
|
}
|
||||||
for i := 0; i < 2; i++ {
|
pa := make([][]uint64, 2)
|
||||||
pa[i] = make([]uint64, 0)
|
for i := 0; i < 2; i++ {
|
||||||
for j := 1; j <= cluster.count; j++ {
|
pa[i] = make([]uint64, 0)
|
||||||
if a[j-1] == i {
|
for j := 1; j <= cluster.count; j++ {
|
||||||
pa[i] = append(pa[i], uint64(j))
|
if a[j-1] == i {
|
||||||
|
pa[i] = append(pa[i], uint64(j))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
cluster.ClearFilters()
|
||||||
|
log.Infof("partition: %v, %v", pa[0], pa[1])
|
||||||
|
cluster.AddFilter(&PartitionFilter{
|
||||||
|
s1: pa[0],
|
||||||
|
s2: pa[1],
|
||||||
|
})
|
||||||
}
|
}
|
||||||
cluster.ClearFilters()
|
|
||||||
log.Infof("partition: %v, %v", pa[0], pa[1])
|
|
||||||
cluster.AddFilter(&PartitionFilter{
|
|
||||||
s1: pa[0],
|
|
||||||
s2: pa[1],
|
|
||||||
})
|
|
||||||
if unreliable {
|
if unreliable {
|
||||||
cluster.AddFilter(&DropFilter{})
|
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
|
// Allow the clients to perform some operations without interruption
|
||||||
time.Sleep(300 * time.Millisecond)
|
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 {
|
if confchange {
|
||||||
// Allow the clients to perfrom some operations without interruption
|
// 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_clients, 1) // tell clients to quit
|
||||||
atomic.StoreInt32(&done_partitioner, 1) // tell partitioner to quit
|
atomic.StoreInt32(&done_partitioner, 1) // tell partitioner to quit
|
||||||
atomic.StoreInt32(&done_confchanger, 1) // tell confchanger to quit
|
atomic.StoreInt32(&done_confchanger, 1) // tell confchanger to quit
|
||||||
if partitions {
|
if unreliable || partitions {
|
||||||
// log.Printf("wait for partitioner\n")
|
// log.Printf("wait for partitioner\n")
|
||||||
<-ch_partitioner
|
<-ch_partitioner
|
||||||
// reconnect network and submit a request. A client may
|
// reconnect network and submit a request. A client may
|
||||||
|
Loading…
Reference in New Issue
Block a user