Repository: apache/flink
File: flink-runtime/src/test/java/org/apache/flink/runtime/resourcemanager/slotmanager/FineGrainedSlotManagerTest.java (Java)

Code before:
                                                            DEFAULT_TOTAL_RESOURCE_PROFILE,
                                                            DEFAULT_SLOT_RESOURCE_PROFILE)));
                    assertThat(assertFutureCompleteAndReturn(registerTaskManagerFuture2))
                            .isEqualTo(SlotManager.RegistrationResult.SUCCESS);

                    // triggers the metric update task on the main thread
                    scheduledExecutor.triggerPeriodicScheduledTasks();
                    context.runInMainThreadAndWait(() -> {});

                    assertThat(slotsTotalGauge.get().getValue())
                            .isEqualTo(2 * DEFAULT_NUM_SLOTS_PER_WORKER);
                    assertThat(slotsAvailableGauge.get().getValue())
                            .isEqualTo(2 * DEFAULT_NUM_SLOTS_PER_WORKER - 1);

                    final CompletableFuture<Boolean> unRegisterTaskManagerFuture =
                            new CompletableFuture<>();
                    context.runInMainThreadAndWait(
                            () ->
                                    unRegisterTaskManagerFuture.complete(
                                            context.getSlotManager()
                                                    .unregisterTaskManager(
                                                            executorConnection2.getInstanceID(),
                                                            TEST_EXCEPTION)));
                    assertThat(assertFutureCompleteAndReturn(unRegisterTaskManagerFuture)).isTrue();

                    // triggers the metric update task on the main thread
                    scheduledExecutor.triggerPeriodicScheduledTasks();
                    context.runInMainThreadAndWait(() -> {});

                    assertThat(slotsTotalGauge.get().getValue())
                            .isEqualTo(DEFAULT_NUM_SLOTS_PER_WORKER);
                    assertThat(slotsAvailableGauge.get().getValue())
                            .isEqualTo(DEFAULT_NUM_SLOTS_PER_WORKER);
                });
    }
}


Review comment (suggestion):
```suggestion
                    // triggers the metric update task on the main thread and waits for the main thread to process queued up callbacks
```

Code after:
                                                            DEFAULT_TOTAL_RESOURCE_PROFILE,
                                                            DEFAULT_SLOT_RESOURCE_PROFILE)));
                    assertThat(assertFutureCompleteAndReturn(registerTaskManagerFuture2))
                            .isEqualTo(SlotManager.RegistrationResult.SUCCESS);

                    // triggers the metric update task on the main thread and waits for the main
                    // thread to process queued up callbacks
                    scheduledExecutor.triggerPeriodicScheduledTasks();
                    context.runInMainThreadAndWait(() -> {});

                    assertThat(slotsTotalGauge.get().getValue())
                            .isEqualTo(2 * DEFAULT_NUM_SLOTS_PER_WORKER);
                    assertThat(slotsAvailableGauge.get().getValue())
                            .isEqualTo(2 * DEFAULT_NUM_SLOTS_PER_WORKER - 1);

                    final CompletableFuture<Boolean> unRegisterTaskManagerFuture =
                            new CompletableFuture<>();
                    context.runInMainThreadAndWait(
                            () ->
                                    unRegisterTaskManagerFuture.complete(
                                            context.getSlotManager()
                                                    .unregisterTaskManager(
                                                            executorConnection2.getInstanceID(),
                                                            TEST_EXCEPTION)));
                    assertThat(assertFutureCompleteAndReturn(unRegisterTaskManagerFuture)).isTrue();

                    // triggers the metric update task on the main thread and waits for the main
                    // thread to process queued up callbacks
                    scheduledExecutor.triggerPeriodicScheduledTasks();
                    context.runInMainThreadAndWait(() -> {});

                    assertThat(slotsTotalGauge.get().getValue())
                            .isEqualTo(DEFAULT_NUM_SLOTS_PER_WORKER);
                    assertThat(slotsAvailableGauge.get().getValue())
                            .isEqualTo(DEFAULT_NUM_SLOTS_PER_WORKER);
                });
    }
}