Code review comment: Why do we have to add this code block? Shouldn't this implicitly be asserted if the jobs finishes successfully?

Code under review:
public void testDispatcherProcessFailure() throws Exception {
		final Time timeout = Time.seconds(30L);
		final File zookeeperStoragePath = temporaryFolder.newFolder();

		
		final int numberOfJobManagers = 2;
		final int numberOfTaskManagers = 2;
		final int numberOfSlotsPerTaskManager = 2;

		assertEquals(PARALLELISM, numberOfTaskManagers * numberOfSlotsPerTaskManager);

		
		final DispatcherProcess[] dispatcherProcesses = new DispatcherProcess[numberOfJobManagers];

		
		TaskManagerRunner[] taskManagerRunners = new TaskManagerRunner[numberOfTaskManagers];

		HighAvailabilityServices highAvailabilityServices = null;

		LeaderRetrievalService leaderRetrievalService = null;

		
		File coordinateTempDir = null;

		
		Configuration config = ZooKeeperTestUtils.createZooKeeperHAConfig(
			zooKeeper.getConnectString(), zookeeperStoragePath.getPath());
		
		config.setString(TaskManagerOptions.MANAGED_MEMORY_SIZE, "4m");
		config.setInteger(TaskManagerOptions.NETWORK_NUM_BUFFERS, 100);
		config.setInteger(TaskManagerOptions.NUM_TASK_SLOTS, 2);

		final RpcService rpcService = AkkaRpcServiceUtils.createRpcService("localhost", 0, config);

		try {
			final Deadline deadline = TestTimeOut.fromNow();

			
			coordinateTempDir = temporaryFolder.newFolder();

			
			dispatcherProcesses[0] = new DispatcherProcess(0, config);
			dispatcherProcesses[0].startProcess();

			highAvailabilityServices = HighAvailabilityServicesUtils.createAvailableOrEmbeddedServices(
				config,
				TestingUtils.defaultExecutor());

			
			for (int i = 0; i < numberOfTaskManagers; i++) {
				taskManagerRunners[i] = new TaskManagerRunner(config, ResourceID.generate());
				taskManagerRunners[i].start();
			}

			
			TestingListener leaderListener = new TestingListener();
			leaderRetrievalService = highAvailabilityServices.getDispatcherLeaderRetriever();
			leaderRetrievalService.start(leaderListener);

			
			leaderListener.waitForNewLeader(deadline.timeLeft().toMillis());

			String leaderAddress = leaderListener.getAddress();
			UUID leaderId = leaderListener.getLeaderSessionID();

			final CompletableFuture<DispatcherGateway> dispatcherGatewayFuture = rpcService.connect(
				leaderAddress,
				DispatcherId.fromUuid(leaderId),
				DispatcherGateway.class);
			final DispatcherGateway dispatcherGateway = dispatcherGatewayFuture.get();

			
			waitForTaskManagers(numberOfTaskManagers, dispatcherGateway, deadline.timeLeft());

			final File coordinateDirClosure = coordinateTempDir;
			final Throwable[] errorRef = new Throwable[1];

			
			Thread programTrigger = new Thread("Program Trigger") {
				@Override
				public void run() {
					try {
						testJobManagerFailure(zooKeeper.getConnectString(), coordinateDirClosure, zookeeperStoragePath);
					}
					catch (Throwable t) {
						t.printStackTrace();
						errorRef[0] = t;
					}
				}
			};

			
			programTrigger.start();

			
			AbstractTaskManagerProcessFailureRecoveryTest.waitForMarkerFiles(coordinateTempDir,
					READY_MARKER_FILE_PREFIX, PARALLELISM, deadline.timeLeft().toMillis());

			
			dispatcherProcesses[0].destroy();

			dispatcherProcesses[1] = new DispatcherProcess(1, config);
			dispatcherProcesses[1].startProcess();

			
			leaderListener.waitForNewLeader(deadline.timeLeft().toMillis());

			leaderAddress = leaderListener.getAddress();
			leaderId = leaderListener.getLeaderSessionID();

			final CompletableFuture<DispatcherGateway> newDispatcherGatewayFuture = rpcService.connect(
				leaderAddress,
				DispatcherId.fromUuid(leaderId),
				DispatcherGateway.class);
			final DispatcherGateway newDispatcherGateway = newDispatcherGatewayFuture.get();

			
			waitForTaskManagers(numberOfTaskManagers, newDispatcherGateway, deadline.timeLeft());

			
			AbstractTaskManagerProcessFailureRecoveryTest.touchFile(new File(coordinateTempDir, PROCEED_MARKER_FILE));

			programTrigger.join(deadline.timeLeft().toMillis());

			
			
			AbstractTaskManagerProcessFailureRecoveryTest.waitForMarkerFiles(coordinateTempDir,
					FINISH_MARKER_FILE_PREFIX, 1, deadline.timeLeft().toMillis());

			
			assertFalse("The program did not finish in time", programTrigger.isAlive());

			
			if (errorRef[0] != null) {
				Throwable error = errorRef[0];
				error.printStackTrace();
				fail("The program encountered a " + error.getClass().getSimpleName() + " : " + error.getMessage());
			}
		}
		catch (Throwable t) {
			
			
			t.printStackTrace();

			for (DispatcherProcess p : dispatcherProcesses) {
				if (p != null) {
					p.printProcessLog();
				}
			}

			throw t;
		}
		finally {
			for (int i = 0; i < numberOfTaskManagers; i++) {
				if (taskManagerRunners[i] != null) {
					taskManagerRunners[i].close();
				}
			}

			if (leaderRetrievalService != null) {
				leaderRetrievalService.stop();
			}

			for (DispatcherProcess dispatcherProcess : dispatcherProcesses) {
				if (dispatcherProcess != null) {
					dispatcherProcess.destroy();
				}
			}

			if (highAvailabilityServices != null) {
				highAvailabilityServices.closeAndCleanupAllData();
			}

			RpcUtils.terminateRpcService(rpcService, timeout);

			
			if (coordinateTempDir != null) {
				try {
					FileUtils.deleteDirectory(coordinateTempDir);
				}
				catch (Throwable ignored) {
				}
			}
		}
	}

