Skip to content
This repository has been archived by the owner on Nov 18, 2020. It is now read-only.

Commit

Permalink
Introduce rabbitmq-diagnostics maybe_stuck
Browse files Browse the repository at this point in the history
Fixes #144.
[Finished ##135678977]
  • Loading branch information
michaelklishin committed Dec 7, 2016
1 parent 24a09ab commit 8f2da77
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 0 deletions.
39 changes: 39 additions & 0 deletions lib/rabbitmq/cli/diagnostics/commands/maybe_stuck_command.ex
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
61 changes: 61 additions & 0 deletions test/diagnostics/maybe_stuck_command_test.exs
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

0 comments on commit 8f2da77

Please sign in to comment.