Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve local test setup #177

Merged
merged 8 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ go.work

## kzg cache
resources/SRSTables/

## Vscode
/.vscode

## Idea
.idea
11 changes: 11 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
epociask marked this conversation as resolved.
Show resolved Hide resolved
"go.testEnvVars": {
"INTEGRATION": "true"
},
"go.testFlags": [
"-test.parallel",
"4",
"-deploy-config",
"../.devnet/devnetL1.json"
]
}
31 changes: 4 additions & 27 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ LDFLAGSSTRING +=-X main.Date=$(BUILD_TIME)
LDFLAGSSTRING +=-X main.Version=$(GIT_TAG)
LDFLAGS := -ldflags "$(LDFLAGSSTRING)"

E2ETEST = INTEGRATION=true go test -timeout 1m ./e2e -parallel 4 -deploy-config ../.devnet/devnetL1.json
HOLESKYTEST = TESTNET=true go test -timeout 50m ./e2e -parallel 4 -deploy-config ../.devnet/devnetL1.json

.PHONY: eigenda-proxy
eigenda-proxy:
env GO111MODULE=on GOOS=$(TARGETOS) GOARCH=$(TARGETARCH) go build -v $(LDFLAGS) -o ./bin/eigenda-proxy ./cmd/server
Expand All @@ -23,22 +20,6 @@ docker-build:
# we only use this to build the docker image locally, so we give it the dev tag as a reminder
@docker build -t ghcr.io/layr-labs/eigenda-proxy:dev .

run-minio:
docker run -p 4566:9000 -d -e "MINIO_ROOT_USER=minioadmin" -e "MINIO_ROOT_PASSWORD=minioadmin" --name minio minio/minio server /data

run-redis:
docker run -p 9001:6379 -d --name redis redis

stop-minio:
@if [ -n "$$(docker ps -q -f name=minio)" ]; then \
docker stop minio && docker rm minio; \
fi

stop-redis:
@if [ -n "$$(docker ps -q -f name=redis)" ]; then \
docker stop redis && docker rm redis; \
fi

run-memstore-server:
./bin/eigenda-proxy --memstore.enabled

Expand All @@ -51,15 +32,11 @@ clean:
test:
go test ./... -parallel 4

e2e-test: stop-minio stop-redis run-minio run-redis
samlaf marked this conversation as resolved.
Show resolved Hide resolved
$(E2ETEST) && \
make stop-minio && \
make stop-redis
e2e-test:
INTEGRATION=true go test -timeout 1m ./e2e -parallel 4 -deploy-config ../.devnet/devnetL1.json

holesky-test: stop-minio stop-redis run-minio run-redis
$(HOLESKYTEST) && \
make stop-minio && \
make stop-redis
holesky-test:
TESTNET=true go test -timeout 50m ./e2e -parallel 4 -deploy-config ../.devnet/devnetL1.json

.PHONY: lint
lint:
Expand Down
5 changes: 5 additions & 0 deletions e2e/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import (
"testing"
)

