You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "Plamen Tanov (Jira)" <ji...@apache.org> on 2022/06/02 09:59:00 UTC

[jira] [Commented] (SUREFIRE-1373) Tests annotated with @NotThreadSafe are not executed in isolation

    [ https://issues.apache.org/jira/browse/SUREFIRE-1373?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17545389#comment-17545389 ] 

Plamen Tanov commented on SUREFIRE-1373:
----------------------------------------

As a workaround you can use multiple executions with excluded groups, e.g.  put @Test(groups="somegroup") together with @NotThreadSafe and then having two configurations like it is described here: [https://rmannibucau.metawerx.net/post/maven-surefire-debugging-execution#configure-multiple-executions]

 

First one (or default one, outside <executions>) with <excludedGroups>somegroup</excludedGroups> and the second one with <groups>somegroup</groups>

 

keep in mind that @BeforeMethod of parent classes will not be called until they have alwaysRun = true (e.g. @BeforeMethod(alwaysRun=true) or @BeforeMethod(groups="somegroup") )

 

But yes - I expected that @NotThreadSafe will be executed at the end (after all other tests are completed) and NOT in parallel to rest of the tests.

 

My case is the same - all tests share one DB instance (for speed optimization) and the tests that checks one statistical method (that aggregates all records in the DB) needs to be called completely separated from the rest of tests (that works on a explicitly separated data) so the data from all tests doesn't conflicts with the expected results from the first method.

> Tests annotated with @NotThreadSafe are not executed in isolation
> -----------------------------------------------------------------
>
>                 Key: SUREFIRE-1373
>                 URL: https://issues.apache.org/jira/browse/SUREFIRE-1373
>             Project: Maven Surefire
>          Issue Type: Bug
>          Components: Maven Surefire Plugin
>    Affects Versions: 2.20
>            Reporter: Sebastian Kirsch
>            Assignee: Tibor Digana
>            Priority: Major
>             Fix For: Backlog
>
>   Original Estimate: 48h
>  Remaining Estimate: 48h
>
> The [surefire documentation|http://maven.apache.org/components/surefire/maven-failsafe-plugin/examples/fork-options-and-parallel-execution.html] states that 
> bq. you can apply the JCIP annotation @net.jcip.annotations.NotThreadSafe on the Java class of JUnit test (pure test class, Suite, Parameterized, etc.) in order to execute it in single Thread instance. The Thread has name maven-surefire-plugin@NotThreadSafe and it is executed at the end of the test run.
> However, the thread is run in parallel to the other tests being executed, which contradicts the documentation and defeats the purpose of running tests sequentially in a single thread.
> See https://github.com/sebastiankirsch/surefire-nonthreadsafe for a test case.



--
This message was sent by Atlassian Jira
(v8.20.7#820007)