Skip to content

Commit

Permalink
[Storage] Log test method entry and exit. (Azure#23853)
Browse files Browse the repository at this point in the history
* Log test method entry and exit.

* pr feedback.
  • Loading branch information
kasobol-msft authored Aug 31, 2021
1 parent 22d1324 commit f3920a2
Showing 1 changed file with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

package com.azure.storage.common.test.shared.extensions;

import com.azure.core.util.logging.ClientLogger;
import com.azure.storage.common.test.shared.TestNameProvider;
import org.spockframework.runtime.extension.AbstractGlobalExtension;
import org.spockframework.runtime.extension.IMethodInterceptor;
Expand All @@ -11,6 +12,8 @@

public final class TestHeaderExtension extends AbstractGlobalExtension {

private static final ClientLogger LOGGER = new ClientLogger(TestHeaderExtension.class);

@Override
public void visitSpec(SpecInfo specInfo) {
specInfo.getAllFeatures().forEach(feature ->
Expand All @@ -19,14 +22,19 @@ public void visitSpec(SpecInfo specInfo) {

private static class TestHeaderIterationInterceptor implements IMethodInterceptor {
@Override
public void intercept(IMethodInvocation invocation) {
public void intercept(IMethodInvocation invocation) throws Throwable {
// Print out the test name to create breadcrumbs in our test logging in case anything hangs.
String testName = TestNameProvider.getTestName(invocation.getIteration());
System.out.printf("========================= %s =========================%n", testName);
System.out.printf("%s is starting%n", testName);
LOGGER.info("{} is starting", testName);
long startTimestamp = System.currentTimeMillis();

try {
invocation.proceed();
} catch (Throwable throwable) {
throwable.printStackTrace();
} finally {
long duration = System.currentTimeMillis() - startTimestamp;
System.out.printf("%s finished and took %d ms%n", testName, duration);
LOGGER.info("{} finished and took {} ms", testName, duration);
}
}
}
Expand Down

0 comments on commit f3920a2

Please sign in to comment.