Line commented on: waitForTaskManagers(numberOfTaskManagers, newDispatcherGateway, deadline.timeLeft());

Revised code:
public void testDispatcherProcessFailure() throws Exception {
		final Time timeout = Time.seconds(30L);
		final File zookeeperStoragePath = temporaryFolder.newFolder();

		
		final int numberOfJobManagers = 2;
		final int numberOfTaskManagers = 2;
		final int numberOfSlotsPerTaskManager = 2;

		assertEquals(PARALLELISM, numberOfTaskManagers * numberOfSlotsPerTaskManager);

		
		final DispatcherProcess[] dispatcherProcesses = new DispatcherProcess[numberOfJobManagers];

		
		TaskManagerRunner[] taskManagerRunners = new TaskManagerRunner[numberOfTaskManagers];

		HighAvailabilityServices highAvailabilityServices = null;

		LeaderRetrievalService leaderRetrievalService = null;

		
		File coordinateTempDir = null;

		
		Configuration config = ZooKeeperTestUtils.createZooKeeperHAConfig(
			zooKeeper.getConnectString(), zookeeperStoragePath.getPath());
		
		config.setString(TaskManagerOptions.MANAGED_MEMORY_SIZE, "4m");
		config.setInteger(TaskManagerOptions.NETWORK_NUM_BUFFERS, 100);
		config.setInteger(TaskManagerOptions.NUM_TASK_SLOTS, 2);

		final RpcService rpcService = AkkaRpcServiceUtils.createRpcService("localhost", 0, config);

		try {
			final Deadline deadline = TestTimeOut.fromNow();

			
			coordinateTempDir = temporaryFolder.newFolder();

			
			dispatcherProcesses[0] = new DispatcherProcess(0, config);
			dispatcherProcesses[0].startProcess();

			highAvailabilityServices = HighAvailabilityServicesUtils.createAvailableOrEmbeddedServices(
				config,
				TestingUtils.defaultExecutor());

			
			for (int i = 0; i < numberOfTaskManagers; i++) {
				taskManagerRunners[i] = new TaskManagerRunner(config, ResourceID.generate());
				taskManagerRunners[i].start();
			}

			
			TestingListener leaderListener = new TestingListener();
			leaderRetrievalService = highAvailabilityServices.getDispatcherLeaderRetriever();
			leaderRetrievalService.start(leaderListener);

			
			leaderListener.waitForNewLeader(deadline.timeLeft().toMillis());

			String leaderAddress = leaderListener.getAddress();
			UUID leaderId = leaderListener.getLeaderSessionID();

			final CompletableFuture<DispatcherGateway> dispatcherGatewayFuture = rpcService.connect(
				leaderAddress,
				DispatcherId.fromUuid(leaderId),
				DispatcherGateway.class);
			final DispatcherGateway dispatcherGateway = dispatcherGatewayFuture.get();

			
			waitForTaskManagers(numberOfTaskManagers, dispatcherGateway, deadline.timeLeft());

			final File coordinateDirClosure = coordinateTempDir;
			final Throwable[] errorRef = new Throwable[1];

			
			Thread programTrigger = new Thread("Program Trigger") {
				@Override
				public void run() {
					try {
						testJobManagerFailure(zooKeeper.getConnectString(), coordinateDirClosure, zookeeperStoragePath);
					}
					catch (Throwable t) {
						t.printStackTrace();
						errorRef[0] = t;
					}
				}
			};

			
			programTrigger.start();

			
			AbstractTaskManagerProcessFailureRecoveryTest.waitForMarkerFiles(coordinateTempDir,
					READY_MARKER_FILE_PREFIX, PARALLELISM, deadline.timeLeft().toMillis());

			
			dispatcherProcesses[0].destroy();

			dispatcherProcesses[1] = new DispatcherProcess(1, config);
			dispatcherProcesses[1].startProcess();

			
			AbstractTaskManagerProcessFailureRecoveryTest.touchFile(new File(coordinateTempDir, PROCEED_MARKER_FILE));

			programTrigger.join(deadline.timeLeft().toMillis());

			
			
			AbstractTaskManagerProcessFailureRecoveryTest.waitForMarkerFiles(coordinateTempDir,
					FINISH_MARKER_FILE_PREFIX, 1, deadline.timeLeft().toMillis());

			
			assertFalse("The program did not finish in time", programTrigger.isAlive());

			
			if (errorRef[0] != null) {
				Throwable error = errorRef[0];
				error.printStackTrace();
				fail("The program encountered a " + error.getClass().getSimpleName() + " : " + error.getMessage());
			}
		}
		catch (Throwable t) {
			
			
			t.printStackTrace();

			for (DispatcherProcess p : dispatcherProcesses) {
				if (p != null) {
					p.printProcessLog();
				}
			}

			throw t;
		}
		finally {
			for (int i = 0; i < numberOfTaskManagers; i++) {
				if (taskManagerRunners[i] != null) {
					taskManagerRunners[i].close();
				}
			}

			if (leaderRetrievalService != null) {
				leaderRetrievalService.stop();
			}

			for (DispatcherProcess dispatcherProcess : dispatcherProcesses) {
				if (dispatcherProcess != null) {
					dispatcherProcess.destroy();
				}
			}

			if (highAvailabilityServices != null) {
				highAvailabilityServices.closeAndCleanupAllData();
			}

			RpcUtils.terminateRpcService(rpcService, timeout);

			
			if (coordinateTempDir != null) {
				try {
					FileUtils.deleteDirectory(coordinateTempDir);
				}
				catch (Throwable ignored) {
				}
			}
		}
	}