This document explains the internal workflow of the EventStream E2E Validator framework. The goal is to ensure that user actions on the frontend correctly trigger the expected backend events in a Kafka-based microservices architecture.
The framework bridges the gap between UI interactions and backend event streams. It works by coordinating a UI test (Playwright) with a backend event listener (Kafka Consumer).
sequenceDiagram
participant User as 👤 User / Playwright
participant UI as 🖥️ UI / Application
participant Producer as 📦 Event Producer
participant Kafka as 🐘 Kafka Topic
participant Consumer as 🎧 Test Consumer
participant Validator as ✅ Schema Validator
User->>UI: Performs Action (e.g., "Place Order")
UI->>Producer: Triggers Backend Event
Producer->>Kafka: Publishes Event (JSON)
par Parallel Verification
User->>UI: Verifies UI Success Message
Consumer->>Kafka: Listens for new messages
end
Kafka-->>Consumer: Delivers Event Payload
Consumer->>Validator: Validates against Schema (AJV)
Validator-->>Consumer: Validation Result (Pass/Fail)
Consumer-->>User: Returns Event Data for Assertion
- Role: Simulates user behavior.
- Action: Clicks buttons, fills forms, and navigates the application.
- Example: A test script logs into the app and clicks "Buy Now".
- Role: Represents the application's backend logic.
- Action: When the UI action happens, this component constructs a JSON event and sends it to a specific Kafka topic (e.g.,
order.events). - Note: In this test framework, we may simulate this using a
producer.tsscript if the real backend isn't connected.
- Role: Acts as the verification agent.
- Action: It subscribes to the relevant Kafka topics before the UI action is performed to ensure no events are missed. It waits for a specific message that matches the expected criteria (e.g., matching
orderId).
- Role: Ensures data integrity.
- Action: Checks the received JSON payload against a strict schema (defined in
schema/order.schema.json). - Checks:
- Are all required fields present?
- Are data types correct (e.g.,
priceis a number, not a string)? - does the structure match the contract?
-
Setup:
- The test starts.
- A Kafka consumer is initialized and subscribes to the target topic.
- Docker containers for Kafka and Zookeeper are ensured to be running.
-
Action:
- Playwright launches the browser.
- The test script performs the business logic (e.g., creating a new user or order).
-
Capture:
- As the action completes, an event is fired to Kafka.
- The test framework's consumer catches this event in real-time.
-
Validation:
- The payload is parsed.
- Schema Validation: Is the JSON valid?
- Data Validation: Does
event.amountmatch the value entered in the UI?
-
Assertion:
- If the event is missing, invalid, or incorrect, the Playwright test fails.
- If everything matches, the test passes.