Skip to content

Commit

Permalink
improve max nodes benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
fspmarshall committed Aug 16, 2024
1 parent 3e20100 commit b2f8712
Showing 2 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -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
28 changes: 21 additions & 7 deletions lib/cache/cache_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit b2f8712

Please sign in to comment.