This is a race condition on the client side occurring during connection close. We have two threads racing to close the connection.
When the test passes, the IoReceiver (processing the ConnectionClose) thread on the client side that completely closes the connection before the test thread calls AMQConnection#close(). The test thread finds the AMQConnection#_closed atomic already set true so the #close call returns and the test passes.
When the test fails, the actions of IoReceiver thread and the test thread race to close the connection. The IoReceiver thread records the cause for the connection close (AMQConnectionClosedException: Error: Broker is shutting down [error code 320: connection forced]), meanwhile the test thread tries to close the connection too. In AMQProtocolHandler#writeCommandFrameAndWaitForReply it finds that the state manager already has a saved exception (AMQConnectionClosedException) so it throws it and the test fails.