-
Notifications
You must be signed in to change notification settings - Fork 499
Expand file tree
/
Copy pathclient_logger_test.go
More file actions
62 lines (52 loc) · 1.5 KB
/
client_logger_test.go
File metadata and controls
62 lines (52 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright IBM Corp. 2016, 2025
// SPDX-License-Identifier: MPL-2.0
package plugin
import (
"io"
"sync"
"testing"
"github.com/hashicorp/go-hclog"
)
func BenchmarkClientLogging(b *testing.B) {
// We're not actually going to start the process in this benchmark,
// so this is just a placeholder to satisfy the ClientConfig.
process := helperProcess("bad-version")
tests := map[string]hclog.Level{
"off": hclog.Off,
"error": hclog.Error,
"trace": hclog.Trace,
}
for name, logLevel := range tests {
b.Run(name, func(b *testing.B) {
logger := hclog.New(&hclog.LoggerOptions{
Name: "test-logger",
Level: logLevel,
Output: io.Discard,
Mutex: new(sync.Mutex),
})
c := NewClient(&ClientConfig{
Cmd: process,
Stderr: io.Discard,
HandshakeConfig: testHandshake,
Logger: logger,
Plugins: testPluginMap,
})
r, w := io.Pipe()
c.clientWaitGroup.Add(1)
c.pipesWaitGroup.Add(1)
// logStderr calls Done() on both waitgroups
go c.logStderr("test", r)
fakeLogLine := []byte("{\"@level\":\"debug\",\"@timestamp\":\"2006-01-02T15:04:05.000000Z\",\"@message\":\"hello\",\"extra\":\"hi\",\"numbers\":[1,2,3]}\n")
for b.Loop() {
n, err := w.Write(fakeLogLine)
if err != nil || n != len(fakeLogLine) {
b.Fatal("failed to write to pipe")
}
}
err := w.Close() // causes the c.logStderr goroutine to exit
if err != nil {
b.Fatalf("failed to close write end of pipe: %s", err)
}
})
}
}