Skip to content

Clean up scheduled executor lifecycle in ProfilerGlobalCooldownTest#4732

Draft
Copilot wants to merge 7 commits into
mainfrom
copilot/fix-review-comment
Draft

Clean up scheduled executor lifecycle in ProfilerGlobalCooldownTest#4732
Copilot wants to merge 7 commits into
mainfrom
copilot/fix-review-comment

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 28, 2026

ProfilerGlobalCooldownTest created a scheduled thread pool per test and never shut it down. Since profileAndUpload() schedules delayed work on that executor, the test could leave background tasks running and become timing-sensitive.

  • Scope

    • Limit the change to ProfilerGlobalCooldownTest
    • Address the review comment without changing profiler behavior
  • Executor lifecycle

    • Replace the ad hoc scheduled pool with a daemon single-thread scheduled executor
    • Track created executors in the test class
    • Shut them down in @AfterEach so no background work survives the test
  • Effect

    • Prevent lingering non-daemon threads from affecting test completion
    • Reduce flakiness from scheduled work continuing past assertions
@AfterEach
void tearDown() {
  scheduledExecutorServices.forEach(ScheduledExecutorService::shutdownNow);
  scheduledExecutorServices.clear();
}

ScheduledExecutorService scheduledExecutorService =
    Executors.newSingleThreadScheduledExecutor(
        runnable -> {
          Thread thread = new Thread(runnable);
          thread.setDaemon(true);
          return thread;
        });

johnoliver and others added 4 commits May 27, 2026 16:55
- Creating/Touching a file at a well known location, by default "<temp_dir>/applicationinsights-agent-profile-trigger"
- Add a JMX mbean, can be called via "jcmd <pid> MBean.invoke com.microsoft:type=AI-alert,name=ProfilerControl triggerProfile"
- Add a global cooldown on the profile to ensure that we dont get repeat profiles from multiple sources
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI and others added 3 commits May 28, 2026 12:47
Co-authored-by: johnoliver <1615532+johnoliver@users.noreply.github.com>
Co-authored-by: johnoliver <1615532+johnoliver@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix code according to review comment Clean up scheduled executor lifecycle in ProfilerGlobalCooldownTest May 28, 2026
Copilot AI requested a review from johnoliver May 28, 2026 12:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants