Skip to content

Commit

Permalink
Efficient-unit-tests (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
mooselumph authored Nov 17, 2023
1 parent f595cf9 commit 3c4c988
Show file tree
Hide file tree
Showing 13 changed files with 202 additions and 136 deletions.
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
40 changes: 0 additions & 40 deletions .github/workflows/test-coverage.yml

This file was deleted.

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)
}
}
Loading

0 comments on commit 3c4c988

Please sign in to comment.