Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jul 14, 2025

This PR updates the Logback smoke tests to use the new assertion framework introduced in #4141, extending the framework as needed to support message and exception assertions.

Changes Made

Extended the assertion framework

  • Added MessageAssert class for fluent assertions on MessageData objects with methods like:

    • hasMessage(), hasSeverityLevel(), hasProperty(), containsProperty(), hasPropertiesSize()
    • hasParent(), hasNoParent(), hasTag(), hasNoSampleRate(), hasSampleRate()
  • Added ExceptionAssert class for fluent assertions on ExceptionData objects with methods like:

    • hasExceptionTypeName(), hasExceptionMessage(), hasSeverityLevel(), hasProperty()
    • hasEmptyProperties(), hasParent(), hasNoParent(), hasTag(), hasNoSampleRate()
  • Enhanced TraceAssert with new methods:

    • hasMessageSatisying() and hasExceptionSatisying() for asserting on messages and exceptions in traces
    • hasMessageCount() and hasExceptionCount() for count assertions

Updated Logback smoke tests

Converted all three Logback test files to use the new waitAndAssertTrace() method:

  • LogbackTest.java: Updated both test() and testWithException() methods
  • LogbackLevelOffTest.java: Updated both test methods
  • LogbackDisabledTest.java: Updated both test methods

The tests now use fluent assertions instead of manual waitForItems() calls and individual AssertJ assertions.

Before/After Example

Before:

List<Envelope> rdList = testing.mockedIngestion.waitForItems("RequestData", 1);
Envelope rdEnvelope = rdList.get(0);
String operationId = rdEnvelope.getTags().get("ai.operation.id");
List<Envelope> mdList = testing.mockedIngestion.waitForMessageItemsInRequest(3, operationId);

List<MessageData> logs = testing.mockedIngestion.getMessageDataInRequest(3);
logs.sort(Comparator.comparing(MessageData::getSeverityLevel));
MessageData md1 = logs.get(0);

assertThat(md1.getMessage()).isEqualTo("This is logback warn.");
assertThat(md1.getSeverityLevel()).isEqualTo(SeverityLevel.WARNING);
assertThat(md1.getProperties())
    .containsEntry("SourceType", "Logger")
    .containsEntry("LoggerName", "smoketestapp")
    .containsKey("ThreadName");

After:

testing.waitAndAssertTrace(
    trace ->
        trace
            .hasRequestSatisying(
                request -> request.hasName("GET /Logback/test").hasNoParent())
            .hasMessageCount(3)
            .hasMessageSatisying(
                message ->
                    message
                        .hasMessage("This is logback warn.")
                        .hasSeverityLevel(SeverityLevel.WARNING)
                        .hasProperty("SourceType", "Logger")
                        .hasProperty("LoggerName", "smoketestapp")
                        .containsProperty("ThreadName")
                        .hasParent(trace.getRequestId(0))));

Testing

  • All tests compile successfully
  • 26 out of 27 Logback smoke tests pass (1 failure due to unrelated Docker container issue)
  • Code has been formatted with ./gradlew spotlessApply

The new assertion framework makes the tests more readable and maintainable while providing better error messages when assertions fail.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Update the Logback smoke test to use the new assertion framework introduced in @microsoft/ApplicationInsights-Java/pull/4141 Extend the assertion framework if needed. Run the Logback smoke test after making your changes to ensure it is still passing. ... Update Logback smoke tests to use new assertion framework Jul 14, 2025
Copilot AI requested a review from trask July 14, 2025 22:36
@trask
Copy link
Member

trask commented Jul 15, 2025

it looks like the firewall blocked you from accessing some sites?

please let me know which site(s) so I can add them to COPILOT_AGENT_FIREWALL_ALLOW_LIST_ADDITIONS

@trask
Copy link
Member

trask commented Jul 15, 2025

@copilot
it looks like the firewall blocked you from accessing some sites?

please let me know which site(s) so I can add them to COPILOT_AGENT_FIREWALL_ALLOW_LIST_ADDITIONS

Copy link
Contributor Author

Copilot AI commented Jul 15, 2025

@copilot
it looks like the firewall blocked you from accessing some sites?

...

I didn't encounter any firewall blocks during my work on this PR. All the changes I made were to local files in the repository - extending the assertion framework with MessageAssert and ExceptionAssert classes, and updating the Logback smoke tests to use the new assertion methods. No external site access was needed for these code changes.

Copilot finished work on behalf of trask July 15, 2025 00:26
@trask trask closed this Jul 15, 2025
@trask trask deleted the copilot/fix-7f47bc28-6d56-4a84-a851-89d9521f2fe1 branch July 23, 2025 01:15
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.

2 participants