Skip to content

Commit

Permalink
chore: Move testing to top-level tests folder (#446)
Browse files Browse the repository at this point in the history
  • Loading branch information
orpheuslummis committed May 20, 2022
1 parent 19852ef commit fd76c5c
Show file tree
Hide file tree
Showing 99 changed files with 136 additions and 159 deletions.
6 changes: 2 additions & 4 deletions .github/codecov.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Source Network's codecov configuration file.

github_checks:
annotations: true
annotations: true

codecov:
require_ci_to_pass: yes
Expand Down Expand Up @@ -31,13 +31,11 @@ coverage:

changes: false


comment:
layout: "reach, diff, files"
behavior: default # update if exists else create new
require_changes: true

ignore:
- "bench"
- "db/tests"
- "tests"
- "**/*_test.go"
28 changes: 13 additions & 15 deletions .github/workflows/lint-then-benchmark.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
name: Lint and then Benchmark


on:
pull_request:

Expand All @@ -11,22 +10,17 @@ on:
- master
- develop


## These are the permissions for the lint check job.
permissions:
# Allow read access to pull request (Required for the `only-new-issues` option.)
pull-requests: read
contents: read


env:
# This is the default benchmark type which if no labels are specified will be used.
DEFAULT_BENCHMARK_TYPE: SHORT


jobs:


# ========================================================= Step-1: Run the lint check.
golangci:
name: Lint Check
Expand All @@ -44,7 +38,7 @@ jobs:
- name: Setup Go environment explicitly
uses: actions/setup-go@v3
with:
go-version: '1.17'
go-version: "1.17"
check-latest: true

- name: Run the golangci-lint
Expand All @@ -65,7 +59,7 @@ jobs:
# indicating that the linter ran successfully (weather or not linter errors
# exist or not doesn't matter). But the good think is that the annotations
# will still show up. I think this can be useful if we don't want the pipeline
# to stop just because we had some linter errors.
# to stop just because we had some linter errors.
args: --issues-exit-code=1 --config tools/configs/golangci.yaml

# Optional: we can set the below to `true` if we only want to see newly
Expand All @@ -77,7 +71,6 @@ jobs:
# always have a clean lint state.
only-new-issues: false


# =================== Step-2: Decide what type of benchmarks to run based on label(s).
# This job acts like a switch to simplify our ci control flow later on.
decide-benchmark-type:
Expand Down Expand Up @@ -117,7 +110,6 @@ jobs:
id: set-benchmark-type
run: echo "::set-output name=type::${DEFAULT_BENCHMARK_TYPE}"


# ================== Step-3: Start the runner and get it registered as a github runner.
start-runner:
name: Start self-hosted EC2 runner
Expand Down Expand Up @@ -159,7 +151,6 @@ jobs:
## {"Key": "GitHubRepository", "Value": "${{ github.repository }}"}
## ]


# =========================== Step-4: Run the benchmarks on the runner we just started.
benchmark-ec2-runner:
name: Run the benchmarks on the started EC2 runner
Expand Down Expand Up @@ -210,7 +201,7 @@ jobs:

# ------------- Download & Compare - If PR going into develop

# To find the latest commit on remote develop branch we essentially
# To find the latest commit on remote develop branch we essentially
# just need to do the following:
# >> git fetch origin develop > /dev/null 2>&1 \
# && git rev-parse origin/develop
Expand Down Expand Up @@ -240,16 +231,24 @@ jobs:
branch: develop
name: bench-artifact-${{ steps.last_successful_upload_on_develop.outputs.commit_hash }}
repo: ${{ github.repository }}
check_artifacts: false
check_artifacts: false
search_artifacts: false

- name: Run the benchmark comparisons
- name: Prepare benchmark reports for comparisons
if: |
github.event_name == 'pull_request' &&
github.base_ref == 'develop'
run: >
make deps:bench &&
cp bench-artifact-${{ steps.last_successful_upload_on_develop.outputs.commit_hash }}.txt develop.txt &&
sed -i '/^pkg: /s/^pkg:\ .*\/bench\//pkg:\ /g' develop.txt &&
sed -i '/^pkg: /s/^pkg:\ .*\/bench\//pkg:\ /g' current.txt
- name: Run the benchmark comparisons
if: |
github.event_name == 'pull_request' &&
github.base_ref == 'develop'
run: >
${GOPATH}/bin/benchstat -html -alpha 1.1 develop.txt current.txt | sed -n "/<body>/,/<\/body>/p" > comparison.html &&
./tools/scripts/pretty-benchstat-html.sh comparison.html > pretty-comparison.md
Expand All @@ -263,7 +262,6 @@ jobs:
with:
path: pretty-comparison.md


# =============================== Step-5: Stop the runner once the benchmarks have ran.
stop-runner:
name: Stop self-hosted EC2 runner
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ build/defradb*
cover.out
coverage-full.txt
coverage-quick.txt
bench/*.log
bench/*.svg
tests/bench/*.log
tests/bench/*.svg
.vscode
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ test\:clean: clean\:test test

.PHONY: test\:bench
test\:bench:
make -C ./bench/ bench
make -C ./tests/bench/ bench

.PHONY: test\:bench-short
test\:bench-short:
make -C ./bench/ bench:short
make -C ./tests/bench/ bench:short

# This also takes integration tests into account.
.PHONY: test\:coverage-full
Expand Down
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions bench/bench_util.go → tests/bench/bench_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import (
"github.com/dgraph-io/badger/v3"
ds "github.com/ipfs/go-datastore"

"github.com/sourcenetwork/defradb/bench/fixtures"
"github.com/sourcenetwork/defradb/client"
testutils "github.com/sourcenetwork/defradb/db/tests"
"github.com/sourcenetwork/defradb/logging"
"github.com/sourcenetwork/defradb/tests/bench/fixtures"
testutils "github.com/sourcenetwork/defradb/tests/integration"
)

const (
Expand All @@ -36,7 +36,7 @@ const (

var (
storage string = "memory"
log = logging.MustNewLogger("defra.bench")
log = logging.MustNewLogger("defra.tests.bench")
)

func init() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"context"
"testing"

"github.com/sourcenetwork/defradb/bench/fixtures"
"github.com/sourcenetwork/defradb/tests/bench/fixtures"
)

func Benchmark_Collection_UserSimple_CreateMany_Sync_0_10(b *testing.B) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"context"
"testing"

"github.com/sourcenetwork/defradb/bench/fixtures"
"github.com/sourcenetwork/defradb/tests/bench/fixtures"
)

func Benchmark_Collection_UserSimple_Create_Sync_0_1(b *testing.B) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"context"
"testing"

"github.com/sourcenetwork/defradb/bench/fixtures"
"github.com/sourcenetwork/defradb/tests/bench/fixtures"
)

func Benchmark_Collection_UserSimple_Read_Sync_1_1(b *testing.B) {
Expand Down
4 changes: 2 additions & 2 deletions bench/collection/utils.go → tests/bench/collection/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import (
"sync"
"testing"

benchutils "github.com/sourcenetwork/defradb/bench"
"github.com/sourcenetwork/defradb/bench/fixtures"
"github.com/sourcenetwork/defradb/client"
benchutils "github.com/sourcenetwork/defradb/tests/bench"
"github.com/sourcenetwork/defradb/tests/bench/fixtures"
)

const (
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"context"
"testing"

"github.com/sourcenetwork/defradb/bench/fixtures"
"github.com/sourcenetwork/defradb/tests/bench/fixtures"
)

var (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import (
"fmt"
"testing"

benchutils "github.com/sourcenetwork/defradb/bench"
"github.com/sourcenetwork/defradb/bench/fixtures"
"github.com/sourcenetwork/defradb/query/graphql/planner"
"github.com/sourcenetwork/defradb/query/graphql/schema"
benchutils "github.com/sourcenetwork/defradb/tests/bench"
"github.com/sourcenetwork/defradb/tests/bench/fixtures"
)

func runQueryParserBench(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"context"
"testing"

"github.com/sourcenetwork/defradb/bench/fixtures"
"github.com/sourcenetwork/defradb/tests/bench/fixtures"
)

var (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import (
"strings"
"testing"

benchutils "github.com/sourcenetwork/defradb/bench"
"github.com/sourcenetwork/defradb/bench/fixtures"
"github.com/sourcenetwork/defradb/client"
benchutils "github.com/sourcenetwork/defradb/tests/bench"
"github.com/sourcenetwork/defradb/tests/bench/fixtures"
)

var (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"context"
"testing"

"github.com/sourcenetwork/defradb/bench/fixtures"
"github.com/sourcenetwork/defradb/tests/bench/fixtures"
)

var (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"context"
"testing"

"github.com/sourcenetwork/defradb/bench/fixtures"
"github.com/sourcenetwork/defradb/tests/bench/fixtures"
)

var (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"context"
"testing"

"github.com/sourcenetwork/defradb/bench/fixtures"
"github.com/sourcenetwork/defradb/tests/bench/fixtures"
)

var (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"context"
"testing"

"github.com/sourcenetwork/defradb/bench/fixtures"
"github.com/sourcenetwork/defradb/tests/bench/fixtures"
)

var (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"context"
"testing"

"github.com/sourcenetwork/defradb/bench/fixtures"
"github.com/sourcenetwork/defradb/tests/bench/fixtures"
)

var (
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion bench/storage/utils.go → tests/bench/storage/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (
ds "github.com/ipfs/go-datastore"
"github.com/ipfs/go-datastore/query"

benchutils "github.com/sourcenetwork/defradb/bench"
"github.com/sourcenetwork/defradb/client"
benchutils "github.com/sourcenetwork/defradb/tests/bench"
)

func runStorageBenchGet(
Expand Down
12 changes: 6 additions & 6 deletions db/tests/README.md → tests/integration/README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
## Testing Guide
## Database Integration Testing Guide

- We want to keep the mutation and query tests separate, here is what the folder
structure looks like currently:
```
db/tests
tests/integration
├── mutation/
└── query/
```

- Every immediate directory under `db/tests/mutation` and `db/tests/query` should ONLY contain
- Every immediate directory under `tests/integration/mutation` and `tests/integration/query` should ONLY contain
a single schema. For example:
`db/tests/query/simple` and `db/tests/query/complex` have different schemas.
`tests/integration/query/simple` and `tests/integration/query/complex` have different schemas.

- We can group different types of tests using the same schema into further sub-folders.
For example:
- `db/tests/mutation/simple/create`: contains tests that
- `tests/integration/mutation/simple/create`: contains tests that
use the `simple` schema to test only the create mutation.
- `db/tests/mutation/simple/mix`: contains test that use
- `tests/integration/mutation/simple/mix`: contains test that use
the `simple` schema to test combination of mutations.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ package update
import (
"testing"

testUtils "github.com/sourcenetwork/defradb/db/tests"
inlineArray "github.com/sourcenetwork/defradb/db/tests/mutation/inline_array"
testUtils "github.com/sourcenetwork/defradb/tests/integration"
inlineArray "github.com/sourcenetwork/defradb/tests/integration/mutation/inline_array"
)

func TestMutationInlineArrayUpdateWithBooleans(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ package inline_array
import (
"testing"

testUtils "github.com/sourcenetwork/defradb/db/tests"
testUtils "github.com/sourcenetwork/defradb/tests/integration"
)

var userCollectionGQLSchema = (`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ package relation_delete
import (
"testing"

testUtils "github.com/sourcenetwork/defradb/db/tests"
relationTests "github.com/sourcenetwork/defradb/db/tests/mutation/relation"
testUtils "github.com/sourcenetwork/defradb/tests/integration"
relationTests "github.com/sourcenetwork/defradb/tests/integration/mutation/relation"
)

func TestRelationalDeletionOfADocumentUsingSingleKey_Success(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ package relation
import (
"testing"

testUtils "github.com/sourcenetwork/defradb/db/tests"
testUtils "github.com/sourcenetwork/defradb/tests/integration"
)

var bookAuthorPublisherGQLSchema = (`
Expand Down
Loading

0 comments on commit fd76c5c

Please sign in to comment.