Skip to content

Conversation

simpat-adam
Copy link
Contributor

@simpat-adam simpat-adam commented Sep 4, 2025

No description provided.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds Kafka end-to-end (E2E) testing capabilities to the Data Management Service (DMS), enabling automated testing of Kafka message production when DMS operations occur.

  • Implements Kafka E2E test infrastructure with message collection and comparison utilities
  • Adds test scenarios for Kafka connectivity and message validation
  • Refactors existing test utilities to support reusable JSON comparison logic

Reviewed Changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
StepDefinitions/KafkaStepDefinitions.cs New step definitions for Kafka connectivity testing and message validation
Management/KafkaMessageCollector.cs Core Kafka consumer for collecting test messages with proper lifecycle management
Management/JsonTestUtilities.cs Extracted reusable JSON comparison utilities from existing step definitions
StepDefinitions/StepDefinitions.cs Refactored to use centralized JSON comparison utilities
Features/General/KafkaMessaging.feature Test scenarios for Kafka functionality
Configuration files Updates to support Kafka testing in CI environment

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.


- name: Build
run: ./build-dms.ps1 Build -Configuration ${{ env.CONFIGURATION }} -IdentityProvider ${{matrix.identityprovider}}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kafka E2E Test Connectivity Fix

Challenge

Kafka E2E tests passed locally but failed in CI with message consumption errors. The issue was a Docker networking mismatch between Kafka's advertised listeners and how clients connect in different environments.

Root Cause

  • Kafka advertises PLAINTEXT://dms-kafka1:9092
  • E2E tests were hardcoded to localhost:9092
  • Local works with host file entry (127.0.0.1 dms-kafka1)
  • CI fails because dms-kafka1 hostname doesn't resolve

Attempted Solutions

  1. Dual listeners (INTERNAL/EXTERNAL) - Failed due to topic isolation between listeners
  2. Single listener with localhost - Failed because containers can't reach each other via localhost
  3. Network aliases - Failed due to Kafka's advertised listener behavior

Final Solution

Made E2E test connection configurable via environment variable:

  • Added KAFKA_BOOTSTRAP_SERVERS environment variable to KafkaStepDefinitions.cs
  • CI uses dms-kafka1:9092 with host file entry
  • Local development continues using localhost:9092 with host file entry
  • Kept original Kafka configuration intact

@@ -17,38 +17,17 @@ public static class SetupHooks
[BeforeTestRun]
public static async Task BeforeTestRun(PlaywrightContext context, TestLogger logger)
{
if (AppSettings.UseTestContainers)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed dead code from the TestContainers days. (It really trips up AI)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@simpat-adam simpat-adam force-pushed the DMS-808 branch 2 times, most recently from 085368c to 4b33f44 Compare September 6, 2025 00:24
namespace EdFi.DataManagementService.Tests.E2E.StepDefinitions;

[Binding]
public class KafkaStepDefinitions(TestLogger logger) : IDisposable
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is sweet!

private readonly TestLogger _logger;
private readonly DateTime _collectionStartTime;

public KafkaMessageCollector(string bootstrapServers, TestLogger logger)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about a comment that this is the Kafka listener/consumer

@bradbanister bradbanister merged commit fd68da6 into main Sep 9, 2025
27 checks passed
@bradbanister bradbanister deleted the DMS-808 branch September 9, 2025 16:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants