diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index e38ea686..7a12e784 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -32,6 +32,10 @@ jobs: - kafkaclient - testhelper steps: + - name: Disable IPv6 + run: | + sudo sysctl -w net.ipv6.conf.all.disable_ipv6=1 + sudo sysctl -w net.ipv6.conf.default.disable_ipv6=1 - uses: actions/checkout@v4 - uses: actions/setup-go@v5 with: diff --git a/testhelper/docker/resource/scylla/config.go b/testhelper/docker/resource/scylla/config.go index 1e9834d6..ba6fb4ed 100644 --- a/testhelper/docker/resource/scylla/config.go +++ b/testhelper/docker/resource/scylla/config.go @@ -1,5 +1,7 @@ package scylla +import "github.com/ory/dockertest/v3/docker" + type Option func(*config) func WithTag(tag string) Option { @@ -14,7 +16,14 @@ func WithKeyspace(keyspace string) Option { } } +func WithDockerNetwork(network *docker.Network) Option { + return func(c *config) { + c.network = network + } +} + type config struct { tag string keyspace string + network *docker.Network } diff --git a/testhelper/docker/resource/scylla/scylla.go b/testhelper/docker/resource/scylla/scylla.go index 3023558c..329cf3a4 100644 --- a/testhelper/docker/resource/scylla/scylla.go +++ b/testhelper/docker/resource/scylla/scylla.go @@ -3,6 +3,7 @@ package scylla import ( "bytes" "fmt" + "time" "github.com/gocql/gocql" "github.com/ory/dockertest/v3" @@ -11,6 +12,7 @@ import ( "github.com/rudderlabs/rudder-go-kit/bytesize" "github.com/rudderlabs/rudder-go-kit/testhelper/docker/resource" "github.com/rudderlabs/rudder-go-kit/testhelper/docker/resource/internal" + "github.com/rudderlabs/rudder-go-kit/testhelper/rand" ) type Resource struct { @@ -19,20 +21,34 @@ type Resource struct { } func Setup(pool *dockertest.Pool, d resource.Cleaner, opts ...Option) (*Resource, error) { - c := &config{ - tag: "5.4.9", - } + c := &config{tag: "6.1"} for _, opt := range opts { opt(c) } + if c.network == nil { + var err error + c.network, err = pool.Client.CreateNetwork(docker.CreateNetworkOptions{ + Name: "scylla_network_test_" + time.Now().Format("YY-MM-DD-") + rand.UniqueString(6), + EnableIPv6: false, + }) + if err != nil { + return nil, err + } + d.Cleanup(func() { + if err := pool.Client.RemoveNetwork(c.network.ID); err != nil { + d.Logf("Error while removing Docker network: %v", err) + } + }) + } + container, err := pool.RunWithOptions(&dockertest.RunOptions{ Repository: "scylladb/scylla", Tag: c.tag, - Env: []string{}, ExposedPorts: []string{"9042/tcp"}, PortBindings: internal.IPv4PortBindings([]string{"9042"}), Cmd: []string{"--smp 1"}, + NetworkID: c.network.ID, }, internal.DefaultHostConfig, func(hc *docker.HostConfig) { hc.CPUCount = 1 hc.Memory = 128 * bytesize.MB @@ -96,7 +112,10 @@ func Setup(pool *dockertest.Pool, d resource.Cleaner, opts ...Option) (*Resource return nil, err } defer session.Close() - err = session.Query(fmt.Sprintf("CREATE KEYSPACE IF NOT EXISTS %s WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };", c.keyspace)).Exec() + err = session.Query(fmt.Sprintf( + "CREATE KEYSPACE IF NOT EXISTS %s WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };", + c.keyspace, + )).Exec() if err != nil { return nil, err }