Skip to content
This repository was archived by the owner on Sep 17, 2022. It is now read-only.

Commit e5f8807

Browse files
committed
Expose parallelism flag
1 parent 451ed89 commit e5f8807

File tree

4 files changed

+27
-14
lines changed

4 files changed

+27
-14
lines changed

common/transaction/runner.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package transaction
22

33
import (
44
"fmt"
5+
"os"
56

67
"github.com/getapid/apid-cli/common/result"
78
"github.com/getapid/apid-cli/common/step"
@@ -31,14 +32,20 @@ type res struct {
3132
}
3233

3334
type TransactionRunner struct {
34-
stepRunner step.Runner
35-
writer result.Writer
35+
stepRunner step.Runner
36+
writer result.Writer
37+
parallelism int
3638
}
3739

38-
func NewTransactionRunner(stepRunner step.Runner, writer result.Writer) Runner {
40+
func NewTransactionRunner(stepRunner step.Runner, writer result.Writer, parallelism int) Runner {
41+
if parallelism < 1 {
42+
fmt.Printf("parallelism level is negative or zero ( %d ), exiting.\n", parallelism)
43+
os.Exit(1)
44+
}
3945
return &TransactionRunner{
40-
stepRunner: stepRunner,
41-
writer: writer,
46+
stepRunner: stepRunner,
47+
writer: writer,
48+
parallelism: parallelism,
4249
}
4350
}
4451

@@ -65,7 +72,7 @@ func (r *TransactionRunner) Run(transactions []Transaction, vars variables.Varia
6572
jobsChan := make(chan job)
6673
resultsChan := make(chan res)
6774

68-
workers := 5
75+
workers := r.parallelism
6976
if workers > len(jobs) {
7077
workers = len(jobs)
7178
}

common/transaction/runner_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,9 @@ func (s *RunnerSuite) TestTransactionRunner_Run() {
280280
mockedCalls = append(mockedCalls, writer.EXPECT().Close())
281281

282282
r := &TransactionRunner{
283-
stepRunner: stepRunner,
284-
writer: writer,
283+
stepRunner: stepRunner,
284+
writer: writer,
285+
parallelism: 10,
285286
}
286287
ok := r.Run(tt.args.transactions, tt.args.vars)
287288
s.Equal(tt.ok, ok, tt.name)
@@ -325,8 +326,9 @@ func (s *RunnerSuite) TestTransactionRunner_RunWithMatrix() {
325326
mockWriter.EXPECT().Close()
326327

327328
r := &TransactionRunner{
328-
stepRunner: mockStepRunner,
329-
writer: mockWriter,
329+
stepRunner: mockStepRunner,
330+
writer: mockWriter,
331+
parallelism: 10,
330332
}
331333
ok := r.Run([]Transaction{transaction}, rootVars)
332334
s.True(ok)

svc/cli/cmd/check.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
var (
1818
configFilepath string
1919
showTimings bool
20+
parallelism int
2021
)
2122

2223
var checkCmd = &cobra.Command{
@@ -38,6 +39,7 @@ func init() {
3839
rootCmd.AddCommand(checkCmd)
3940
checkCmd.Flags().StringVarP(&configFilepath, "config", "c", "./apid.yaml", "file with config to run")
4041
checkCmd.Flags().BoolVarP(&showTimings, "timings", "t", false, "output the durations of request steps")
42+
checkCmd.Flags().IntVarP(&parallelism, "parallelism", "p", 10, "number of concurrent transaction executions")
4143
}
4244

4345
func checkRun(cmd *cobra.Command, args []string) error {
@@ -62,7 +64,7 @@ func checkRun(cmd *cobra.Command, args []string) error {
6264
stepExtractor := step.NewBodyExtractor()
6365
stepChecker := step.NewRunner(stepExecutor, stepValidator, stepInterpolator, stepExtractor)
6466

65-
transactionRunner := transaction.NewTransactionRunner(stepChecker, writer)
67+
transactionRunner := transaction.NewTransactionRunner(stepChecker, writer, parallelism)
6668

6769
vars := c.Variables.Merge(variables.New(variables.WithEnv()))
6870
ok := transactionRunner.Run(c.Transactions, vars)

svc/cli/cmd/cloud/check.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ import (
1717
)
1818

1919
var (
20-
region = ""
21-
showTimings = false
20+
region string
21+
showTimings bool
22+
parallelism int
2223
)
2324

2425
var checkCmd = &cobra.Command{
@@ -42,6 +43,7 @@ func init() {
4243
RootCommand.AddCommand(checkCmd)
4344
checkCmd.Flags().StringVarP(&configFilepath, "config", "c", "./apid.yaml", "file with config to run")
4445
checkCmd.Flags().BoolVarP(&showTimings, "timings", "t", false, "output the durations of requests")
46+
checkCmd.Flags().IntVarP(&parallelism, "parallelism", "p", 10, "number of concurrent transaction executions")
4547
checkCmd.Flags().StringVarP(&region, "region", "r", "washington", "location to run the tests from")
4648
}
4749

@@ -69,7 +71,7 @@ func remoteCheck(cmd *cobra.Command, args []string) error {
6971
stepExtractor := step.NewBodyExtractor()
7072
stepChecker := step.NewRunner(stepExecutor, stepValidator, stepInterpolator, stepExtractor)
7173

72-
transactionRunner := transaction.NewTransactionRunner(stepChecker, writer)
74+
transactionRunner := transaction.NewTransactionRunner(stepChecker, writer, parallelism)
7375

7476
vars := c.Variables.Merge(variables.New(variables.WithEnv()))
7577
ok := transactionRunner.Run(c.Transactions, vars)

0 commit comments

Comments
 (0)