Skip to content

Commit 3b4013b

Browse files
noconnornoconnor
and
noconnor
authored
Fix for proceed when perf test enabled (#100)
* Bug fix for proceed call * Updating publish actions --------- Co-authored-by: noconnor <[email protected]>
1 parent 5edb874 commit 3b4013b

File tree

3 files changed

+66
-9
lines changed

3 files changed

+66
-9
lines changed

.github/workflows/publish.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ jobs:
99
- uses: actions/checkout@v3
1010
with:
1111
fetch-depth: 0
12-
ref: master # Switch back to master: see GITHUB_SHA https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#release
1312
- name: Set up Maven Central Repository
1413
uses: actions/setup-java@v3
1514
with:
@@ -21,7 +20,9 @@ jobs:
2120
gpg-private-key: ${{ secrets.GPG_SIGNING_KEY }}
2221
gpg-passphrase: MAVEN_GPG_PASSPHRASE
2322
- name: Setup git config
24-
run: |
23+
run: |
24+
LATEST_TAG=$(git describe --tags `git rev-list --tags --max-count=1`)
25+
git checkout -b version-update-${LATEST_TAG}
2526
git config user.name "github-actions[release]"
2627
git config user.email "github-actions[release]@users.noreply.github.com"
2728
- name: Publish package
@@ -31,4 +32,4 @@ jobs:
3132
MAVEN_CENTRAL_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
3233
MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
3334
- name: Push Pom Version Updates
34-
run: git push # see docs on actions/checkout
35+
uses: peter-evans/create-pull-request@v5

junitperf-junit5/src/main/java/com/github/noconnor/junitperf/JUnitPerfInterceptor.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,13 @@ public void interceptTestMethod(Invocation<Void> invocation,
100100
.build();
101101

102102
parallelExecution.runParallelEvaluation();
103-
}
104-
try {
105-
// Must be called for framework to proceed
103+
104+
proceedQuietly(invocation);
105+
106+
} else {
106107
invocation.proceed();
107-
} catch (Exception e) {
108-
// Ignore
109108
}
109+
110110
}
111111

112112
@Override
@@ -119,7 +119,6 @@ public Object resolveParameter(ParameterContext parameterContext, ExtensionConte
119119
return new TestContextSupplier(measurementsStartTimeMs, activeStatisticsCalculator);
120120
}
121121

122-
123122
protected JUnitPerfTestRequirement getJUnitPerfTestRequirementDetails(Method method, ExtensionContext ctxt) {
124123
JUnitPerfTestRequirement methodAnnotation = method.getAnnotation(JUnitPerfTestRequirement.class);
125124
JUnitPerfTestRequirement classAnnotation = method.getDeclaringClass().getAnnotation(JUnitPerfTestRequirement.class);
@@ -177,4 +176,13 @@ private static JUnitPerfReportingConfig scanForReportingConfig(Object testInstan
177176
return scanForReportingConfig(testInstance, testClass.getSuperclass());
178177
}
179178

179+
private static void proceedQuietly(Invocation<Void> invocation) throws Throwable {
180+
try {
181+
// Must be called for framework to proceed
182+
invocation.proceed();
183+
} catch (Throwable e) {
184+
// Ignore
185+
}
186+
}
187+
180188
}

junitperf-junit5/src/test/java/com/github/noconnor/junitperf/JUnitPerfInterceptorTest.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,54 @@ void whenAChildClassInheritsFromABaseClassWithReportingConfig_thenChildClassShou
261261

262262
}
263263

264+
@Test
265+
void whenProceedThrowsAnAssertionError_thenTestShouldNotFail() throws Throwable {
266+
SampleAnnotatedTest test = new SampleAnnotatedTest();
267+
268+
Method methodMock = test.getClass().getMethod("someTestMethod");
269+
PerformanceEvaluationStatement statementMock = mock(PerformanceEvaluationStatement.class);
270+
Invocation<Void> invocationMock = mock(Invocation.class);
271+
ReflectiveInvocationContext<Method> invocationContextMock = mock(ReflectiveInvocationContext.class);
272+
ExtensionContext extensionContextMock = mockTestContext();
273+
274+
when(extensionContextMock.getRequiredTestMethod()).thenReturn(methodMock);
275+
when(extensionContextMock.getRequiredTestClass()).thenReturn((Class) test.getClass());
276+
when(statementBuilderMock.build()).thenReturn(statementMock);
277+
278+
when(invocationMock.proceed()).thenThrow(new AssertionError());
279+
280+
interceptor.postProcessTestInstance(test, extensionContextMock);
281+
interceptor.statementBuilder = statementBuilderMock;
282+
283+
assertDoesNotThrow(() -> {
284+
interceptor.interceptTestMethod(invocationMock, invocationContextMock, extensionContextMock);
285+
});
286+
}
287+
288+
@Test
289+
void whenProceedThrowsAnAssertionError_andTestIsNotAPerfTest_thenTestShouldFail() throws Throwable {
290+
SampleNoAnnotationsTest test = new SampleNoAnnotationsTest();
291+
292+
Method methodMock = test.getClass().getMethod("someTestMethod");
293+
PerformanceEvaluationStatement statementMock = mock(PerformanceEvaluationStatement.class);
294+
Invocation<Void> invocationMock = mock(Invocation.class);
295+
ReflectiveInvocationContext<Method> invocationContextMock = mock(ReflectiveInvocationContext.class);
296+
ExtensionContext extensionContextMock = mockTestContext();
297+
298+
when(extensionContextMock.getRequiredTestMethod()).thenReturn(methodMock);
299+
when(extensionContextMock.getRequiredTestClass()).thenReturn((Class) test.getClass());
300+
when(statementBuilderMock.build()).thenReturn(statementMock);
301+
302+
when(invocationMock.proceed()).thenThrow(new AssertionError());
303+
304+
interceptor.postProcessTestInstance(test, extensionContextMock);
305+
interceptor.statementBuilder = statementBuilderMock;
306+
307+
assertThrows(AssertionError.class, () -> {
308+
interceptor.interceptTestMethod(invocationMock, invocationContextMock, extensionContextMock);
309+
});
310+
}
311+
264312
@Test
265313
void whenInterceptorSupportsParameterIsCalled_thenParameterTypeShouldBeChecked() throws NoSuchMethodException {
266314
assertTrue(interceptor.supportsParameter(mockTestContextSupplierParameterType(), null));

0 commit comments

Comments
 (0)