// Integration tests are run against memstore whereas.
// Testnetintegration tests are run against eigenda backend talking to testnet disperser.
// Some of the assertions in the tests are different based on the backend as well.
// e.g, in TestProxyServerCaching we only assert to read metrics with EigenDA
// when referencing memstore since we don't profile the eigenDAClient interactions
var (
runTestnetIntegrationTests bool
runIntegrationTests bool
Expand Down
69 changes: 66 additions & 3 deletions e2e/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"
"runtime"
"strings"
"testing"
"time"

Expand All @@ -26,6 +27,8 @@ import (
opmetrics "github.com/ethereum-optimism/optimism/op-service/metrics"

"github.com/stretchr/testify/require"
miniotc "github.com/testcontainers/testcontainers-go/modules/minio"
redistc "github.com/testcontainers/testcontainers-go/modules/redis"
samlaf marked this conversation as resolved.
Show resolved Hide resolved
)

const (
Expand All @@ -37,6 +40,66 @@ const (
holeskyDA = "disperser-holesky.eigenda.xyz:443"
)

var (
// set by startMinioContainer
minioEndpoint = ""
// set by startRedisContainer
redisEndpoint = ""
)

func init() {
err := startMinioContainer()
if err != nil {
panic(err)
}
err = startRedisContainer()
if err != nil {
panic(err)
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

knit - using an init pattern like this could make our code super hard to import - at least this library

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree that this sucks... also it could at some point be needed to have new clean instances per test. wanted to talk with you about how to best refactor this.

I didn't see an obvious place where to start these containers. The separation between creating the config (one fct that sets all the config vars) and starting the endpoints makes it hard... because the actual endpoint of the containers are only known after they are started, so we'd need to start them in the "createConfig" function, which feels wrong... perhaps we need yet another function like startDependencyContainers() or something? And we can call it from the test main function?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On another note though I'm not sure why anyone would want to import this package... do you have anything in mind or just saying in case?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just saying as an in-case - maybe one day we try importing this into node software directly for cross testing framework integration

Copy link
Collaborator Author

@samlaf samlaf Oct 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with you, but want to move on to other things for now and worry about this when it actually becomes a problem (perhaps an obvious refactor will also surface once we have an actual need for this). Added a TODO comment: a9ae57b


// startMinioContainer starts a MinIO container and returns the container instance and its endpoint
func startMinioContainer() error {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

knit - startMinIOContainer

Copy link
Collaborator Author

@samlaf samlaf Oct 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

minioContainer, err := miniotc.Run(ctx,
"minio/minio:RELEASE.2024-10-02T17-50-41Z",
miniotc.WithUsername("minioadmin"),
miniotc.WithPassword("minioadmin"),
)
if err != nil {
return fmt.Errorf("failed to start MinIO container: %w", err)
}

endpoint, err := minioContainer.Endpoint(ctx, "")
if err != nil {
return fmt.Errorf("failed to get MinIO endpoint: %w", err)
}

minioEndpoint = strings.TrimPrefix(endpoint, "http://")
return nil
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

knit - we document the above function but not this one

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

func startRedisContainer() error {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

redisContainer, err := redistc.Run(ctx,
"docker.io/redis:7",
)
if err != nil {
return fmt.Errorf("failed to start Redis container: %w", err)
}

endpoint, err := redisContainer.Endpoint(ctx, "")
if err != nil {
return fmt.Errorf("failed to get Redis endpoint: %w", err)
}
redisEndpoint = endpoint
return nil
}

type Cfg struct {
UseMemory bool
Expiration time.Duration
Expand All @@ -60,7 +123,7 @@ func TestConfig(useMemory bool) *Cfg {

func createRedisConfig(eigendaCfg server.Config) server.CLIConfig {
eigendaCfg.RedisConfig = redis.Config{
Endpoint: "127.0.0.1:9001",
Endpoint: redisEndpoint,
Password: "",
DB: 0,
Eviction: 10 * time.Minute,
Expand All @@ -80,7 +143,7 @@ func createS3Config(eigendaCfg server.Config) server.CLIConfig {
Profiling: true,
Bucket: bucketName,
Path: "",
Endpoint: "localhost:4566",
Endpoint: minioEndpoint,
EnableTLS: false,
AccessKeySecret: "minioadmin",
AccessKeyID: "minioadmin",
Expand Down Expand Up @@ -222,7 +285,7 @@ func (ts *TestSuite) Address() string {

func createS3Bucket(bucketName string) {
// Initialize minio client object.
endpoint := "localhost:4566"
endpoint := minioEndpoint
accessKeyID := "minioadmin"
secretAccessKey := "minioadmin"
useSSL := false
Expand Down
41 changes: 37 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ require (
github.com/minio/minio-go/v7 v7.0.76
github.com/prometheus/client_golang v1.20.2
github.com/stretchr/testify v1.9.0
github.com/testcontainers/testcontainers-go/modules/minio v0.33.0
github.com/testcontainers/testcontainers-go/modules/redis v0.33.0
github.com/urfave/cli/v2 v2.27.4
golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa
)

require (
dario.cat/mergo v1.0.0 // indirect
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/BurntSushi/toml v1.4.0 // indirect
github.com/DataDog/zstd v1.5.6-0.20230824185856-869dae002e5e // indirect
github.com/Layr-Labs/eigensdk-go v0.1.7-0.20240507215523-7e4891d5099a // indirect
Expand Down Expand Up @@ -49,6 +53,7 @@ require (
github.com/btcsuite/btcd/btcutil v1.1.5 // indirect
github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0 // indirect
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cockroachdb/errors v1.11.3 // indirect
github.com/cockroachdb/fifo v0.0.0-20240606204812-0bbfbd93a7ce // indirect
Expand All @@ -58,7 +63,11 @@ require (
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
github.com/consensys/bavard v0.1.13 // indirect
github.com/containerd/cgroups v1.1.0 // indirect
github.com/containerd/containerd v1.7.18 // indirect
github.com/containerd/log v0.1.0 // indirect
github.com/containerd/platforms v0.2.1 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/cpuguy83/dockercfg v0.3.1 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
github.com/crate-crypto/go-ipa v0.0.0-20240223125850-b1e8a79f509c // indirect
github.com/crate-crypto/go-kzg-4844 v1.0.0 // indirect
Expand All @@ -69,7 +78,10 @@ require (
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
github.com/deepmap/oapi-codegen v1.8.2 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/distribution/reference v0.6.0 // indirect
github.com/dlclark/regexp2 v1.7.0 // indirect
github.com/docker/docker v27.1.1+incompatible // indirect
github.com/docker/go-connections v0.5.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/dop251/goja v0.0.0-20230806174421-c933cf95e127 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
Expand All @@ -79,6 +91,7 @@ require (
github.com/ethereum/c-kzg-4844 v1.0.0 // indirect
github.com/ethereum/go-verkle v0.1.1-0.20240306133620-7d920df305f0 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/ferranbt/fastssz v0.1.2 // indirect
github.com/flynn/noise v1.1.0 // indirect
github.com/francoispqt/gojay v1.2.13 // indirect
Expand All @@ -89,6 +102,8 @@ require (
github.com/gballet/go-libpcsclite v0.0.0-20191108122812-4678299bea08 // indirect
github.com/getsentry/sentry-go v0.27.0 // indirect
github.com/go-ini/ini v1.67.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/go-sourcemap/sourcemap v2.1.3+incompatible // indirect
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
Expand All @@ -98,7 +113,6 @@ require (
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/gopacket v1.1.19 // indirect
Expand Down Expand Up @@ -151,6 +165,8 @@ require (
github.com/libp2p/go-reuseport v0.4.0 // indirect
github.com/libp2p/go-yamux/v4 v4.0.1 // indirect
github.com/lmittmann/tint v1.0.4 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
Expand All @@ -163,6 +179,12 @@ require (
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mitchellh/pointerstructure v1.2.1 // indirect
github.com/mmcloughlin/addchain v0.4.0 // indirect
github.com/moby/docker-image-spec v1.3.1 // indirect
github.com/moby/patternmatcher v0.6.0 // indirect
github.com/moby/sys/sequential v0.5.0 // indirect
github.com/moby/sys/user v0.1.0 // indirect
github.com/moby/term v0.5.0 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/mr-tron/base58 v1.2.0 // indirect
github.com/multiformats/go-base32 v0.1.0 // indirect
github.com/multiformats/go-base36 v0.2.0 // indirect
Expand All @@ -178,6 +200,8 @@ require (
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/onsi/ginkgo/v2 v2.20.0 // indirect
github.com/onsi/gomega v1.34.1 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0 // indirect
github.com/opencontainers/runtime-spec v1.2.0 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect
Expand All @@ -201,6 +225,7 @@ require (
github.com/pion/webrtc/v3 v3.3.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
Expand All @@ -215,12 +240,16 @@ require (
github.com/rs/xid v1.6.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/shirou/gopsutil v3.21.11+incompatible // indirect
github.com/shirou/gopsutil/v3 v3.23.12 // indirect
github.com/shoenig/go-m1cpu v0.1.6 // indirect
github.com/shurcooL/graphql v0.0.0-20230722043721-ed46e5a46466 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/status-im/keycard-go v0.2.0 // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/supranational/blst v0.3.11 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20220614013038-64ee5596c38a // indirect
github.com/testcontainers/testcontainers-go v0.33.0 // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
github.com/tyler-smith/go-bip39 v1.1.0 // indirect
Expand All @@ -230,7 +259,11 @@ require (
github.com/x448/float16 v0.8.4 // indirect
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
github.com/yusufpapurcu/wmi v1.2.3 // indirect
go.etcd.io/bbolt v1.3.5 // indirect
go.etcd.io/bbolt v1.3.7 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
go.uber.org/dig v1.18.0 // indirect
go.uber.org/fx v1.22.2 // indirect
go.uber.org/mock v0.4.0 // indirect
Expand All @@ -245,8 +278,8 @@ require (
golang.org/x/text v0.17.0 // indirect
golang.org/x/time v0.6.0 // indirect
golang.org/x/tools v0.24.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b // indirect
google.golang.org/grpc v1.59.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 // indirect
google.golang.org/grpc v1.64.1 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
Loading
Loading