|
|
|
@ -121,7 +121,7 @@ func TestLockCommand_Try_Semaphore(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestLockCommand_MonitorRetry_Lock(t *testing.T) {
|
|
|
|
|
func TestLockCommand_MonitorRetry_Lock_Default(t *testing.T) {
|
|
|
|
|
a1 := testAgent(t)
|
|
|
|
|
defer a1.Shutdown()
|
|
|
|
|
waitForLeader(t, a1.httpAddr)
|
|
|
|
@ -130,7 +130,7 @@ func TestLockCommand_MonitorRetry_Lock(t *testing.T) {
|
|
|
|
|
c := &LockCommand{Ui: ui}
|
|
|
|
|
filePath := filepath.Join(a1.dir, "test_touch")
|
|
|
|
|
touchCmd := fmt.Sprintf("touch '%s'", filePath)
|
|
|
|
|
args := []string{"-http-addr=" + a1.httpAddr, "-monitor-retry=3", "test/prefix", touchCmd}
|
|
|
|
|
args := []string{"-http-addr=" + a1.httpAddr, "test/prefix", touchCmd}
|
|
|
|
|
|
|
|
|
|
// Run the command.
|
|
|
|
|
var lu *LockUnlock
|
|
|
|
@ -148,12 +148,13 @@ func TestLockCommand_MonitorRetry_Lock(t *testing.T) {
|
|
|
|
|
if !ok {
|
|
|
|
|
t.Fatalf("bad type")
|
|
|
|
|
}
|
|
|
|
|
if opts.MonitorRetries != 3 {
|
|
|
|
|
t.Fatalf("bad: %d", opts.MonitorRetries)
|
|
|
|
|
if opts.MonitorRetries != defaultMonitorRetry ||
|
|
|
|
|
opts.MonitorRetryTime != defaultMonitorRetryTime {
|
|
|
|
|
t.Fatalf("bad: %#v", opts)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestLockCommand_MonitorRetry_Semaphore(t *testing.T) {
|
|
|
|
|
func TestLockCommand_MonitorRetry_Semaphore_Default(t *testing.T) {
|
|
|
|
|
a1 := testAgent(t)
|
|
|
|
|
defer a1.Shutdown()
|
|
|
|
|
waitForLeader(t, a1.httpAddr)
|
|
|
|
@ -162,7 +163,7 @@ func TestLockCommand_MonitorRetry_Semaphore(t *testing.T) {
|
|
|
|
|
c := &LockCommand{Ui: ui}
|
|
|
|
|
filePath := filepath.Join(a1.dir, "test_touch")
|
|
|
|
|
touchCmd := fmt.Sprintf("touch '%s'", filePath)
|
|
|
|
|
args := []string{"-http-addr=" + a1.httpAddr, "-n=3", "-monitor-retry=3", "test/prefix", touchCmd}
|
|
|
|
|
args := []string{"-http-addr=" + a1.httpAddr, "-n=3", "test/prefix", touchCmd}
|
|
|
|
|
|
|
|
|
|
// Run the command.
|
|
|
|
|
var lu *LockUnlock
|
|
|
|
@ -180,7 +181,74 @@ func TestLockCommand_MonitorRetry_Semaphore(t *testing.T) {
|
|
|
|
|
if !ok {
|
|
|
|
|
t.Fatalf("bad type")
|
|
|
|
|
}
|
|
|
|
|
if opts.MonitorRetries != 3 {
|
|
|
|
|
t.Fatalf("bad: %d", opts.MonitorRetries)
|
|
|
|
|
if opts.MonitorRetries != defaultMonitorRetry ||
|
|
|
|
|
opts.MonitorRetryTime != defaultMonitorRetryTime {
|
|
|
|
|
t.Fatalf("bad: %#v", opts)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestLockCommand_MonitorRetry_Lock_Arg(t *testing.T) {
|
|
|
|
|
a1 := testAgent(t)
|
|
|
|
|
defer a1.Shutdown()
|
|
|
|
|
waitForLeader(t, a1.httpAddr)
|
|
|
|
|
|
|
|
|
|
ui := new(cli.MockUi)
|
|
|
|
|
c := &LockCommand{Ui: ui}
|
|
|
|
|
filePath := filepath.Join(a1.dir, "test_touch")
|
|
|
|
|
touchCmd := fmt.Sprintf("touch '%s'", filePath)
|
|
|
|
|
args := []string{"-http-addr=" + a1.httpAddr, "-monitor-retry=9", "test/prefix", touchCmd}
|
|
|
|
|
|
|
|
|
|
// Run the command.
|
|
|
|
|
var lu *LockUnlock
|
|
|
|
|
code := c.run(args, &lu)
|
|
|
|
|
if code != 0 {
|
|
|
|
|
t.Fatalf("bad: %d. %#v", code, ui.ErrorWriter.String())
|
|
|
|
|
}
|
|
|
|
|
_, err := ioutil.ReadFile(filePath)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Make sure the monitor options were set correctly.
|
|
|
|
|
opts, ok := lu.rawOpts.(*api.LockOptions)
|
|
|
|
|
if !ok {
|
|
|
|
|
t.Fatalf("bad type")
|
|
|
|
|
}
|
|
|
|
|
if opts.MonitorRetries != 9 ||
|
|
|
|
|
opts.MonitorRetryTime != defaultMonitorRetryTime {
|
|
|
|
|
t.Fatalf("bad: %#v", opts)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestLockCommand_MonitorRetry_Semaphore_Arg(t *testing.T) {
|
|
|
|
|
a1 := testAgent(t)
|
|
|
|
|
defer a1.Shutdown()
|
|
|
|
|
waitForLeader(t, a1.httpAddr)
|
|
|
|
|
|
|
|
|
|
ui := new(cli.MockUi)
|
|
|
|
|
c := &LockCommand{Ui: ui}
|
|
|
|
|
filePath := filepath.Join(a1.dir, "test_touch")
|
|
|
|
|
touchCmd := fmt.Sprintf("touch '%s'", filePath)
|
|
|
|
|
args := []string{"-http-addr=" + a1.httpAddr, "-n=3", "-monitor-retry=9", "test/prefix", touchCmd}
|
|
|
|
|
|
|
|
|
|
// Run the command.
|
|
|
|
|
var lu *LockUnlock
|
|
|
|
|
code := c.run(args, &lu)
|
|
|
|
|
if code != 0 {
|
|
|
|
|
t.Fatalf("bad: %d. %#v", code, ui.ErrorWriter.String())
|
|
|
|
|
}
|
|
|
|
|
_, err := ioutil.ReadFile(filePath)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Make sure the monitor options were set correctly.
|
|
|
|
|
opts, ok := lu.rawOpts.(*api.SemaphoreOptions)
|
|
|
|
|
if !ok {
|
|
|
|
|
t.Fatalf("bad type")
|
|
|
|
|
}
|
|
|
|
|
if opts.MonitorRetries != 9 ||
|
|
|
|
|
opts.MonitorRetryTime != defaultMonitorRetryTime {
|
|
|
|
|
t.Fatalf("bad: %#v", opts)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|