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

Efficient-unit-tests #50

Merged
merged 10 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from 9 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
6 changes: 6 additions & 0 deletions .github/actions/test-coverage/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ runs:
with:
go-version: ${{inputs.go-version}}

- name: Download coverage artifact
uses: actions/download-artifact@v2
with:
name: coverage
path: .

- name: Generate coverage report
shell: bash
env:
Expand Down
8 changes: 5 additions & 3 deletions .github/actions/test-coverage/coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@ set -euo pipefail
SCRIPT_DIR="$(dirname -- "$(readlink -f "${BASH_SOURCE[0]}")")"

OUT_DIR="${1-$SCRIPT_DIR}"
OUT_FILE="$(mktemp)"

# Get coverage for all packages in the current directory; store next to script.
go test -short ./... -coverprofile "$OUT_FILE"
# OUT_FILE="$(mktemp)"
# # Get coverage for all packages in the current directory; store next to script.
# go test -short ./... -coverprofile "$OUT_FILE"

OUT_FILE="coverage.out"

if [[ "${INPUT_REPORT-true}" == "true" ]]; then
# Create an HTML report; store next to script.
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/test-coverage.yml
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this still needed if we report coverage right in the unit-tests flow?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, I can remove.

Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: test-coverage

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
workflow_dispatch:
# push:
# branches: [ master ]
# pull_request:
# branches: [ master ]
# workflow_dispatch:

jobs:

Expand Down
21 changes: 20 additions & 1 deletion .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,23 @@ jobs:
run: make build

- name: Test all
run: go test -coverprofile=coverage.out -short ./...
run: ./test.sh -coverprofile=coverage.out

- name: Upload coverage artifact
uses: actions/upload-artifact@v2
with:
name: coverage
path: coverage.out

coverage-report:
name: Coverage Report
needs: unit-tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Update coverage badge
uses: ./.github/actions/test-coverage
with:
chart: true
amend: true
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: compile-el compile-dl clean protoc lint
.PHONY: compile-el compile-dl clean protoc lint build unit-tests integration-tests-churner integration-tests-indexer integration-tests-inabox integration-tests-inabox-nochurner integration-tests-graph-indexer

PROTOS := ./api/proto
PROTOS_DISPERSER := ./disperser/proto
Expand Down Expand Up @@ -45,7 +45,7 @@ build:
cd tools/traffic && make build

unit-tests:
go clean -testcache && go test -short ./... -p 2 -race
./test.sh

integration-tests-churner:
go test -v ./churner/tests
Expand Down
27 changes: 19 additions & 8 deletions common/aws/dynamodb/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ var (
dockertestResource *dockertest.Resource
dynamoClient *commondynamodb.Client
clientConfig commonaws.ClientConfig

deployLocalStack bool
localStackPort = "4567"
)

