diff --git a/Makefile b/Makefile index 99f1cf6acb6f3..da61cda99f4bd 100644 --- a/Makefile +++ b/Makefile @@ -885,7 +885,7 @@ endif # todo: Use gotestsum when it is compatible with benchmark output. Currently will consider all benchmarks failed. .PHONY: test-go-bench test-go-bench: PACKAGES = $(shell grep --exclude-dir api --include "*_test.go" -lr testing.B . | xargs dirname | xargs go list | sort -u) -test-go-bench: BENCHMARK_SKIP_PATTERN = "^BenchmarkRoot|^BenchmarkGetMaxNodes$$" +test-go-bench: BENCHMARK_SKIP_PATTERN = "^BenchmarkRoot" test-go-bench: | $(TEST_LOG_DIR) go test -run ^$$ -bench . -skip $(BENCHMARK_SKIP_PATTERN) -benchtime 1x $(PACKAGES) \ | tee $(TEST_LOG_DIR)/bench.txt diff --git a/lib/cache/cache_test.go b/lib/cache/cache_test.go index c733695edeab1..1161aa27205ac 100644 --- a/lib/cache/cache_test.go +++ b/lib/cache/cache_test.go @@ -925,7 +925,7 @@ cpu: Intel(R) Core(TM) i9-10885H CPU @ 2.40GHz BenchmarkGetMaxNodes-16 1 1029199093 ns/op */ func BenchmarkGetMaxNodes(b *testing.B) { - benchGetNodes(b, backend.DefaultRangeLimit) + benchGetNodes(b, 1_000_000) } func benchGetNodes(b *testing.B, nodeCount int) { @@ -933,18 +933,32 @@ func benchGetNodes(b *testing.B, nodeCount int) { require.NoError(b, err) defer p.Close() - ctx := context.Background() + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() - for i := 0; i < nodeCount; i++ { - server := suite.NewServer(types.KindNode, uuid.New().String(), "127.0.0.1:2022", apidefaults.Namespace) - _, err := p.presenceS.UpsertNode(ctx, server) - require.NoError(b, err) + createErr := make(chan error, 1) + go func() { + for i := 0; i < nodeCount; i++ { + server := suite.NewServer(types.KindNode, uuid.New().String(), "127.0.0.1:2022", apidefaults.Namespace) + _, err := p.presenceS.UpsertNode(ctx, server) + if err != nil { + createErr <- err + return + } + } + }() + + timeout := time.After(time.Second * 90) + + for i := 0; i < nodeCount; i++ { select { case event := <-p.eventsC: require.Equal(b, EventProcessed, event.Type) - case <-time.After(200 * time.Millisecond): - b.Fatalf("timeout waiting for event, iteration=%d", i) + case err := <-createErr: + b.Fatalf("failed to create node: %v", err) + case <-timeout: + b.Fatalf("timeout waiting for event, progress=%d", i) } }