Is there a way to pass a unique system property to each test process when maxParallelForks is greater than 1?

I’m trying to parallelize some integration tests which each need to execute with a unique user id. These ids are managed by a remote system, so I need to configure my tests to pick one of the ids that is not currently being used by another test. When I set maxParallelForks = 8, is there some way I can pass in unique system property to each forked process that my tests can use to figure out which user to use? Even just the number of the process would suffice (ie, the “3” in “Successfully started process ‘Gradle Worker 3’”).

To my knowledge, Gradle doesn’t currently make such information available.

I went digging, and found what I was looking for in the org.gradle.api.internal.tasks.testing.worker.TestWorker class. It has a public static field, ‘WORKER_ID_SYS_PROPERTY’, which is the key for a system property that stores the id of the worker the current test is executing in. Rather than hard code a dependency on this system property in my test code, I got things working with a simple system property conversion:

task myTest(type: Test){
String workedIdProperty = org.gradle.api.internal.tasks.testing.worker.TestWorker.WORKER_ID_SYS_PROPERTY
systemProperty 'test.processIdProperty', workerIdProperty

Then, in my test code:

def processIdProperty = System.getProperty("test.processIdProperty")
def processId = processIdProperty ? System.getProperty(processIdProperty) : null

This seems to work exactly the way I want. I’m not certain if depending on that particular system property is a poor idea going forward, but it seems to work just fine right now.