[Perf] add edge-case test for GetMetadataForSourceFileIDs
Bug: 446827886
Add unit test for an edge case where the IDs list is empty.
Change-Id: I1425105e0ba4624f68bca3799821886eb71bfffd
Reviewed-on: https://skia-review.googlesource.com/c/buildbot/+/1060157
Commit-Queue: Marcin Mordecki <mordeckimarcin@google.com>
Reviewed-by: Ashwin Verleker <ashwinpv@google.com>
diff --git a/perf/go/tracestore/sqltracestore/sqlmetadatastore.go b/perf/go/tracestore/sqltracestore/sqlmetadatastore.go
index 8f37b1e..44946db 100644
--- a/perf/go/tracestore/sqltracestore/sqlmetadatastore.go
+++ b/perf/go/tracestore/sqltracestore/sqlmetadatastore.go
@@ -9,6 +9,7 @@
"github.com/jackc/pgx/v4"
"go.skia.org/infra/go/skerr"
+ "go.skia.org/infra/go/sklog"
"go.skia.org/infra/go/sql/pool"
"go.skia.org/infra/go/util"
"go.skia.org/infra/perf/go/tracestore"
@@ -172,6 +173,10 @@
}
func (s *SQLMetadataStore) GetMetadataForSourceFileIDs(ctx context.Context, sourceFileIDs []int64) (map[int64]map[string]string, error) {
+ if len(sourceFileIDs) == 0 {
+ sklog.Info("sourceFileIDs list is empty, returning")
+ return map[int64]map[string]string{}, nil
+ }
fileLinksAggregate := map[int64]map[string]string{}
mutex := sync.Mutex{}
err := util.ChunkIterParallelPool(ctx, len(sourceFileIDs), 200, 50, func(ctx context.Context, startIdx, endIdx int) error {
diff --git a/perf/go/tracestore/sqltracestore/sqlmetadatastore_test.go b/perf/go/tracestore/sqltracestore/sqlmetadatastore_test.go
index 0f390a6..2a80616 100644
--- a/perf/go/tracestore/sqltracestore/sqlmetadatastore_test.go
+++ b/perf/go/tracestore/sqltracestore/sqlmetadatastore_test.go
@@ -4,8 +4,10 @@
"context"
"fmt"
"testing"
+ "time"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
"go.skia.org/infra/go/sql/pool"
"go.skia.org/infra/perf/go/sql/sqltest"
)
@@ -112,3 +114,13 @@
assert.Equal(t, metadata["key2"], fmt.Sprintf("link2_file_%s", sourceFile))
}
}
+
+func TestGetMetadataForSourceFileIDs_EmptyIDsList(t *testing.T) {
+ store := createMetadataStoreForTests(t)
+ emptyIDsList := []int64{}
+ // ctx to get rid of warnings
+ ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
+ defer cancel()
+ _, err := store.GetMetadataForSourceFileIDs(ctx, emptyIDsList)
+ require.NoError(t, err)
+}