Skip to content

Commit

Permalink
ci(tests): run each test as a separate job
Browse files Browse the repository at this point in the history
  • Loading branch information
byashimov committed Feb 29, 2024
1 parent 077c752 commit a452384
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 18 deletions.
21 changes: 19 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,34 @@ jobs:
AIVEN_TOKEN: ${{ secrets.AIVEN_TOKEN }}
AIVEN_PROJECT_NAME_PREFIX: ${{ secrets.AIVEN_PROJECT_NAME_PREFIX }}

find_tests:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.find_tests.outputs.matrix }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
- id: find_tests
run: |
echo "matrix=$(LIST_ONLY=1 go test ./tests/... -list=. | grep Test | jq -cnR '[inputs | select(length>0)]')" >> $GITHUB_OUTPUT
test:
needs: setup_aiven_project_suffix
needs: [setup_aiven_project_suffix, find_tests]
runs-on: ubuntu-latest
strategy:
max-parallel: 5
matrix:
name: ${{ fromJson(needs.find_tests.outputs.matrix) }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
- run: make test
- run: make run="^${{ matrix.name }}$" test
env:
AIVEN_TOKEN: ${{ secrets.AIVEN_TOKEN }}
AIVEN_PROJECT_NAME: >-
Expand Down
26 changes: 10 additions & 16 deletions tests/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
)

const (
suiteTimeout = time.Minute * 20
retryInterval = time.Second * 10
createTimeout = time.Second * 15
waitRunningTimeout = time.Minute * 20
Expand All @@ -46,23 +45,20 @@ type Session interface {
var _ Session = &session{}

type session struct {
k8s client.Client
avn *aiven.Client
ctx context.Context
cancelCtx func()
objs map[string]client.Object
project string
k8s client.Client
avn *aiven.Client
ctx context.Context
objs map[string]client.Object
project string
}

func NewSession(k8s client.Client, avn *aiven.Client, project string) Session {
ctx, cancel := context.WithTimeout(context.Background(), suiteTimeout)
s := &session{
k8s: k8s,
avn: avn,
ctx: ctx,
cancelCtx: cancel,
objs: make(map[string]client.Object),
project: project,
k8s: k8s,
avn: avn,
ctx: context.Background(),
objs: make(map[string]client.Object),
project: project,
}
return s
}
Expand Down Expand Up @@ -146,8 +142,6 @@ func (s *session) GetSecret(keys ...string) (*corev1.Secret, error) {
// Tolerant to "not found" error,
// because resource may have been deleted manually
func (s *session) Destroy() {
defer s.cancelCtx()

if err := recover(); err != nil {
log.Printf("panicked, deleting resources: %s", err)
}
Expand Down
7 changes: 7 additions & 0 deletions tests/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ type testConfig struct {
}

func TestMain(m *testing.M) {
if os.Getenv("LIST_ONLY") != "" {
// For go test ./... -list=.
// Lists test names without running them.
m.Run()
return
}

env, err := setupSuite()
if err != nil {
log.Fatal(err)
Expand Down

0 comments on commit a452384

Please sign in to comment.