Skip to content

Instantly share code, notes, and snippets.

@Andrew0000
Created October 15, 2024 12:27
Show Gist options
  • Save Andrew0000/0af304294f54b8142528c735bc48e40b to your computer and use it in GitHub Desktop.
Save Andrew0000/0af304294f54b8142528c735bc48e40b to your computer and use it in GitHub Desktop.
Check gradle parallel test: same process (memory) or different?
tasks.withType<Test>().configureEach {
maxParallelForks = 3
}
// Another File
object TestSharedObject {
@Volatile
var counter = 0
}
// Another File
import org.junit.Assert
import org.junit.Test
class Test1 {
@Test
fun t1() {
TestSharedObject.counter = 1
Thread.sleep(3000)
Assert.assertEquals(1, TestSharedObject.counter)
}
}
// Another File
import org.junit.Assert
import org.junit.Test
class Test2 {
@Test
fun t2() {
TestSharedObject.counter = 2
Thread.sleep(3000)
Assert.assertEquals(2, TestSharedObject.counter)
}
}
// Another File
import org.junit.Assert
import org.junit.Test
class Test3 {
@Test
fun t3() {
TestSharedObject.counter = 3
Thread.sleep(3000)
Assert.assertEquals(3, TestSharedObject.counter)
}
}
@Andrew0000
Copy link
Author

Andrew0000 commented Oct 15, 2024

image

p.s. don't look at 9 sec, it's 3 sec in total in reality

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment