Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ void schedule(Action action, long delayInMillis) {
getLogger()
.debug(
"enqueue an action [{}] for [{}] with a delay [{}]ms", action, name(), delayInMillis);
var future = context.schedule(() -> actions.offer(action), delayInMillis);
var future = context.schedule(() -> post(action), delayInMillis);
scheduledActions.put(action, future);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ private void activate(int code) {
if (!task.isActive()) {
task.setActive(true);
}
// cancel any existing scheduled task ping as the activate call does the same action.
var dedupAction =
code == Constants.TASK_PING_CODE ? Action.TASK_PING : new Action.TaskPing(code);
Comment on lines +90 to +92
Copy link

Copilot AI Oct 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The logic for determining the dedup action could be extracted into a helper method to improve readability and make the intention clearer. Consider creating a method like getDedupAction(int code) that returns the appropriate Action.

Copilot uses AI. Check for mistakes.
var future = getScheduledActions().get(dedupAction);
if (future != null) {
future.cancel(false);
}
execute(code);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
import com.netflix.maestro.flow.models.Task;
import com.netflix.maestro.flow.models.TaskDef;
import java.util.Set;
import java.util.concurrent.ScheduledFuture;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;

public class TaskActorTest extends ActorBaseTest {

Expand Down Expand Up @@ -144,10 +146,21 @@ public void testRunForActionTaskPingForTerminatedTask() {

@Test
public void testRunForActionTaskActivate() {
verifyExecute(Action.TASK_ACTIVATE, false);
var mockFuture = Mockito.mock(ScheduledFuture.class);
taskActor.getScheduledActions().put(Action.TASK_PING, mockFuture);
Copy link

Copilot AI Oct 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test uses Action.TASK_PING as the key, but the production code creates a new Action.TaskPing(code) object. These are different objects and won't match in the map lookup, making this test ineffective.

Suggested change
taskActor.getScheduledActions().put(Action.TASK_PING, mockFuture);
taskActor.getScheduledActions().put(new Action.TaskPing(task.getCode()), mockFuture);

Copilot uses AI. Check for mistakes.
verifyExecute(Action.TASK_ACTIVATE, false, null);
verify(mockFuture, times(1)).cancel(false);
}

private void verifyExecute(Action action, boolean activeFlag) {
@Test
public void testRunForActionTaskActivateWithoutCancel() {
var mockFuture = Mockito.mock(ScheduledFuture.class);
taskActor.getScheduledActions().put(new Action.TaskPing(123), mockFuture);
verifyExecute(Action.TASK_ACTIVATE, false, new Action.TaskPing(123));
verify(mockFuture, times(0)).cancel(false);
}

private void verifyExecute(Action action, boolean activeFlag, Action extra) {
task.setActive(activeFlag);
task.setStarted(true);
task.setStartDelayInMillis(3000000L);
Expand All @@ -157,7 +170,8 @@ private void verifyExecute(Action action, boolean activeFlag) {
assertTrue(task.isActive());
verify(context, times(1)).execute(any(), any());
assertEquals(1, task.getPollCount());
assertEquals(Set.of(Action.TASK_PING), taskActor.getScheduledActions().keySet());
var actions = extra == null ? Set.of(Action.TASK_PING) : Set.of(Action.TASK_PING, extra);
assertEquals(actions, taskActor.getScheduledActions().keySet());
verify(context, times(0)).cloneTask(any());
verifyEmptyAction(flowActor);
}
Expand Down Expand Up @@ -193,7 +207,7 @@ public void testExecuteWithCustomCode() {

@Test
public void testRunForActionTaskTimeout() {
verifyExecute(Action.TASK_TIMEOUT, true);
verifyExecute(Action.TASK_TIMEOUT, true, null);
}

@Test
Expand Down