Skip to content

Commit

Permalink
-parallel-scenarios flag support added (#21)
Browse files Browse the repository at this point in the history
* multiple scenario parallel execution added

* -parallel-scenarios flag support added
  • Loading branch information
piano-man authored Apr 14, 2020
1 parent d6b299d commit 0af876c
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions bin/test_suite/test_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func main() {
logsDirectory := flag.String("logs-directory", "/tmp", "Location of the logs.")
netInterface := flag.String("interface", "", "The interface to listen to when capturing pcaps. Lets tcpdump decide if not set.")
parallel := flag.Bool("parallel", false, "Runs each scenario against multiple hosts at the same time.")
parallelScenarios := flag.Bool("parallel-scenarios", false, "Run multiple scenarios against multiple hosts in parallel. Enable this only if all the test servers can support multiple connections")
maxInstances := flag.Int("max-instances", 10, "Limits the number of parallel scenario runs.")
randomise := flag.Bool("randomise", false, "Randomise the execution order of scenarii")
timeout := flag.Int("timeout", 10, "The amount of time in seconds spent when completing a test. Defaults to 10. When set to 0, each test ends as soon as possible.")
Expand Down Expand Up @@ -75,22 +76,25 @@ func main() {
close(resultsAgg)
}()

if !*parallel && !*parallelScenarios {
*maxInstances = 1
}

semaphore := make(chan bool, *maxInstances)
for i := 0; i < *maxInstances; i++ {
semaphore <- true
}
wg := &sync.WaitGroup{}

for _, id := range scenarioIds {
if *scenarioName != "" && *scenarioName != id {
continue
}
scenario := scenariiInstances[id]

if !*parallel {
*maxInstances = 1
}
semaphore := make(chan bool, *maxInstances)
for i := 0; i < *maxInstances; i++ {
semaphore <- true
}
wg := &sync.WaitGroup{}
scenarioId := id
scenario := scenariiInstances[scenarioId]

os.MkdirAll(p.Join(*logsDirectory, id), os.ModePerm)
os.MkdirAll(p.Join(*logsDirectory, scenarioId), os.ModePerm)

scanner := bufio.NewScanner(file)
for scanner.Scan() {
Expand Down Expand Up @@ -126,7 +130,7 @@ func main() {
}
outputFile.Close()

logFile, err := os.Create(p.Join(*logsDirectory, id, host))
logFile, err := os.Create(p.Join(*logsDirectory, scenarioId, host))
if err != nil {
println(err.Error())
return
Expand All @@ -136,7 +140,7 @@ func main() {
crashTrace := GetCrashTrace(scenario, host) // Prepare one just in case
start := time.Now()

args := []string{"run", scenarioRunnerFilename, "-host", host, "-path", path, "-alpn", preferredALPN, "-scenario", id, "-interface", *netInterface, "-output", outputFile.Name(), "-timeout", strconv.Itoa(*timeout)}
args := []string{"run", scenarioRunnerFilename, "-host", host, "-path", path, "-alpn", preferredALPN, "-scenario", scenarioId, "-interface", *netInterface, "-output", outputFile.Name(), "-timeout", strconv.Itoa(*timeout)}
if *debug {
args = append(args, "-debug")
}
Expand Down Expand Up @@ -168,10 +172,13 @@ func main() {
result <- &trace
}()
}

wg.Wait()
if !*parallelScenarios {
wg.Wait()
}
file.Seek(0, 0)
}

wg.Wait()
close(result)
<-resultsAgg

Expand All @@ -198,11 +205,12 @@ func GetCrashTrace(scenario scenarii.Scenario, host string) *qt.Trace {
}

type Results []qt.Trace

func (a Results) Less(i, j int) bool {
if a[i].Scenario == a[j].Scenario {
return a[i].Host < a[j].Host
}
return a[i].Scenario < a[j].Scenario
}
func (a Results) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a Results) Len() int { return len(a) }
func (a Results) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a Results) Len() int { return len(a) }

0 comments on commit 0af876c

Please sign in to comment.