Browse Source

etcd-runner: pass in lock name as a command arg for lock_racer.

fanmin shi 8 years ago
parent
commit
debc69e1f2
1 changed files with 13 additions and 6 deletions
  1. 13 6
      tools/functional-tester/etcd-runner/command/lock_racer_command.go

+ 13 - 6
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))
 }