Copilot commented on code in PR #23638:
URL: https://github.com/apache/kafka/pull/23638#discussion_r4641551826


##########
core/src/test/scala/unit/kafka/server/StreamsGroupDescribeRequestTest.scala:
##########
@@ -44,6 +44,124 @@ import java.lang.{Byte => JByte}
 )
 class StreamsGroupDescribeRequestTest(cluster: ClusterInstance) extends 
GroupCoordinatorBaseRequestTest(cluster) {
 
+  @ClusterTest(
+    serverProperties = Array(
+      new ClusterConfigProperty(key = 
GroupCoordinatorConfig.STREAMS_GROUP_INITIAL_REBALANCE_DELAY_MS_CONFIG, value = 
"0"),
+      new ClusterConfigProperty(key = 
GroupCoordinatorConfig.STREAMS_GROUP_ASSIGNOR_OFFLOAD_ENABLE_CONFIG, value = 
"false")
+    )
+  )
+  def testStreamsGroupDescribeIncludesTasksPendingRevocation(): Unit = {
+    createOffsetsTopic()
+    createTopic(topic = "foo", numPartitions = 2)
+
+    val topology = new StreamsGroupHeartbeatRequestData.Topology()
+      .setEpoch(1)
+      .setSubtopologies(List(
+        new StreamsGroupHeartbeatRequestData.Subtopology()
+          .setSubtopologyId("subtopology-1")
+          .setSourceTopics(List("foo").asJava)
+          .setRepartitionSinkTopics(List.empty.asJava)
+          .setRepartitionSourceTopics(List.empty.asJava)
+          .setStateChangelogTopics(List.empty.asJava)
+      ).asJava)
+
+    // Member-1 joins and receives both active tasks.
+    var member1Response: StreamsGroupHeartbeatResponseData = null
+    TestUtils.waitUntilTrue(() => {
+      member1Response = streamsGroupHeartbeat(
+        groupId = "grp",
+        memberId = "member-1",
+        processId = "process-1",
+        rebalanceTimeoutMs = 5 * 60 * 1000,
+        activeTasks = List.empty,
+        standbyTasks = List.empty,
+        warmupTasks = List.empty,
+        topology = topology
+      )
+      member1Response.activeTasks != null &&
+        
member1Response.activeTasks.asScala.flatMap(_.partitions.asScala).toSet == 
Set[Integer](0, 1)
+    }, msg = s"Member-1 did not receive both tasks. Last response 
$member1Response.")
+
+    // Member-2 joins, moving one task to its target assignment.
+    val member2Response = streamsGroupHeartbeat(
+      groupId = "grp",
+      memberId = "member-2",
+      processId = "process-2",
+      rebalanceTimeoutMs = 5 * 60 * 1000,
+      activeTasks = List.empty,
+      standbyTasks = List.empty,
+      warmupTasks = List.empty,
+      topology = topology
+    )
+
+    // Member-1 reports that it still owns both tasks and receives a 
revocation request.
+    // Do not acknowledge the reduced assignment: the revoked task is still 
pending.
+    val revocationResponse = streamsGroupHeartbeat(
+      groupId = "grp",
+      memberId = "member-1",
+      memberEpoch = member1Response.memberEpoch,
+      activeTasks = convertTaskIds(member1Response.activeTasks),
+      standbyTasks = List.empty,
+      warmupTasks = List.empty
+    )
+    assertEquals(1, 
revocationResponse.activeTasks.asScala.flatMap(_.partitions.asScala).size)
+
+    for (version <- ApiKeys.STREAMS_GROUP_DESCRIBE.oldestVersion() to 
ApiKeys.STREAMS_GROUP_DESCRIBE.latestVersion(isUnstableApiEnabled)) {
+      val group = streamsGroupDescribe(groupIds = List("grp"), version = 
version.toShort).head
+      assertEquals(Errors.NONE.code, group.errorCode)
+      assertEquals("Reconciling", group.groupState)
+      assertEquals(2, group.members.size)
+
+      val member1 = group.members.asScala.find(_.memberId == "member-1").get
+      val member2 = group.members.asScala.find(_.memberId == "member-2").get
+      val member1Target = 
member1.targetAssignment.activeTasks.asScala.flatMap(_.partitions.asScala).toSet
+      val member2Target = 
member2.targetAssignment.activeTasks.asScala.flatMap(_.partitions.asScala).toSet
+      assertEquals(1, member1Target.size)
+      assertEquals(1, member2Target.size)
+      assertEquals(Set[Integer](0, 1), member1Target ++ member2Target)
+      assertTrue(member2.assignment.activeTasks.isEmpty)
+
+      // Describe must include the task pending revocation until member-1 
acknowledges its release.
+      assertEquals(1, member1.assignment.activeTasks.size)
+      assertEquals("subtopology-1", 
member1.assignment.activeTasks.get(0).subtopologyId)
+      assertEquals(
+        Set[Integer](0, 1),
+        member1.assignment.activeTasks.get(0).partitions.asScala.toSet,
+        s"Describe version $version must include active tasks pending 
revocation"

Review Comment:
   This cluster test asserts Describe state immediately after a heartbeat that 
triggers revocation. In practice, group state/assignment visibility can be 
slightly asynchronous, which can make this test flaky under load. Consider 
wrapping the per-version Describe assertions in `TestUtils.waitUntilTrue` (or 
add a single `waitUntilTrue` before the loop that waits for `Reconciling` + 
expected member/assignments) so the test waits for the coordinator to publish 
the updated state before asserting.



##########
group-coordinator/src/test/java/org/apache/kafka/coordinator/group/streams/StreamsGroupMemberTest.java:
##########
@@ -421,6 +430,35 @@ public void testAsStreamsGroupDescribeMember() {
         assertEquals(expected, actual);
     }
 
+    @Test
+    public void 
testAsStreamsGroupDescribeMemberWithOnlyTasksPendingRevocation() {
+        final StreamsGroupMember member = new 
StreamsGroupMember.Builder(createStreamsGroupMember())
+            .setState(MemberState.UNREVOKED_TASKS)
+            .setAssignedTasks(TasksTupleWithEpochs.EMPTY)
+            .build();
+
+        StreamsGroupDescribeResponseData.Member actual = 
member.asStreamsGroupDescribeMember(TasksTuple.EMPTY, MemberTaskOffsets.EMPTY);

Review Comment:
   This test passes `TasksTuple.EMPTY` (non-null) as `targetAssignment`, but 
`asStreamsGroupDescribeMember` will populate `targetAssignment` with explicitly 
empty lists when the argument is non-null. Depending on the generated `equals` 
semantics (null vs empty list), `new Assignment()` may not be equal to an 
Assignment with fields set to empty lists, making the assertion 
brittle/incorrect. To make the test consistent with the production method 
behavior, either (a) pass `null` for `targetAssignment` if the intent is 'no 
target assignment', or (b) update the expected `targetAssignment` to set empty 
task lists explicitly.



##########
group-coordinator/src/test/java/org/apache/kafka/coordinator/group/streams/StreamsGroupMemberTest.java:
##########
@@ -421,6 +430,35 @@ public void testAsStreamsGroupDescribeMember() {
         assertEquals(expected, actual);
     }
 
+    @Test
+    public void 
testAsStreamsGroupDescribeMemberWithOnlyTasksPendingRevocation() {
+        final StreamsGroupMember member = new 
StreamsGroupMember.Builder(createStreamsGroupMember())
+            .setState(MemberState.UNREVOKED_TASKS)
+            .setAssignedTasks(TasksTupleWithEpochs.EMPTY)
+            .build();
+
+        StreamsGroupDescribeResponseData.Member actual = 
member.asStreamsGroupDescribeMember(TasksTuple.EMPTY, MemberTaskOffsets.EMPTY);
+        StreamsGroupDescribeResponseData.Assignment expected = new 
StreamsGroupDescribeResponseData.Assignment()
+            .setActiveTasks(List.of(
+                new StreamsGroupDescribeResponseData.TaskIds()
+                    .setSubtopologyId(SUBTOPOLOGY2)
+                    .setPartitions(List.of(1, 2, 3))
+            ))
+            .setStandbyTasks(List.of(
+                new StreamsGroupDescribeResponseData.TaskIds()
+                    .setSubtopologyId(SUBTOPOLOGY1)
+                    .setPartitions(List.of(4, 5, 6))
+            ))
+            .setWarmupTasks(List.of(
+                new StreamsGroupDescribeResponseData.TaskIds()
+                    .setSubtopologyId(SUBTOPOLOGY2)
+                    .setPartitions(List.of(7, 9))
+            ));
+
+        assertEquals(expected, actual.assignment());
+        assertEquals(new StreamsGroupDescribeResponseData.Assignment(), 
actual.targetAssignment());

Review Comment:
   This test passes `TasksTuple.EMPTY` (non-null) as `targetAssignment`, but 
`asStreamsGroupDescribeMember` will populate `targetAssignment` with explicitly 
empty lists when the argument is non-null. Depending on the generated `equals` 
semantics (null vs empty list), `new Assignment()` may not be equal to an 
Assignment with fields set to empty lists, making the assertion 
brittle/incorrect. To make the test consistent with the production method 
behavior, either (a) pass `null` for `targetAssignment` if the intent is 'no 
target assignment', or (b) update the expected `targetAssignment` to set empty 
task lists explicitly.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to