func TestMain(m *testing.M) {
Expand All @@ -33,13 +36,19 @@ func TestMain(m *testing.M) {
}

func setup(m *testing.M) {
localStackPort := "4567"
pool, resource, err := deploy.StartDockertestWithLocalstackContainer(localStackPort)
dockertestPool = pool
dockertestResource = resource
if err != nil {
teardown()
panic("failed to start localstack container")

deployLocalStack = !(os.Getenv("DEPLOY_LOCALSTACK") == "false")
if !deployLocalStack {
localStackPort = os.Getenv("LOCALSTACK_PORT")
}

if deployLocalStack {
var err error
dockertestPool, dockertestResource, err = deploy.StartDockertestWithLocalstackContainer(localStackPort)
if err != nil {
teardown()
panic("failed to start localstack container")
}
}

logger, err := logging.GetLogger(logging.DefaultCLIConfig())
Expand All @@ -62,7 +71,9 @@ func setup(m *testing.M) {
}

func teardown() {
deploy.PurgeDockertestResources(dockertestPool, dockertestResource)
if deployLocalStack {
deploy.PurgeDockertestResources(dockertestPool, dockertestResource)
}
}

func createTable(t *testing.T, tableName string) {
Expand Down
37 changes: 24 additions & 13 deletions common/store/dynamo_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ var (

dockertestPool *dockertest.Pool
dockertestResource *dockertest.Resource
localStackPort string

deployLocalStack bool
localStackPort = "4566"

dynamoClient *dynamodb.Client
dynamoParamStore common.KVStore[common.RateBucketParams]
Expand All @@ -38,13 +40,19 @@ func TestMain(m *testing.M) {
}

func setup(m *testing.M) {
localStackPort = "4569"
pool, resource, err := deploy.StartDockertestWithLocalstackContainer(localStackPort)
dockertestPool = pool
dockertestResource = resource
if err != nil {
teardown()
panic("failed to start localstack container")

deployLocalStack = !(os.Getenv("DEPLOY_LOCALSTACK") == "false")
if !deployLocalStack {
localStackPort = os.Getenv("LOCALSTACK_PORT")
}

if deployLocalStack {
var err error
dockertestPool, dockertestResource, err = deploy.StartDockertestWithLocalstackContainer(localStackPort)
if err != nil {
teardown()
panic("failed to start localstack container")
}
}

cfg := aws.ClientConfig{
Expand All @@ -53,23 +61,26 @@ func setup(m *testing.M) {
SecretAccessKey: "localstack",
EndpointURL: fmt.Sprintf("http://0.0.0.0:%s", localStackPort),
}
dynamoClient, err = dynamodb.NewClient(cfg, logger)

_, err := test_utils.CreateTable(context.Background(), cfg, bucketTableName, store.GenerateTableSchema(10, 10, bucketTableName))
if err != nil {
teardown()
panic("failed to create dynamodb client: " + err.Error())
panic("failed to create dynamodb table: " + err.Error())
}

_, err = test_utils.CreateTable(context.Background(), cfg, bucketTableName, store.GenerateTableSchema(10, 10, bucketTableName))
dynamoClient, err = dynamodb.NewClient(cfg, logger)
if err != nil {
teardown()
panic("failed to create dynamodb table: " + err.Error())
panic("failed to create dynamodb client: " + err.Error())
}

dynamoParamStore = store.NewDynamoParamStore[common.RateBucketParams](dynamoClient, bucketTableName)
}

func teardown() {
deploy.PurgeDockertestResources(dockertestPool, dockertestResource)
if deployLocalStack {
deploy.PurgeDockertestResources(dockertestPool, dockertestResource)
}
}

func TestDynamoBucketStore(t *testing.T) {
Expand Down
38 changes: 26 additions & 12 deletions disperser/apiserver/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/Layr-Labs/eigenda/disperser/apiserver"
"github.com/Layr-Labs/eigenda/disperser/blobstore"
gethcommon "github.com/ethereum/go-ethereum/common"
"github.com/google/uuid"

pb "github.com/Layr-Labs/eigenda/api/grpc/disperser"
"github.com/Layr-Labs/eigenda/common"
Expand All @@ -36,9 +37,12 @@ var (
dispersalServer *apiserver.DispersalServer
dockertestPool *dockertest.Pool
dockertestResource *dockertest.Resource
localStackPort string
metadataTableName = "test-BlobMetadata"
bucketTableName = "test-BucketStore"
UUID = uuid.New()
metadataTableName = fmt.Sprintf("test-BlobMetadata-%v", UUID)
bucketTableName = fmt.Sprintf("test-BucketStore-%v", UUID)

deployLocalStack bool
localStackPort = "4568"
)

func TestMain(m *testing.M) {
Expand Down Expand Up @@ -276,16 +280,24 @@ func TestDisperseBlobWithExceedSizeLimit(t *testing.T) {
}

func setup(m *testing.M) {
localStackPort = "4568"
pool, resource, err := deploy.StartDockertestWithLocalstackContainer(localStackPort)
dockertestPool = pool
dockertestResource = resource
if err != nil {
teardown()
panic("failed to start localstack container")

deployLocalStack = !(os.Getenv("DEPLOY_LOCALSTACK") == "false")
if !deployLocalStack {
localStackPort = os.Getenv("LOCALSTACK_PORT")
}

if deployLocalStack {

var err error
dockertestPool, dockertestResource, err = deploy.StartDockertestWithLocalstackContainer(localStackPort)
if err != nil {
teardown()
panic("failed to start localstack container")
}

}

err = deploy.DeployResources(pool, localStackPort, metadataTableName, bucketTableName)
err := deploy.DeployResources(dockertestPool, localStackPort, metadataTableName, bucketTableName)
if err != nil {
teardown()
panic("failed to deploy AWS resources")
Expand All @@ -295,7 +307,9 @@ func setup(m *testing.M) {
}

func teardown() {
deploy.PurgeDockertestResources(dockertestPool, dockertestResource)
if deployLocalStack {
deploy.PurgeDockertestResources(dockertestPool, dockertestResource)
}
}

func newTestServer(m *testing.M) *apiserver.DispersalServer {
Expand Down
43 changes: 29 additions & 14 deletions disperser/blobstore/blobstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/Layr-Labs/eigenda/common/aws"
"github.com/Layr-Labs/eigenda/common/aws/dynamodb"
test_utils "github.com/Layr-Labs/eigenda/common/aws/dynamodb/utils"
"github.com/google/uuid"

cmock "github.com/Layr-Labs/eigenda/common/mock"
"github.com/Layr-Labs/eigenda/core"
Expand Down Expand Up @@ -39,12 +40,16 @@ var (

dockertestPool *dockertest.Pool
dockertestResource *dockertest.Resource
localStackPort string

deployLocalStack bool
localStackPort = "4569"

dynamoClient *dynamodb.Client
blobMetadataStore *blobstore.BlobMetadataStore
metadataTableName = "test-BlobMetadata"
sharedStorage *blobstore.SharedBlobStore

UUID = uuid.New()
metadataTableName = fmt.Sprintf("test-BlobMetadata-%v", UUID)
)

func TestMain(m *testing.M) {
Expand All @@ -55,13 +60,20 @@ func TestMain(m *testing.M) {
}

func setup(m *testing.M) {
localStackPort = "4569"
pool, resource, err := deploy.StartDockertestWithLocalstackContainer(localStackPort)
dockertestPool = pool
dockertestResource = resource
if err != nil {
teardown()
panic("failed to start localstack container")

deployLocalStack = !(os.Getenv("DEPLOY_LOCALSTACK") == "false")
if !deployLocalStack {
localStackPort = os.Getenv("LOCALSTACK_PORT")
}

if deployLocalStack {
var err error
dockertestPool, dockertestResource, err = deploy.StartDockertestWithLocalstackContainer(localStackPort)
if err != nil {
teardown()
panic("failed to start localstack container")
}

}

cfg := aws.ClientConfig{
Expand All @@ -70,22 +82,25 @@ func setup(m *testing.M) {
SecretAccessKey: "localstack",
EndpointURL: fmt.Sprintf("http://0.0.0.0:%s", localStackPort),
}
dynamoClient, err = dynamodb.NewClient(cfg, logger)

_, err := test_utils.CreateTable(context.Background(), cfg, metadataTableName, blobstore.GenerateTableSchema(metadataTableName, 10, 10))
if err != nil {
teardown()
panic("failed to create dynamodb client: " + err.Error())
panic("failed to create dynamodb table: " + err.Error())
}

_, err = test_utils.CreateTable(context.Background(), cfg, metadataTableName, blobstore.GenerateTableSchema(metadataTableName, 10, 10))
dynamoClient, err = dynamodb.NewClient(cfg, logger)
if err != nil {
teardown()
panic("failed to create dynamodb table: " + err.Error())
panic("failed to create dynamodb client: " + err.Error())
}

blobMetadataStore = blobstore.NewBlobMetadataStore(dynamoClient, logger, metadataTableName, time.Hour)
sharedStorage = blobstore.NewSharedStorage(bucketName, s3Client, blobMetadataStore, logger)
}

func teardown() {
deploy.PurgeDockertestResources(dockertestPool, dockertestResource)
if deployLocalStack {
deploy.PurgeDockertestResources(dockertestPool, dockertestResource)
}
}
12 changes: 6 additions & 6 deletions inabox/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ stop-geth:
cd geth && docker compose down


.PHONY: new-anvil new-docker-anvil infra resources exp deploy-all stop-infra run-e2e run-e2e-nochurner run-e2e-nograph clean
.PHONY: new-anvil new-docker-anvil chain localstack exp deploy-all stop-infra run-e2e run-e2e-nochurner run-e2e-nograph clean

new-anvil:
mkdir -p "testdata/$(dt)"
Expand All @@ -23,11 +23,11 @@ new-docker-anvil:
mkdir -p "testdata/$(dt)"
cp ./templates/testconfig-anvil-docker.yaml "testdata/$(dt)/config.yaml"

infra:
go run ./deploy/cmd -localstack-port 4570 infra
chain:
go run ./deploy/cmd -localstack-port 4570 chain

resources:
go run ./deploy/cmd -localstack-port 4570 resources
localstack:
go run ./deploy/cmd -localstack-port 4570 localstack

exp:
go run ./deploy/cmd exp
Expand All @@ -38,7 +38,7 @@ deploy-all:
stop-infra:
./bin.sh stop-anvil
./bin.sh stop-graph
docker stop $(shell docker container ls --all --filter=ancestor=localstack/localstack:latest --format "{{.ID}}")
docker stop localstack-test

run-e2e:
go test ./tests -v -config=../templates/testconfig-anvil.yaml
Expand Down
Loading
Loading