mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-12 06:53:46 +00:00
go routine for test
This commit is contained in:
parent
916c7d8196
commit
1ffbfa4086
1 changed files with 33 additions and 16 deletions
|
|
@ -9,6 +9,7 @@ import (
|
||||||
_log "log"
|
_log "log"
|
||||||
"math/big"
|
"math/big"
|
||||||
"os"
|
"os"
|
||||||
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -240,28 +241,33 @@ var keys_21val = []map[string]string{
|
||||||
}
|
}
|
||||||
|
|
||||||
func getTestSprintLengthReorgCases(t *testing.T) []map[string]uint64 {
|
func getTestSprintLengthReorgCases(t *testing.T) []map[string]uint64 {
|
||||||
sprintSizes := []uint64{8, 16, 32, 64}
|
sprintSizes := []uint64{64, 32, 16, 8}
|
||||||
faultyNode := uint64(1)
|
faultyNodes := []uint64{1, 0}
|
||||||
reorgsLengthTests := make([]map[string]uint64, 0)
|
reorgsLengthTests := make([]map[string]uint64, 0)
|
||||||
for i := uint64(0); i < uint64(len(sprintSizes)); i++ {
|
for i := uint64(0); i < uint64(len(sprintSizes)); i++ {
|
||||||
maxReorgLength := sprintSizes[i] * 5
|
maxReorgLength := sprintSizes[i] * 4
|
||||||
for j := uint64(3); j <= maxReorgLength; j++ {
|
for j := uint64(3); j <= maxReorgLength; j = j + 4 {
|
||||||
maxStartBlock := sprintSizes[i] - 1
|
maxStartBlock := sprintSizes[i] - 1
|
||||||
for k := sprintSizes[i] / 2; k <= maxStartBlock; k++ {
|
for k := sprintSizes[i] / 2; k <= maxStartBlock; k = k + 4 {
|
||||||
reorgsLengthTest := map[string]uint64{
|
for l := uint64(0); l < uint64(len(faultyNodes)); l++ {
|
||||||
"reorgLength": j,
|
if j+k < sprintSizes[i] {
|
||||||
"startBlock": k,
|
continue
|
||||||
"sprintSize": sprintSizes[i],
|
}
|
||||||
"faultyNode": faultyNode, // node 1(index) is primary validator of the first sprint
|
reorgsLengthTest := map[string]uint64{
|
||||||
|
"reorgLength": j,
|
||||||
|
"startBlock": k,
|
||||||
|
"sprintSize": sprintSizes[i],
|
||||||
|
"faultyNode": faultyNodes[l], // node 1(index) is primary validator of the first sprint
|
||||||
|
}
|
||||||
|
reorgsLengthTests = append(reorgsLengthTests, reorgsLengthTest)
|
||||||
}
|
}
|
||||||
reorgsLengthTests = append(reorgsLengthTests, reorgsLengthTest)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// reorgsLengthTests := []map[string]uint64{
|
// reorgsLengthTests := []map[string]uint64{
|
||||||
// {
|
// {
|
||||||
// "reorgLength": 13,
|
// "reorgLength": 3,
|
||||||
// "startBlock": 1,
|
// "startBlock": 7,
|
||||||
// "sprintSize": 8,
|
// "sprintSize": 8,
|
||||||
// "faultyNode": 1,
|
// "faultyNode": 1,
|
||||||
// },
|
// },
|
||||||
|
|
@ -298,11 +304,22 @@ func TestSprintLengthReorg(t *testing.T) {
|
||||||
w.Write([]string{"Induced Reorg Length", "Start Block", "Sprint Size", "Disconnected Node Id", "Disconnected Node Id's Reorg Length", "Observer Node Id's Reorg Length"})
|
w.Write([]string{"Induced Reorg Length", "Start Block", "Sprint Size", "Disconnected Node Id", "Disconnected Node Id's Reorg Length", "Observer Node Id's Reorg Length"})
|
||||||
w.Flush()
|
w.Flush()
|
||||||
|
|
||||||
|
var wg sync.WaitGroup
|
||||||
for index, tt := range reorgsLengthTests {
|
for index, tt := range reorgsLengthTests {
|
||||||
r1, r2, r3, r4, r5, r6 := SprintLengthReorgIndividual(t, index, tt)
|
if index%4 == 0 {
|
||||||
w.Write([]string{fmt.Sprint(r1), fmt.Sprint(r2), fmt.Sprint(r3), fmt.Sprint(r4), fmt.Sprint(r5), fmt.Sprint(r6)})
|
wg.Wait()
|
||||||
w.Flush()
|
}
|
||||||
|
wg.Add(1)
|
||||||
|
go SprintLengthReorgIndividualHelper(t, index, tt, w, &wg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func SprintLengthReorgIndividualHelper(t *testing.T, index int, tt map[string]uint64, w *csv.Writer, wg *sync.WaitGroup) {
|
||||||
|
r1, r2, r3, r4, r5, r6 := SprintLengthReorgIndividual(t, index, tt)
|
||||||
|
w.Write([]string{fmt.Sprint(r1), fmt.Sprint(r2), fmt.Sprint(r3), fmt.Sprint(r4), fmt.Sprint(r5), fmt.Sprint(r6)})
|
||||||
|
w.Flush()
|
||||||
|
(*wg).Done()
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetupValidatorsAndTest(t *testing.T, tt map[string]uint64) (uint64, uint64) {
|
func SetupValidatorsAndTest(t *testing.T, tt map[string]uint64) (uint64, uint64) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue