From bf3b84146e48ae8c2d0eabbe111e9c1fef7782d1 Mon Sep 17 00:00:00 2001 From: Forrest <30576607+fspmarshall@users.noreply.github.com> Date: Mon, 26 Aug 2024 11:52:50 -0700 Subject: [PATCH] improve max nodes benchmark (#45545) (#45850) * improve max nodes benchmark * Update Makefile --------- Co-authored-by: rosstimothy <39066650+rosstimothy@users.noreply.github.com> --- lib/cache/cache_test.go | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/lib/cache/cache_test.go b/lib/cache/cache_test.go index 3b676cd57bc48..144297b81442f 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) } }