From e206a3663fc38714bd2c7004e0a20ba2430587f7 Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Fri, 11 Feb 2022 12:28:24 -0800 Subject: [PATCH] cmd/derper: add BenchmarkHandleBootstrapDNS Signed-off-by: Josh Bleecher Snyder --- cmd/derper/bootstrap_dns_test.go | 35 ++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 cmd/derper/bootstrap_dns_test.go diff --git a/cmd/derper/bootstrap_dns_test.go b/cmd/derper/bootstrap_dns_test.go new file mode 100644 index 000000000..240711a5e --- /dev/null +++ b/cmd/derper/bootstrap_dns_test.go @@ -0,0 +1,35 @@ +// Copyright (c) 2022 Tailscale Inc & AUTHORS All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "net/http" + "testing" +) + +func BenchmarkHandleBootstrapDNS(b *testing.B) { + prev := *bootstrapDNS + *bootstrapDNS = "log.tailscale.io,login.tailscale.com,controlplane.tailscale.com,login.us.tailscale.com" + defer func() { + *bootstrapDNS = prev + }() + refreshBootstrapDNS() + w := new(bitbucketResponseWriter) + b.ReportAllocs() + b.ResetTimer() + b.RunParallel(func(b *testing.PB) { + for b.Next() { + handleBootstrapDNS(w, nil) + } + }) +} + +type bitbucketResponseWriter struct{} + +func (b *bitbucketResponseWriter) Header() http.Header { return make(http.Header) } + +func (b *bitbucketResponseWriter) Write(p []byte) (int, error) { return len(p), nil } + +func (b *bitbucketResponseWriter) WriteHeader(statusCode int) {}