gradle / test-retry-gradle-plugin

Gradle plugin to retry tests that have failed to mitigate test flakiness.
Apache License 2.0
220 stars 49 forks source link

Can't connect to a gradle worker #225

Closed igor-rubis closed 11 months ago

igor-rubis commented 11 months ago

I'm using the plugin for the first time, so might be missing something, but anyways. Related code in my build.gradle:

id 'org.gradle.test-retry' version '1.5.6'

dependencies {
    implementation(
            'org.testng:testng:7.5'
    )
}

tasks.register('testLocalAll', Test) {
       useTestNG {
        useDefaultListeners = false
        groupByInstances = true
        }
    include 'tests/package'    
    retry {
        maxRetries = 3
    }
}

I created a sample test using groovy:

@Test
class SampleTest {

    @Test
    void sampleTest() {
        print('run test')
        assert 1 == 0 // I expect it to fail and get retried for 3 times
    }
}

With --debug and --stacktrace after the test fails for the first time, I see the following output in the console:

2023-10-06T18:28:15.784+0100 [DEBUG] [TestEventLogger] Gradle Test Executor 1 FAILED
2023-10-06T18:28:15.800+0100 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Changing state to: SUCCEEDED
2023-10-06T18:28:15.800+0100 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Process 'Gradle Test Executor 1' finished with exit value 0 (state: SUCCEEDED)
2023-10-06T18:28:15.803+0100 [DEBUG] [org.gradle.internal.work.DefaultWorkerLeaseService] Worker lease root.1.91.209 completed (1 worker(s) in use)
2023-10-06T18:28:15.803+0100 [DEBUG] [org.gradle.internal.resources.AbstractTrackedResourceLock] Dispatch org.gradle.api.internal.tasks.testing.processors.RestartEveryNTestClassProcessor@1ee5cb77: released lock on root.1.91.209
2023-10-06T18:28:15.812+0100 [DEBUG] [org.gradle.internal.operations.DefaultBuildOperationRunner] Build operation 'Resolve files of :testRuntimeClasspath' completed
2023-10-06T18:28:15.834+0100 [INFO] [org.gradle.api.internal.file.collections.DirectoryFileTree] file or directory '~/project/build-gradle/classes/java/test', not found
2023-10-06T18:28:15.894+0100 [DEBUG] [org.gradle.internal.work.DefaultWorkerLeaseService] Worker lease root.1.91.212 started (1 worker(s) in use).
2023-10-06T18:28:15.894+0100 [DEBUG] [org.gradle.internal.resources.AbstractTrackedResourceLock] Dispatch org.gradle.api.internal.tasks.testing.processors.RestartEveryNTestClassProcessor@2a1c6905: acquired lock on root.1.91.212
2023-10-06T18:28:15.899+0100 [DEBUG] [org.gradle.internal.remote.internal.inet.TcpIncomingConnector] Listening on [70a12b24-55fd-410e-a781-deb8568f8229 port:53849, addresses:[localhost/127.0.0.1]].
2023-10-06T18:28:15.899+0100 [DEBUG] [org.gradle.process.internal.worker.DefaultWorkerProcessBuilder] Creating Gradle Test Executor 2
2023-10-06T18:28:15.900+0100 [DEBUG] [org.gradle.process.internal.worker.child.WorkerProcessClassPathProvider] Using worker process classpath: [~/.gradle/caches/6.8.3/workerMain/gradle-worker.jar]
2023-10-06T18:28:15.902+0100 [INFO] [org.gradle.process.internal.DefaultExecHandle] Starting process 'Gradle Test Executor 2'. Working directory: ~/project
2023-10-06T18:28:15.902+0100 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Changing state to: STARTING
2023-10-06T18:28:15.902+0100 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Waiting until process started: Gradle Test Executor 2.
2023-10-06T18:28:15.916+0100 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Changing state to: STARTED
2023-10-06T18:28:15.917+0100 [INFO] [org.gradle.process.internal.DefaultExecHandle] Successfully started process 'Gradle Test Executor 2'
2023-10-06T18:28:15.917+0100 [DEBUG] [org.gradle.process.internal.ExecHandleRunner] waiting until streams are handled...
2023-10-06T18:28:16.181+0100 [ERROR] [system.err] ERROR: transport error 202: connect failed: Connection refused
2023-10-06T18:28:16.181+0100 [ERROR] [system.err] ERROR: JDWP Transport dt_socket failed to initialize, TRANSPORT_INIT(510)
2023-10-06T18:28:16.181+0100 [ERROR] [system.err] JDWP exit error AGENT_ERROR_TRANSPORT_INIT(197): No transports initialized [debugInit.c:750]
2023-10-06T18:28:16.183+0100 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Changing state to: FAILED
2023-10-06T18:28:16.183+0100 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Process 'Gradle Test Executor 2' finished with exit value 2 (state: FAILED)
2023-10-06T18:28:16.184+0100 [DEBUG] [org.gradle.internal.work.DefaultWorkerLeaseService] Worker lease root.1.91.212 completed (1 worker(s) in use)
2023-10-06T18:28:16.184+0100 [DEBUG] [org.gradle.internal.resources.AbstractTrackedResourceLock] Dispatch org.gradle.api.internal.tasks.testing.processors.RestartEveryNTestClassProcessor@2a1c6905: released lock on root.1.91.212
2023-10-06T18:28:16.187+0100 [QUIET] [system.out] 
2023-10-06T18:28:16.187+0100 [DEBUG] [TestEventLogger] 
2023-10-06T18:28:16.187+0100 [DEBUG] [TestEventLogger] Gradle Test Run :testLocalAll FAILED

