Skip to content

Commit

Permalink
fix: added count method (#4985)
Browse files Browse the repository at this point in the history
* fix: added count method

* fix: added Count method to results and suites results

* fix: added cool down to flaky test
  • Loading branch information
exu authored Feb 9, 2024
1 parent 1acd131 commit a53f26e
Show file tree
Hide file tree
Showing 15 changed files with 69 additions and 11 deletions.
4 changes: 4 additions & 0 deletions internal/app/api/v1/executions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,10 @@ func (r MockExecutionResultsRepository) GetTestMetrics(ctx context.Context, name
panic("not implemented")
}

func (r MockExecutionResultsRepository) Count(ctx context.Context, filter result.Filter) (int64, error) {
panic("not implemented")
}

type MockExecutor struct {
LogsFn func(id string) (chan output.Output, error)
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/cloud/data/result/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,3 +316,7 @@ func (r *CloudRepository) GetTestMetrics(ctx context.Context, name string, limit
}
return commandResponse.Metrics, nil
}

func (r *CloudRepository) Count(ctx context.Context, filter result.Filter) (int64, error) {
return 0, nil
}
4 changes: 4 additions & 0 deletions pkg/cloud/data/testresult/testresult.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,7 @@ func (r *CloudRepository) GetTestSuiteMetrics(ctx context.Context, name string,
}
return commandResponse.Metrics, nil
}

func (r *CloudRepository) Count(ctx context.Context, filter testresult.Filter) (int64, error) {
return 0, nil
}
5 changes: 5 additions & 0 deletions pkg/executor/containerexecutor/containerexecutor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,11 @@ func (r FakeResultRepository) GetTestMetrics(ctx context.Context, name string, l
panic("implement me")
}

func (r FakeResultRepository) Count(ctx context.Context, filter result.Filter) (count int64, err error) {
//TODO implement me
panic("implement me")
}

func (FakeResultRepository) Get(ctx context.Context, id string) (testkube.Execution, error) {
return testkube.Execution{}, nil
}
Expand Down
1 change: 0 additions & 1 deletion pkg/executor/scraper/mock_scraper.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion pkg/executor/scraper/mock_uploader.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion pkg/logs/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func TestLogs_EventsFlow(t *testing.T) {
// and wait for message to be propagated
emitter.Notify(testkube.NewEventEndTestFailed(&testkube.Execution{Id: "id1"}))

time.Sleep(time.Second)
time.Sleep(waitTime)

assertMessagesCount(t, a, messagesCount)

Expand Down Expand Up @@ -253,6 +253,9 @@ func TestLogs_EventsFlow(t *testing.T) {
_, err = stream.Stop(ctx, id)
assert.NoError(t, err)

// cool down
time.Sleep(waitTime)

// then each adapter should receive messages
assertMessagesCount(t, a1, messagesCount)
assertMessagesCount(t, a2, messagesCount)
Expand Down
1 change: 0 additions & 1 deletion pkg/repository/config/mock_repository.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion pkg/repository/result/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@ type Repository interface {
DeleteByTestSuites(ctx context.Context, testSuiteNames []string) (err error)
// DeleteForAllTestSuites deletes execution results for all test suites
DeleteForAllTestSuites(ctx context.Context) (err error)

// GetTestMetrics returns metrics for test
GetTestMetrics(ctx context.Context, name string, limit, last int) (metrics testkube.ExecutionsMetrics, err error)
// Count returns executions count
Count(ctx context.Context, filter Filter) (int64, error)
}

type Sequences interface {
Expand Down
16 changes: 15 additions & 1 deletion pkg/repository/result/mock_repository.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions pkg/repository/result/mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,11 @@ func (r *MongoRepository) GetExecutions(ctx context.Context, filter Filter) (res
return
}

func (r *MongoRepository) Count(ctx context.Context, filter Filter) (count int64, err error) {
query, _ := composeQueryAndOpts(filter)
return r.ResultsColl.CountDocuments(ctx, query)
}

func (r *MongoRepository) GetExecutionTotals(ctx context.Context, paging bool, filter ...Filter) (totals testkube.ExecutionsTotals, err error) {
var result []struct {
Status string `bson:"_id"`
Expand Down
6 changes: 4 additions & 2 deletions pkg/repository/testresult/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type Filter interface {
Selector() string
}

//go:generate mockgen -destination=./mock_repository.go -package=testresult "github.com/kubeshop/testkube/internal/pkg/api/repository/testresult" Repository
//go:generate mockgen -destination=./mock_repository.go -package=testresult "github.com/kubeshop/testkube/pkg/repository/testresult" Repository
type Repository interface {
// Get gets execution result by id or name
Get(ctx context.Context, id string) (testkube.TestSuiteExecution, error)
Expand Down Expand Up @@ -55,6 +55,8 @@ type Repository interface {
DeleteAll(ctx context.Context) error
// DeleteByTestSuites deletes execution results by test suites
DeleteByTestSuites(ctx context.Context, testSuiteNames []string) (err error)

// GetTestSuiteMetrics returns metrics for test suite
GetTestSuiteMetrics(ctx context.Context, name string, limit, last int) (metrics testkube.ExecutionsMetrics, err error)
// Count returns executions count
Count(ctx context.Context, filter Filter) (int64, error)
}
18 changes: 16 additions & 2 deletions pkg/repository/testresult/mock_repository.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions pkg/repository/testresult/mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,11 @@ func (r *MongoRepository) GetNewestExecutions(ctx context.Context, limit int) (r
return
}

func (r *MongoRepository) Count(ctx context.Context, filter Filter) (count int64, err error) {
query, _ := composeQueryAndOpts(filter)
return r.Coll.CountDocuments(ctx, query)
}

func (r *MongoRepository) GetExecutionsTotals(ctx context.Context, filter ...Filter) (totals testkube.ExecutionsTotals, err error) {
var result []struct {
Status string `bson:"_id"`
Expand Down
1 change: 0 additions & 1 deletion pkg/storage/artifacts_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a53f26e

Please sign in to comment.