Skip to content

Commit

Permalink
use output test cases also for benchmarking
Browse files Browse the repository at this point in the history
So far, the output tests were only used for correctness checking. But they
cover a variety of scenarios for which there were no benchmarks, therefore it
makes sense to also use them for that.
  • Loading branch information
pohly authored and dims committed Jan 19, 2023
1 parent f833abb commit 757e6bb
Show file tree
Hide file tree
Showing 4 changed files with 489 additions and 390 deletions.
13 changes: 10 additions & 3 deletions examples/output_test/output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ import (
"k8s.io/klog/v2/textlogger"
)

func newLogger(out io.Writer, v int, vmodule string) logr.Logger {
return newZaprLogger(out, v)
}

// TestZaprOutput tests the zapr, directly and as backend.
func TestZaprOutput(t *testing.T) {
test.InitKlog(t)
newLogger := func(out io.Writer, v int, vmodule string) logr.Logger {
return newZaprLogger(out, v)
}
t.Run("direct", func(t *testing.T) {
test.Output(t, test.OutputConfig{NewLogger: newLogger, ExpectedOutputMapping: test.ZaprOutputMappingDirect()})
})
Expand All @@ -48,6 +49,12 @@ func TestZaprOutput(t *testing.T) {
})
}

// Benchmark direct zapr output.
func BenchmarkZaprOutput(b *testing.B) {
test.InitKlog(b)
test.Benchmark(b, test.OutputConfig{NewLogger: newLogger, ExpectedOutputMapping: test.ZaprOutputMappingDirect()})
}

// TestKlogrStackText tests klogr.klogr -> klog -> text logger.
func TestKlogrStackText(t *testing.T) {
test.InitKlog(t)
Expand Down
25 changes: 17 additions & 8 deletions output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,27 @@ import (
"k8s.io/klog/v2/test"
)

// TestKlogOutput tests klog output without a logger.
// klogConfig tests klog output without a logger.
var klogConfig = test.OutputConfig{}

func TestKlogOutput(t *testing.T) {
test.InitKlog(t)
test.Output(t, test.OutputConfig{})
test.Output(t, klogConfig)
}

func BenchmarkKlogOutput(b *testing.B) {
test.InitKlog(b)
test.Benchmark(b, klogConfig)
}

// klogKlogrConfig tests klogr output via klog, using the klog/v2 klogr.
var klogKLogrConfig = test.OutputConfig{
NewLogger: func(out io.Writer, v int, vmodule string) logr.Logger {
return klog.NewKlogr()
},
}

// TestKlogKlogrOutput tests klogr output via klog, using the klog/v2 klogr.
func TestKlogrOutput(t *testing.T) {
test.InitKlog(t)
test.Output(t, test.OutputConfig{
NewLogger: func(out io.Writer, v int, vmodule string) logr.Logger {
return klog.NewKlogr()
},
})
test.Output(t, klogKLogrConfig)
}
Loading

0 comments on commit 757e6bb

Please sign in to comment.