From debc69e1f2b1cb9193a6d8452ac0ea25c86c5ca8 Mon Sep 17 00:00:00 2001 From: fanmin shi Date: Tue, 25 Apr 2017 10:31:15 -0700 Subject: [PATCH] etcd-runner: pass in lock name as a command arg for lock_racer. --- .../etcd-runner/command/lock_racer_command.go | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/tools/functional-tester/etcd-runner/command/lock_racer_command.go b/tools/functional-tester/etcd-runner/command/lock_racer_command.go index d9544263a..b0ec491f4 100644 --- a/tools/functional-tester/etcd-runner/command/lock_racer_command.go +++ b/tools/functional-tester/etcd-runner/command/lock_racer_command.go @@ -20,24 +20,29 @@ import ( "fmt" "github.com/coreos/etcd/clientv3/concurrency" + "github.com/spf13/cobra" ) // NewLockRacerCommand returns the cobra command for "lock-racer runner". func NewLockRacerCommand() *cobra.Command { cmd := &cobra.Command{ - Use: "lock-racer", + Use: "lock-racer [name of lock (defaults to 'racers')]", Short: "Performs lock race operation", Run: runRacerFunc, } - cmd.Flags().IntVar(&rounds, "rounds", 100, "number of rounds to run") cmd.Flags().IntVar(&totalClientConnections, "total-client-connections", 10, "total number of client connections") return cmd } func runRacerFunc(cmd *cobra.Command, args []string) { - if len(args) > 0 { - ExitWithError(ExitBadArgs, errors.New("lock-racer does not take any argument")) + racers := "racers" + if len(args) == 1 { + racers = args[0] + } + + if len(args) > 1 { + ExitWithError(ExitBadArgs, errors.New("lock-racer takes at most one argument")) } rcs := make([]roundClient, totalClientConnections) @@ -61,7 +66,7 @@ func runRacerFunc(cmd *cobra.Command, args []string) { break } } - m := concurrency.NewMutex(s, "racers") + m := concurrency.NewMutex(s, racers) rcs[i].acquire = func() error { return m.Lock(ctx) } rcs[i].validate = func() error { if cnt++; cnt != 1 { @@ -77,5 +82,7 @@ func runRacerFunc(cmd *cobra.Command, args []string) { return nil } } - doRounds(rcs, rounds) + // each client creates 1 key from NewMutex() and delete it from Unlock() + // a round involves in 2*len(rcs) requests. + doRounds(rcs, rounds, 2*len(rcs)) }