Files
openobserve/tests/ui-testing/pages/functionsPages
Shrinath RaoandClaude Opus 4.8 9e67c98622 test: fix flaky Functions "create with valid VRL" save (empty body race) (#13222)
## Issue

The Functions e2e test `should create function successfully with valid
VRL code` (`functions-form-validation.spec.js`) flakes on slow CI
runners, failing all retries with a timeout waiting for the success
toast.

From the failing run's trace, the create request went out with an
**empty function body**:

```
POST /api/default/functions  →  {"name":"test_fv_vrl_001","function":"","params":"row",...}
400 Bad Request              →  {"code":400,"message":"Function body cannot be empty"}
```

The backend is behaving correctly (it should reject an empty body). The
bug is in the test's editor-injection helper.

## Root cause

`typeInVrlEditor()` set the Monaco editor content via `executeEdits()`
and then waited a fixed `500ms` before clicking Save. Two problems
compound:

- `executeEdits()` writes the model value but does **not** drive the
editor's `onDidChangeModelContent` commit.
- The editor's `@update:query` emit that syncs `formData.function` is
**debounced by 500ms** (`CodeQueryEditor.vue`).

The fixed `500ms` wait sat exactly on the debounce boundary, so under CI
contention Save fired before `formData.function` was populated —
submitting an empty body. Because it is a deterministic timing gap on a
slow machine, all retries failed together, which reads as flakiness.

## Fix

Make the helper deterministic instead of sleep-based:

- Poll until Monaco has loaded and the function editor is registered
(scoped to its container) instead of a fixed sleep before injection.
- Type real keystrokes into the visible `.view-lines` surface (the
`textarea.inputarea` is a 1px hidden input Playwright cannot click), so
the editor's change listener actually fires.
- Verify the content landed in the Monaco model before proceeding.
- Blur the editor to flush the debounced emit so `formData.function`
updates immediately, rather than racing the debounce timer.

App code is unchanged — this is a test-only fix.

## Verification (local)

- Target test: **4/4 passed** on `--repeat-each=4`.
- Full `functions-form-validation.spec.js`: **11 passed, 3 skipped, 0
failed**.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-16 05:36:30 +00:00
..