[GitHub] [kafka] machi1990 commented on a diff in pull request #13664: KAFKA-14961: harden DefaultBackgroundThreadTest.testStartupAndTearDown test

2023-05-03 Thread via GitHub


machi1990 commented on code in PR #13664:
URL: https://github.com/apache/kafka/pull/13664#discussion_r1183913810


##
clients/src/test/java/org/apache/kafka/clients/consumer/internals/DefaultBackgroundThreadTest.java:
##
@@ -89,11 +90,14 @@ public void setup() {
 }
 
 @Test
-public void testStartupAndTearDown() {
+public void testStartupAndTearDown() throws InterruptedException {
+
when(coordinatorManager.poll(anyLong())).thenReturn(mockPollCoordinatorResult());
+when(commitManager.poll(anyLong())).thenReturn(mockPollCommitResult());
 DefaultBackgroundThread backgroundThread = mockBackgroundThread();
 backgroundThread.start();
-assertTrue(backgroundThread.isRunning());
+TestUtils.waitForCondition(backgroundThread::isRunning, "Failed 
awaiting for the background thread to be running");
 backgroundThread.close();
+assertFalse(backgroundThread.isRunning());

Review Comment:
   Thanks for the review @kirktrue 
   
   It is guaranteed that is running will be false when `close()` is called: 
https://github.com/apache/kafka/blob/6c3e82f69a081b760a685817332ea0a2f7a2a6a8/clients/src/main/java/org/apache/kafka/clients/consumer/internals/DefaultBackgroundThread.java#L230



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



[GitHub] [kafka] machi1990 commented on a diff in pull request #13664: KAFKA-14961: harden DefaultBackgroundThreadTest.testStartupAndTearDown test

2023-05-03 Thread via GitHub


machi1990 commented on code in PR #13664:
URL: https://github.com/apache/kafka/pull/13664#discussion_r1183579541


##
clients/src/test/java/org/apache/kafka/clients/consumer/internals/DefaultBackgroundThreadTest.java:
##
@@ -89,11 +90,14 @@ public void setup() {
 }
 
 @Test
-public void testStartupAndTearDown() {
+public void testStartupAndTearDown() throws InterruptedException {
+
when(coordinatorManager.poll(anyLong())).thenReturn(mockPollCoordinatorResult());
+when(commitManager.poll(anyLong())).thenReturn(mockPollCommitResult());

Review Comment:
   These stubs call where missing thus causing the NPE as indicated in the JIRA



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



[GitHub] [kafka] machi1990 commented on a diff in pull request #13664: KAFKA-14961: harden DefaultBackgroundThreadTest.testStartupAndTearDown test

2023-05-03 Thread via GitHub


machi1990 commented on code in PR #13664:
URL: https://github.com/apache/kafka/pull/13664#discussion_r1183579038


##
clients/src/test/java/org/apache/kafka/clients/consumer/internals/DefaultBackgroundThreadTest.java:
##
@@ -89,11 +90,14 @@ public void setup() {
 }
 
 @Test
-public void testStartupAndTearDown() {
+public void testStartupAndTearDown() throws InterruptedException {
+
when(coordinatorManager.poll(anyLong())).thenReturn(mockPollCoordinatorResult());
+when(commitManager.poll(anyLong())).thenReturn(mockPollCommitResult());
 DefaultBackgroundThread backgroundThread = mockBackgroundThread();
 backgroundThread.start();
-assertTrue(backgroundThread.isRunning());
+TestUtils.waitForCondition(backgroundThread::isRunning, "Failed 
awaiting for the background thread to be running");

Review Comment:
   This will wait up to 15s, the default timeout. It should be good enough!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org