gesellix / gradle-docker-plugin

Gradle Docker plugin
MIT License
79 stars 17 forks source link

Build fails when using junixsocket 2.1.2 #75

Closed gesellix closed 5 years ago

gesellix commented 5 years ago

The build fails with this exception: https://github.com/kohlschutter/junixsocket/blob/6b88c5f8aa65b9f0f77b6e4880c521ee09a176f5/junixsocket-common/src/main/java/org/newsclub/net/unix/AFUNIXSocket.java#L54

Stacktrace:

Caused by: java.io.IOException: Couldn't load native library
    at org.newsclub.net.unix.AFUNIXSocket.setIsCreated(AFUNIXSocket.java:50)
    at org.newsclub.net.unix.AFUNIXSocket.<init>(AFUNIXSocket.java:42)
    at org.newsclub.net.unix.AFUNIXSocket.newInstance(AFUNIXSocket.java:71)
    at org.newsclub.net.unix.AFUNIXSocket.newInstance(AFUNIXSocket.java:66)
    at de.gesellix.docker.client.filesocket.UnixSocket.connect(UnixSocket.java:36)
gesellix commented 5 years ago

It seems like the way the integrative tests are performed makes triggers the issue.

  1. Tests are filtered/activated using @Requires({ LocalDocker.available() })
  2. The actual test run is performed via GradleRunner in another thread

Both 1. and 2. check AFUNIXSocket.isSupported(), which internally tries new NativeLibraryLoader().loadLibrary().

gesellix commented 5 years ago

This one works without issues:

package de.gesellix.gradle.docker

import de.gesellix.docker.client.DockerClientImpl
import spock.lang.Requires
import spock.lang.Specification

import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit
import java.util.concurrent.atomic.AtomicInteger

@Requires({ LocalDocker.available() })
class TestJunixsocket extends Specification {

    def "perform simple test"() {
        expect:
        200 == new DockerClientImpl().ping().status.code
    }

    def "perform async test"() {
        given:
        def result = new AtomicInteger()
        def latch = new CountDownLatch(1)

        when:
        Thread.start {
            def code = new DockerClientImpl().ping().status.code
            result.set(code)
            latch.countDown()
        }
        while (!latch.await(5, TimeUnit.SECONDS)) {
            Thread.sleep(500)
        }

        then:
        result.get() == 200
    }
}
gesellix commented 5 years ago

--> does using the GradleRunner break anything?

gesellix commented 5 years ago

See https://github.com/gesellix/gradle-testkit-junixsocket-issue for a reproducible test and https://github.com/kohlschutter/junixsocket/issues/60 for a discussion

junixsocket 2.2.0 fixes the issue