Skip to content

Commit

Permalink
exclude testcontainer watchdog thread from thread leak checks
Browse files Browse the repository at this point in the history
Signed-off-by: Varun Bharadwaj <[email protected]>
  • Loading branch information
varunbharadwaj committed Feb 5, 2025
1 parent 670e471 commit 0313be2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
4 changes: 3 additions & 1 deletion plugins/ingestion-kafka/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ dependencies {
// kafka
api "org.slf4j:slf4j-api:${versions.slf4j}"
api "org.apache.kafka:kafka-clients:${versions.kafka}"
api "org.xerial.snappy:snappy-java:${versions.snappy}"

// dependencies of kafka-clients
runtimeOnly "org.xerial.snappy:snappy-java:${versions.snappy}"

// test
testImplementation "com.github.docker-java:docker-java-api:${versions.docker}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

package org.opensearch.plugin.kafka;

import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope;
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters;

import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.Producer;
Expand Down Expand Up @@ -45,12 +45,7 @@
/**
* Integration test for Kafka ingestion
*/

// This test uses a Kafka test container which schedules a watcher daemon thread for monitoring hanging tests.
// The watcher thread sometimes is not stopped on time at the end of test execution resulting in thread leak check
// errors after which they are attempted to be stopped. Since these threads are outside the scope of this test and have
// no good way to stop them, we disable the checks using ThreadLeakScope.Scope.NONE
@ThreadLeakScope(ThreadLeakScope.Scope.NONE)
@ThreadLeakFilters(filters = TestContainerWatchdogThreadLeakFilter.class)
public class IngestFromKafkaIT extends OpenSearchIntegTestCase {
static final String topicName = "test";

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

package org.opensearch.plugin.kafka;

import com.carrotsearch.randomizedtesting.ThreadFilter;

/**
* The {@link org.testcontainers.images.TimeLimitedLoggedPullImageResultCallback} instance used by test containers,
* for example {@link org.testcontainers.containers.KafkaContainer} creates a watcher daemon thread which is never
* stopped. This filter excludes that thread from the thread leak detection logic.
*/
public final class TestContainerWatchdogThreadLeakFilter implements ThreadFilter {
@Override
public boolean reject(Thread t) {
return t.getName().startsWith("testcontainers-pull-watchdog-");
}
}

0 comments on commit 0313be2

Please sign in to comment.