[ 
https://issues.apache.org/jira/browse/SLING-4280?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Chetan Mehrotra updated SLING-4280:
-----------------------------------
    Attachment: test-fail-output.txt
                SLING-4280.patch

[Patch|^SLING-4280.patch] which provides a JUnit Rule and a Servlet to enable 
dumping of remote server logs. It works in following way

# {{RemoteLogDumper}} - A junit rule implementation which exposes the current 
executing test description to Slf4j MDC (a threadlocal storage)
# Propagation of test description via HTTP Headers - Whenever the testcase 
makes a remote call via HTTP Client then the associated test description is 
sent as part of following HTTP headers
## {{sling.test.class}} - Header capturing the testcase
## {{sling.test.name}} - Header capturing the testname
# Server side log collection - On server side a {{TestLogServlet}} (registered 
at {{/system/sling/testlog}}) collects the logs in an in memory buffer. The 
buffer gets reset for every new test execution. This allows capturing of the 
logs relevant to currently executing test. These logs are then exposed via the 
{{TestLogServlet}}
# Upon testcase failure the {{RemoteLogDumper}} would fetch the logs from the 
{{TestLogServlet}} and would dump it as part of system output. See [attached 
sample|^test-fail-output.txt]

*Usage*
On client side the testcase needs to just add following rule

{code}
public class AuthenticationResponseCodeTest {
    @Rule
    public TestRule logRule = new RemoteLogDumper();
    ...
    
    @Test
    public void testValidatingCorrectFormCredentials() throws Exception {
       ... //Make remote calls
    }
}
{code}

*Propagation of test description via HTTP Headers*

To enable propoagation of test description via HTTP headers the approach 
differs based on HTTP Client version.

For Http Client 3.x (used in 
org.apache.sling.commons.testing.integration.HttpTestBase which is used by 
majority of integration-test) the headers are added via overriding the execute 
calls. As required changes are done in {{HttpTestBase}} the test classes would 
not be required to do much

For Http Client 4.x a {{TestDescriptionInterceptor}} is provided which should 
be registered with the HttpClient whereever it is instantiated

{code}
DefaultHttpClient httpClient = new DefaultHttpClient();
httpClient.addRequestInterceptor(new TestDescriptionInterceptor());
{code}



> Enable dumping of remote server logs in case of test failures
> -------------------------------------------------------------
>
>                 Key: SLING-4280
>                 URL: https://issues.apache.org/jira/browse/SLING-4280
>             Project: Sling
>          Issue Type: New Feature
>          Components: Testing
>            Reporter: Chetan Mehrotra
>            Assignee: Chetan Mehrotra
>         Attachments: SLING-4280.patch, test-fail-output.txt
>
>
> In case of large test suite running on CI server its hard to make out which 
> logs were created due to execution of which testcase. This makes determining 
> the cause of testcase failure difficult. Often the server logs are also not 
> avialable once the build is completed and only source of information is 
> system out logs captured via junit framework on client side.
> This debugging process can be made simpler if the testcase also dumps the 
> server side logs generated while that testcase executes locally upon failure



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to