private void test_infra_application_fail(NodeType nodeType, int count, int expectedFailCount) {
        NodeFailTester tester = NodeFailTester.withInfraApplication(nodeType, count);

        // For a day all nodes work so nothing happens
        for (int minutes = 0; minutes < 24 * 60; minutes +=5 ) {
            tester.runMaintainers();
            tester.clock.advance(Duration.ofMinutes(5));

            assertEquals(count, tester.nodeRepository.nodes().list(Node.State.active).nodeType(nodeType).size());
        }

        Set<String> downHosts = Set.of("host2", "host3");

        for (String downHost : downHosts)
            tester.serviceMonitor.setHostDown(downHost);
        // nothing happens the first 45 minutes
        for (int minutes = 0; minutes < 45; minutes +=5 ) {
            tester.runMaintainers();
            tester.clock.advance(Duration.ofMinutes(5));
            assertEquals( 0, tester.deployer.activations);
            assertEquals(count, tester.nodeRepository.nodes().list(Node.State.active).nodeType(nodeType).size());
        }

        tester.clock.advance(Duration.ofMinutes(60));
        tester.runMaintainers();

        // one down host should now be failed, but not two as we are only allowed to fail one proxy
        assertEquals(expectedFailCount, tester.deployer.activations);
        assertEquals(count - expectedFailCount, tester.nodeRepository.nodes().list(Node.State.active).nodeType(nodeType).size());
        assertEquals(expectedFailCount, tester.nodeRepository.nodes().list(Node.State.failed).nodeType(nodeType).size());
        tester.nodeRepository.nodes().list(Node.State.failed).nodeType(nodeType)
                .forEach(node -> assertTrue(downHosts.contains(node.hostname())));

        // trying to fail again will still not fail the other down host
        tester.clock.advance(Duration.ofMinutes(60));
        tester.runMaintainers();
        assertEquals(count - expectedFailCount, tester.nodeRepository.nodes().list(Node.State.active).nodeType(nodeType).size());
    }
Tests automatic failing of nodes.

@author bratseth
@author mpolden
node-repository/src/test/java/com/yahoo/vespa/hosted/provision/maintenance/NodeFailerTest.java