Skip to content

Flaky Integration Tests Due to Async Terminal Write Processing #107

@javier-godoy

Description

@javier-godoy

Describe the bug

SelectionFeatureIT.testSelectionFeature (and potentially other tests) exhibits flaky behavior where assertions intermittently fail because the terminal buffer hasn't been updated yet when the assertion runs.

Observed Behavior

The test randomly fails at different assertion points with stale values:

term.sendKeys(Keys.BACK_SPACE);
assertThat(term.currentLine(), is("abc")); // Sometimes fails with "abcd"

term.sendKeys(Keys.DELETE);
assertThat(term.currentLine(), is("b")); // Sometimes fails with "ab"

Root Cause

When sendKeys() sends a keystroke to the terminal:

  1. The key event handler in xterm-console-mixin.ts calls terminal.write() with an escape sequence
  2. terminal.write() is asynchronous - xterm.js batches writes for performance
  3. The CSI handler (e.g., backspace(), deleteChar()) processes the escape sequence later
  4. The test's assertion runs before the write queue is processed

The currentLine property is a computed getter that reads fresh from the buffer, but the buffer itself hasn't been updated yet.

Expected behavior

Integration test must pass

Minimal reproducible example

SelectionFeatureIT

Add-on Version

3.2.1-SNAPSHOT

Vaadin Version

25.0.3

Additional information

No response

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Status

Inbox (needs triage)

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions