Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to run subprojects tests (including setup methods) sequentially when testing
    primarykey
    data
    text
    <p><strong>EDIT4</strong> Most of the text below the horizontal rule doesn't have anything to do with the real problem. At the beginning I thought forking is the problem, but that is not true.</p> <p>I'm trying to run all the tests of an aggregates subprojects. Before all the tests in a subproject a setup method should run, and after the tests in a subproject a cleanup method should run.</p> <p>When running the test task for the aggregate project, I expect the following sequence</p> <ul> <li>setup method of project A is called</li> <li>tests for project A are executed</li> <li>cleanup method for project A is called</li> <li>the same for project B</li> </ul> <p>But the sequence is:</p> <ul> <li>setup methods of project A and B are called</li> <li>tests of project A are executed</li> <li>tests of project B are executed</li> <li>cleanup methods of project A and B are called</li> </ul> <p>A build script having this behaviour can be found <a href="https://gist.github.com/choedl/6634961" rel="noreferrer">here</a>.</p> <p>How can I fix this problem to get my expected sequence?</p> <hr> <p>I'm using forking to run the tests in my subprojects. For every subproject a mongo db is started before the tests and stopped after the tests.</p> <p>The tests within one project run sequentially; this works well if I run the tests for a single project.</p> <p>But if I run the task <strong>test</strong> for project root (the aggregate containing the sub projects), I want the forked jvms to be started sequentially, i.e.</p> <ol> <li>the jvm for project A is forked and its tests are executed</li> <li>the jvm for project B is forked and its tests are executed</li> <li>...</li> </ol> <p>But it looks like the jvms are started in parallel; this is not what I want.</p> <p>I tried the following (which should be set to 1 already, according to the documentation):</p> <pre><code> concurrentRestrictions in Test := Seq( Tags.limit(Tags.ForkedTestGroup, 1) ) </code></pre> <p>But it didn't work. Directly after starting the test task, the following is printed (before any test log is printed) from my setup method:</p> <pre><code>startupDb, thread name = pool-4-thread-5 startupDb, thread name = pool-4-thread-7 startupDb, thread name = pool-4-thread-2 startupDb, thread name = pool-4-thread-6 startupDb, thread name = pool-4-thread-8 startupDb, thread name = pool-4-thread-3 startupDb, thread name = pool-4-thread-9 </code></pre> <p>These are my test related settings:</p> <pre><code>parallelExecution in Test := false, testOptions in Test += Tests.Setup( () =&gt; MongoTest.startupDb() ), testOptions in Test += Tests.Cleanup( () =&gt; MongoTest.shutdownDb() ), fork in Test := true, concurrentRestrictions in Test := Seq( Tags.limit(Tags.ForkedTestGroup, 1) ) </code></pre> <p>It's important for me to use forking, but in the way as described above.</p> <p>I'm using sbt 0.13.0 on Windows 7.</p> <p><strong>EDIT</strong> I created a gist with a <a href="https://gist.github.com/choedl/6634961" rel="noreferrer">sample build</a>.</p> <p><strong>EDIT2</strong> In the <a href="http://www.scala-sbt.org/release/docs/Detailed-Topics/Testing#forking-tests" rel="noreferrer">documentation</a> it says:</p> <blockquote> <p>Control the number of forked JVMs allowed to run at the same time by setting the limit on Tags.ForkedTestGroup tag, which is 1 by default</p> </blockquote> <p>So this should work theoretically. Is this a bug? If not, how can I manage to do that?</p> <p><strong>EDIT3</strong> It looks like forking is not the problem. The problem is that the setup methods are called immediately for all subprojects.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload