[
https://issues.apache.org/jira/browse/FLINK-41721?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Martijn Visser updated FLINK-41721:
-----------------------------------
Labels: starter (was: )
> InternalMiniClusterExtension leaks a MiniCluster when registered on a static
> field
> ----------------------------------------------------------------------------------
>
> Key: FLINK-41721
> URL: https://issues.apache.org/jira/browse/FLINK-41721
> Project: Flink
> Issue Type: Bug
> Components: Tests
> Affects Versions: 2.4.0, 2.5.0
> Reporter: Purushottam Sinha
> Priority: Minor
> Labels: starter
>
> *Problem*
> Since FLINK-32852, {{InternalMiniClusterExtension}} also implements
> {{BeforeEachCallback}} and {{AfterEachCallback}}. JUnit calls both the class
> and the per-test callbacks of an extension registered on a static field. So
> every test starts a new MiniCluster, and the one started in {{beforeAll}} is
> never shut down. It keeps its TaskManagers, threads and ports until the
> forked JVM exits.
> *Evidence*
> *
> {{flink-runtime/src/test/java/org/apache/flink/runtime/testutils/InternalMiniClusterExtension.java}}:
> {{beforeAll}} and {{beforeEach}} both call {{miniClusterResource.before()}}.
> {{MiniClusterResource.before()}} starts a new cluster on every call and
> overwrites the field.
> * {{SlotCountExceedingParallelismTest}} (3 tests) with a static registration:
> 4 clusters started, 3 shut down.
> * 8 tests on master register it this way: {{ClientTest}},
> {{PartialConsumePipelinedResultTest}}, {{JobRecoveryITCase}},
> {{CoordinatorEventsExactlyOnceITCase}}, {{AdaptiveSchedulerSimpleITCase}},
> {{AdaptiveSchedulerSlotSharingITCase}},
> {{TaskCancelAsyncProducerConsumerITCase}}, {{StateHandleReuseITCase}}.
> *Proposed fix*
> * Skip {{beforeEach}}/{{afterEach}} when {{beforeAll}} already started the
> cluster. A static field then gives one cluster per class, as before
> FLINK-32852, and an instance field still gives one per test.
> *Acceptance*
> * A test with a static registration gets the same running cluster in every
> test method.
> * The 8 tests above start and shut down the same number of clusters.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)