public static ChannelState waitForChannelClose(Selector selector, String node, ChannelState.State channelState, int delayBetweenPollMs)
            throws IOException {
        boolean closed = false;
        for (int i = 0; i < 300; i++) {
            if (delayBetweenPollMs > 0)
                Utils.sleep(delayBetweenPollMs);
            selector.poll(100L);
            if (selector.channel(node) == null && selector.closingChannel(node) == null) {
                closed = true;
                break;
            }
        }
        assertTrue(closed, "Channel was not closed by timeout");
        ChannelState finalState = selector.disconnected().get(node);
        assertEquals(channelState, finalState.state());
        return finalState;
    }
Common utility functions used by transport layer and authenticator tests.
clients/src/test/java/org/apache/kafka/common/network/NetworkTestUtils.java