Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: Consul lock does not receive signals if lock not acquired #5909

Merged
merged 2 commits into from
Jan 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion command/commands_oss.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func init() {
Register("kv import", func(ui cli.Ui) (cli.Command, error) { return kvimp.New(ui), nil })
Register("kv put", func(ui cli.Ui) (cli.Command, error) { return kvput.New(ui), nil })
Register("leave", func(ui cli.Ui) (cli.Command, error) { return leave.New(ui), nil })
Register("lock", func(ui cli.Ui) (cli.Command, error) { return lock.New(ui), nil })
Register("lock", func(ui cli.Ui) (cli.Command, error) { return lock.New(ui, MakeShutdownCh()), nil })
Register("login", func(ui cli.Ui) (cli.Command, error) { return login.New(ui), nil })
Register("logout", func(ui cli.Ui) (cli.Command, error) { return logout.New(ui), nil })
Register("maint", func(ui cli.Ui) (cli.Command, error) { return maint.New(ui), nil })
Expand Down
4 changes: 2 additions & 2 deletions command/lock/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ type cmd struct {
timeout time.Duration
}

func New(ui cli.Ui) *cmd {
c := &cmd{UI: ui}
func New(ui cli.Ui, shutdownCh <-chan struct{}) *cmd {
c := &cmd{UI: ui, ShutdownCh: shutdownCh}
c.init()
return c
}
Expand Down
22 changes: 11 additions & 11 deletions command/lock/lock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

func argFail(t *testing.T, args []string, expected string) {
ui := cli.NewMockUi()
c := New(ui)
c := New(ui, nil)
c.flags.SetOutput(ui.ErrorWriter)
if code := c.Run(args); code != 1 {
t.Fatalf("expected return code 1, got %d", code)
Expand All @@ -28,7 +28,7 @@ func argFail(t *testing.T, args []string, expected string) {

func TestLockCommand_noTabs(t *testing.T) {
t.Parallel()
if strings.ContainsRune(New(cli.NewMockUi()).Help(), '\t') {
if strings.ContainsRune(New(cli.NewMockUi(), nil).Help(), '\t') {
t.Fatal("help has tabs")
}
}
Expand All @@ -48,7 +48,7 @@ func TestLockCommand(t *testing.T) {
testrpc.WaitForTestAgent(t, a.RPC, "dc1")

ui := cli.NewMockUi()
c := New(ui)
c := New(ui, nil)

filePath := filepath.Join(a.Config.DataDir, "test_touch")
args := []string{"-http-addr=" + a.HTTPAddr(), "test/prefix", "touch", filePath}
Expand All @@ -73,7 +73,7 @@ func TestLockCommand_NoShell(t *testing.T) {
testrpc.WaitForTestAgent(t, a.RPC, "dc1")

ui := cli.NewMockUi()
c := New(ui)
c := New(ui, nil)

filePath := filepath.Join(a.Config.DataDir, "test_touch")
args := []string{"-http-addr=" + a.HTTPAddr(), "-shell=false", "test/prefix", "touch", filePath}
Expand All @@ -98,7 +98,7 @@ func TestLockCommand_TryLock(t *testing.T) {
testrpc.WaitForTestAgent(t, a.RPC, "dc1")

ui := cli.NewMockUi()
c := New(ui)
c := New(ui, nil)

filePath := filepath.Join(a.Config.DataDir, "test_touch")
args := []string{"-http-addr=" + a.HTTPAddr(), "-try=10s", "test/prefix", "touch", filePath}
Expand Down Expand Up @@ -132,7 +132,7 @@ func TestLockCommand_TrySemaphore(t *testing.T) {
testrpc.WaitForTestAgent(t, a.RPC, "dc1")

ui := cli.NewMockUi()
c := New(ui)
c := New(ui, nil)

filePath := filepath.Join(a.Config.DataDir, "test_touch")
args := []string{"-http-addr=" + a.HTTPAddr(), "-n=3", "-try=10s", "test/prefix", "touch", filePath}
Expand Down Expand Up @@ -166,7 +166,7 @@ func TestLockCommand_MonitorRetry_Lock_Default(t *testing.T) {
testrpc.WaitForTestAgent(t, a.RPC, "dc1")

ui := cli.NewMockUi()
c := New(ui)
c := New(ui, nil)

filePath := filepath.Join(a.Config.DataDir, "test_touch")
args := []string{"-http-addr=" + a.HTTPAddr(), "test/prefix", "touch", filePath}
Expand Down Expand Up @@ -201,7 +201,7 @@ func TestLockCommand_MonitorRetry_Semaphore_Default(t *testing.T) {
testrpc.WaitForTestAgent(t, a.RPC, "dc1")

ui := cli.NewMockUi()
c := New(ui)
c := New(ui, nil)

filePath := filepath.Join(a.Config.DataDir, "test_touch")
args := []string{"-http-addr=" + a.HTTPAddr(), "-n=3", "test/prefix", "touch", filePath}
Expand Down Expand Up @@ -236,7 +236,7 @@ func TestLockCommand_MonitorRetry_Lock_Arg(t *testing.T) {
testrpc.WaitForTestAgent(t, a.RPC, "dc1")

ui := cli.NewMockUi()
c := New(ui)
c := New(ui, nil)

filePath := filepath.Join(a.Config.DataDir, "test_touch")
args := []string{"-http-addr=" + a.HTTPAddr(), "-monitor-retry=9", "test/prefix", "touch", filePath}
Expand Down Expand Up @@ -271,7 +271,7 @@ func TestLockCommand_MonitorRetry_Semaphore_Arg(t *testing.T) {
testrpc.WaitForTestAgent(t, a.RPC, "dc1")

ui := cli.NewMockUi()
c := New(ui)
c := New(ui, nil)

filePath := filepath.Join(a.Config.DataDir, "test_touch")
args := []string{"-http-addr=" + a.HTTPAddr(), "-n=3", "-monitor-retry=9", "test/prefix", "touch", filePath}
Expand Down Expand Up @@ -330,7 +330,7 @@ func TestLockCommand_ChildExitCode(t *testing.T) {
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
ui := cli.NewMockUi()
c := New(ui)
c := New(ui, nil)

if got := c.Run(tc.args); got != tc.want {
t.Fatalf("got %d want %d", got, tc.want)
Expand Down