Skip to content

Commit

Permalink
fix SetupYugabyte
Browse files Browse the repository at this point in the history
  • Loading branch information
nonsense committed May 8, 2023
1 parent de1c639 commit 97826ec
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 55 deletions.
1 change: 1 addition & 0 deletions extern/boostd-data/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ services:
image: public.ecr.aws/n6b0k8i7/yugabyte-test:x86_64-2.17.2.0
ports:
- 9042:9042
- 5432:5432
restart: on-failure

go-tests:
Expand Down
98 changes: 46 additions & 52 deletions extern/boostd-data/svc/setup_yugabyte_test_util.go
Original file line number Diff line number Diff line change
@@ -1,78 +1,72 @@
package svc

import (
"github.com/davecgh/go-spew/spew"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
dockercl "github.com/docker/docker/client"
"github.com/docker/go-connections/nat"
"testing"
"time"

"github.com/filecoin-project/boostd-data/yugabyte"
"github.com/stretchr/testify/require"
"github.com/yugabyte/gocql"
"golang.org/x/net/context"
"io"
"os"
"testing"
"time"
)

func SetupYugabyte(t *testing.T) {
ctx := context.Background()
cli, err := dockercl.NewClientWithOpts(dockercl.FromEnv)
require.NoError(t, err)
//cli, err := dockercl.NewClientWithOpts(dockercl.FromEnv)
//require.NoError(t, err)

imageName := "public.ecr.aws/n6b0k8i7/yugabyte-test:x86_64-2.17.2.0"
out, err := cli.ImagePull(ctx, imageName, types.ImagePullOptions{})
require.NoError(t, err)
//imageName := "public.ecr.aws/n6b0k8i7/yugabyte-test:x86_64-2.17.2.0"
//out, err := cli.ImagePull(ctx, imageName, types.ImagePullOptions{})
//require.NoError(t, err)

_, err = io.Copy(os.Stdout, out)
require.NoError(t, err)
//_, err = io.Copy(os.Stdout, out)
//require.NoError(t, err)

tlog.Info("yugabyte docker container create...")
resp, err := cli.ContainerCreate(ctx, &container.Config{
Image: imageName,
ExposedPorts: nat.PortSet{
"7000": struct{}{},
"9000": struct{}{},
"5433": struct{}{},
"9042": struct{}{},
},
}, &container.HostConfig{
PortBindings: map[nat.Port][]nat.PortBinding{
"7000": {{HostIP: "127.0.0.1", HostPort: "7001"}},
"9000": {{HostIP: "127.0.0.1", HostPort: "9000"}},
"5433": {{HostIP: "127.0.0.1", HostPort: "5433"}},
"9042": {{HostIP: "127.0.0.1", HostPort: "9042"}},
},
}, nil, nil, "")
require.NoError(t, err)
tlog.Info("yugabyte docker container created")
//tlog.Info("yugabyte docker container create...")
//resp, err := cli.ContainerCreate(ctx, &container.Config{
//Image: imageName,
//ExposedPorts: nat.PortSet{
//"7000": struct{}{},
//"9000": struct{}{},
//"5433": struct{}{},
//"9042": struct{}{},
//},
//}, &container.HostConfig{
//PortBindings: map[nat.Port][]nat.PortBinding{
//"7000": {{HostIP: "127.0.0.1", HostPort: "7001"}},
//"9000": {{HostIP: "127.0.0.1", HostPort: "9000"}},
//"5433": {{HostIP: "127.0.0.1", HostPort: "5433"}},
//"9042": {{HostIP: "127.0.0.1", HostPort: "9042"}},
//},
//}, nil, nil, "")
//require.NoError(t, err)
//tlog.Info("yugabyte docker container created")

tlog.Info("yugabyte docker container start...")
err = cli.ContainerStart(ctx, resp.ID, types.ContainerStartOptions{})
require.NoError(t, err)
tlog.Info("yugabyte docker container started")
//tlog.Info("yugabyte docker container start...")
//err = cli.ContainerStart(ctx, resp.ID, types.ContainerStartOptions{})
//require.NoError(t, err)
//tlog.Info("yugabyte docker container started")

inspect, err := cli.ContainerInspect(ctx, resp.ID)
require.NoError(t, err)
spew.Dump(inspect)
//inspect, err := cli.ContainerInspect(ctx, resp.ID)
//require.NoError(t, err)
//spew.Dump(inspect)

t.Cleanup(func() {
tlog.Info("yugabyte docker container remove...")
err := cli.ContainerRemove(ctx, resp.ID, types.ContainerRemoveOptions{Force: true})
require.NoError(t, err)
tlog.Info("yugabyte docker container removed")
})
//t.Cleanup(func() {
//tlog.Info("yugabyte docker container remove...")
//err := cli.ContainerRemove(ctx, resp.ID, types.ContainerRemoveOptions{Force: true})
//require.NoError(t, err)
//tlog.Info("yugabyte docker container removed")
//})

tlog.Info("wait for yugabyte start...")
awaitYugabyteUp(t, time.Minute)
tlog.Info("yugabyte started")

store := yugabyte.NewStore(yugabyte.DBSettings{
Hosts: []string{"127.0.0.1"},
ConnectString: "postgresql://postgres:postgres@localhost",
Hosts: []string{"yugabyte"},
ConnectString: "postgresql://postgres:postgres@yugabyte",
})
err = store.Start(ctx)
err := store.Start(ctx)
require.NoError(t, err)

RecreateTables(ctx, t, store)
Expand All @@ -87,7 +81,7 @@ func RecreateTables(ctx context.Context, t *testing.T, store *yugabyte.Store) {

func awaitYugabyteUp(t *testing.T, duration time.Duration) {
start := time.Now()
cluster := gocql.NewCluster("127.0.0.1")
cluster := gocql.NewCluster("yugabyte")
for {
session, err := cluster.CreateSession()
if err == nil {
Expand Down
6 changes: 3 additions & 3 deletions extern/boostd-data/svc/svc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func TestService(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
defer cancel()

// SetupYugabyte(t)
SetupYugabyte(t)

bdsvc := NewYugabyte(testYugaSettings)

Expand Down Expand Up @@ -226,7 +226,7 @@ func TestServiceFuzz(t *testing.T) {
})

t.Run("yugabyte", func(t *testing.T) {
// SetupYugabyte(t)
SetupYugabyte(t)
bdsvc := NewYugabyte(testYugaSettings)

addr := "localhost:8044"
Expand Down Expand Up @@ -460,7 +460,7 @@ func TestCleanup(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
defer cancel()

// SetupYugabyte(t)
SetupYugabyte(t)

bdsvc := NewYugabyte(testYugaSettings)
testCleanup(ctx, t, bdsvc, "localhost:8044")
Expand Down

0 comments on commit 97826ec

Please sign in to comment.