Skip to content

Replace remaining Thread.sleep with deterministic synchronization in tests #560

Description

@stalep

Summary

Following the short-sleep test stabilization (#559), the remaining ~150 Thread.sleep occurrences across ~28 test files should be converted to deterministic synchronization patterns. These use 80-200ms+ sleeps and are less likely to flake, but still represent non-deterministic test behavior.

Proposed patterns

  1. Command execution waits: CommandExecutionListener + CountDownLatch (same as Replace Thread.sleep with CountDownLatch in tests with short sleeps (10-50ms) #559)
  2. Sequential multi-command tests: Reusable latch that resets between commands, or a CountDownLatch(N) for N commands
  3. Completion/tab rendering waits: TestConnection.waitForOutputContaining() instead of sleep + assert
  4. Pipe/streaming waits: May need custom synchronization based on stream completion

Files to convert

File Sleep(ms) Occurrences
AeshCommandCompletionTest.java 80-200ms 7
AeshCommandOptionActivatorTest.java 80ms 3
AeshCommandResultHandlerTest.java 80ms 4
AeshCommandPipelineTest.java 100-200ms 7
AeshCommandConditionalOperatorTest.java 100ms 15
AeshCommandEndOperatorTest.java 100ms 1
AeshCommandOverrideRequiredTest.java 100ms 1
AeshConsoleTest.java 100ms 1
AeshConnectionClosedTest.java 100ms 2
AeshHelpCommandTest.java 100ms 3
AeshAliasTest.java 100ms 5
ExecutionsTest.java 100ms 18
HyperlinkTest.java 100ms 3
OptionVisibilityTest.java 100ms 2
StreamingPipeTest.java 100-2000ms 6
SubCommandModeConsoleTest.java 100-300ms 25
AeshCommandValidatorTest.java 100ms 2
CompletionConsoleTest.java 200ms 2
AeshRuntimeRunnerTest.java 200ms 3
AeshConsoleRunnerTest.java 200ms 3
AeshCommandActivatorTest.java 200ms 1
AeshCommandRequiredTest.java 200ms 3
CommandExecutionListenerTest.java 200ms 1
HelpDocFormatTest.java 200ms 11
MapCommandTest.java 200ms 12
PromptSupplierTest.java 200ms 5
ShellFeaturesTest.java 200ms 1

Depends on

Notes

  • The SubCommandModeConsoleTest (25 occurrences) and ExecutionsTest (18 occurrences) are the largest files and may benefit from a helper method that wraps the latch/listener pattern.
  • Streaming pipe tests may need stream-completion signals rather than command-execution listeners.
  • Some sleeps may be intentional (e.g., testing timeout behavior) — review each individually.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions