This repository has been archived by the owner on Nov 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce
rabbitmq-diagnostics maybe_stuck
Fixes #144. [Finished ##135678977]
- Loading branch information
1 parent
24a09ab
commit 8f2da77
Showing
2 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
lib/rabbitmq/cli/diagnostics/commands/maybe_stuck_command.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
## The contents of this file are subject to the Mozilla Public License | ||
## Version 1.1 (the "License"); you may not use this file except in | ||
## compliance with the License. You may obtain a copy of the License | ||
## at http://www.mozilla.org/MPL/ | ||
## | ||
## Software distributed under the License is distributed on an "AS IS" | ||
## basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See | ||
## the License for the specific language governing rights and | ||
## limitations under the License. | ||
## | ||
## The Original Code is RabbitMQ. | ||
## | ||
## The Initial Developer of the Original Code is GoPivotal, Inc. | ||
## Copyright (c) 2007-2016 Pivotal Software, Inc. All rights reserved. | ||
|
||
|
||
defmodule RabbitMQ.CLI.Diagnostics.Commands.MaybeStuckCommand do | ||
@behaviour RabbitMQ.CLI.CommandBehaviour | ||
use RabbitMQ.CLI.DefaultOutput | ||
|
||
def merge_defaults(args, opts), do: {args, opts} | ||
|
||
def switches(), do: [] | ||
|
||
def validate(args, _) when length(args) > 0 do | ||
{:validation_failure, :too_many_args} | ||
end | ||
def validate(_, _), do: :ok | ||
|
||
def usage, do: "maybe_stuck" | ||
|
||
def run([], %{node: node_name, timeout: timeout}) do | ||
:rabbit_misc.rpc_call(node_name, :rabbit_diagnostics, :maybe_stuck, [], timeout) | ||
end | ||
|
||
def banner(_, %{node: node_name}) do | ||
"Asking node #{node_name} to detect potentially stuck Erlang processes..." | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
## The contents of this file are subject to the Mozilla Public License | ||
## Version 1.1 (the "License"); you may not use this file except in | ||
## compliance with the License. You may obtain a copy of the License | ||
## at http://www.mozilla.org/MPL/ | ||
## | ||
## Software distributed under the License is distributed on an "AS IS" | ||
## basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See | ||
## the License for the specific language governing rights and | ||
## limitations under the License. | ||
## | ||
## The Original Code is RabbitMQ. | ||
## | ||
## The Initial Developer of the Original Code is GoPivotal, Inc. | ||
## Copyright (c) 2007-2016 Pivotal Software, Inc. All rights reserved. | ||
|
||
|
||
defmodule MaybeStuckCommandTest do | ||
use ExUnit.Case | ||
import TestHelper | ||
|
||
@command RabbitMQ.CLI.Diagnostics.Commands.MaybeStuckCommand | ||
|
||
setup_all do | ||
RabbitMQ.CLI.Core.Distribution.start() | ||
:net_kernel.connect_node(get_rabbit_hostname) | ||
|
||
on_exit([], fn -> | ||
:erlang.disconnect_node(get_rabbit_hostname) | ||
|
||
end) | ||
|
||
:ok | ||
end | ||
|
||
setup context do | ||
{:ok, opts: %{ | ||
node: get_rabbit_hostname, | ||
timeout: context[:test_timeout] || 15 | ||
}} | ||
end | ||
|
||
test "merge_defaults: returns inputs" do | ||
assert @command.merge_defaults([], %{timeout: 30}) == {[], %{timeout: 30}} | ||
end | ||
|
||
test "validate: treats positional arguments as a failure" do | ||
assert @command.validate(["extra-arg"], %{}) == {:validation_failure, :too_many_args} | ||
end | ||
|
||
test "validate: treats empty positional arguments and default switches as a success" do | ||
assert @command.validate([], %{}) == :ok | ||
end | ||
|
||
@tag test_timeout: 0 | ||
test "run: targeting an unreachable node throws a badrpc", context do | ||
target = :jake@thedog | ||
:net_kernel.connect_node(target) | ||
opts = %{node: target} | ||
assert @command.run([], Map.merge(context[:opts], opts)) == {:badrpc, :nodedown} | ||
end | ||
end |