Software Testing & QA (50 Qs)•Part 3: Advanced Internals, Scale & Production Quality (Senior / Lead)
Testing Asynchronous Event-Driven Architectures: Validating Kafka / RabbitMQ consumer processing.
senior LevelCode ExampleTestingAsync & PromisesSystem Design
In Simple Words: Testing distributed systems where publishers and consumers communicate asynchronously over message brokers:
- Producer publishes
OrderCreatedevent to Kafka (running via Testcontainers). - Polling Assertions: Never use
sleep(5000)! Use polling libraries (e.g.awaitilityin Java, or Playwright'sexpect.poll()in TypeScript):typescriptawait expect.poll(async () => { return await db.query('SELECT status FROM orders WHERE id = $1', [orderId]); }, { timeout: 10000, intervals: [200] }).toBe('PROCESSED'); - Verifies that background async consumers processed the message and committed the database transaction without race conditions.