And as a result the test doesn't get retried.

marcphilipp commented 11 months ago

This looks like a general problem with Gradle that would happen even without the test retry plugin. You seem to be passing some kind of debug options to the JVM. Are you running this with --debug-jvm?

igor-rubis commented 11 months ago

With --debug and --stacktrace

igor-rubis commented 11 months ago

Well, as I said. For the first time it a test is executed like it should in Gradle Test Executor 1. But if I add the retry plugin, I see the following in the output:

2023-10-06T18:28:15.902+0100 [INFO] [org.gradle.process.internal.DefaultExecHandle] Starting process 'Gradle Test Executor 2'. Working directory: ~/project
2023-10-06T18:28:15.902+0100 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Changing state to: STARTING
2023-10-06T18:28:15.902+0100 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Waiting until process started: Gradle Test Executor 2.
2023-10-06T18:28:15.916+0100 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Changing state to: STARTED
2023-10-06T18:28:15.917+0100 [INFO] [org.gradle.process.internal.DefaultExecHandle] Successfully started process 'Gradle Test Executor 2'
2023-10-06T18:28:15.917+0100 [DEBUG] [org.gradle.process.internal.ExecHandleRunner] waiting until streams are handled...
2023-10-06T18:28:16.181+0100 [ERROR] [system.err] ERROR: transport error 202: connect failed: Connection refused
2023-10-06T18:28:16.181+0100 [ERROR] [system.err] ERROR: JDWP Transport dt_socket failed to initialize, TRANSPORT_INIT(510)
2023-10-06T18:28:16.181+0100 [ERROR] [system.err] JDWP exit error AGENT_ERROR_TRANSPORT_INIT(197): No transports initialized [debugInit.c:750]
2023-10-06T18:28:16.183+0100 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Changing state to: FAILED
2023-10-06T18:28:16.183+0100 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Process 'Gradle Test Executor 2' finished with exit value 2 (state: FAILED)
2023-10-06T18:28:16.184+0100 [DEBUG] [org.gradle.internal.work.DefaultWorkerLeaseService] Worker lease root.1.91.212 completed (1 worker(s) in use)
2023-10-06T18:28:16.184+0100 [DEBUG] [org.gradle.internal.resources.AbstractTrackedResourceLock] Dispatch org.gradle.api.internal.tasks.testing.processors.RestartEveryNTestClassProcessor@2a1c6905: released lock on root.1.91.212

This happens during the retry process.

marcphilipp commented 10 months ago

Are you passing any debug options as JVM args, like -agentlib:jdwp=...?

igor-rubis commented 10 months ago

You were right, it was an issue with Intelij running the task.