-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathdaemon_test.go
More file actions
79 lines (65 loc) · 2.05 KB
/
daemon_test.go
File metadata and controls
79 lines (65 loc) · 2.05 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package test
import (
"context"
"encoding/json"
"fmt"
"net/http"
"os"
"os/exec"
"path"
"strings"
"testing"
"github.com/google/pprof/profile"
"github.com/moby/buildkit-bench/util/testutil"
"github.com/stretchr/testify/require"
)
func TestDaemon(t *testing.T) {
testutil.Run(t, testutil.TestFuncs(
testDaemonVersion,
testDaemonDebugHeap,
))
}
func BenchmarkDaemon(b *testing.B) {
testutil.Run(b, testutil.BenchFuncs(
benchmarkDaemonVersion,
benchmarkDaemonSize,
))
}
func testDaemonVersion(t *testing.T, sb testutil.Sandbox) {
buildkitdPath := path.Join(sb.BuildKitBinsDir(), sb.Name(), "buildkitd")
output, err := exec.CommandContext(context.Background(), buildkitdPath, "--version").Output()
require.NoError(t, err)
versionParts := strings.Fields(string(output))
require.Len(t, versionParts, 4)
require.Equal(t, "buildkitd", versionParts[0])
t.Log("repo:", versionParts[1])
t.Log("version:", versionParts[2])
t.Log("commit:", versionParts[3])
}
func testDaemonDebugHeap(t *testing.T, sb testutil.Sandbox) {
client := &http.Client{}
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, fmt.Sprintf("http://%s/debug/pprof/heap?debug=1", sb.DebugAddress()), nil)
require.NoError(t, err)
resp, err := client.Do(req)
require.NoError(t, err)
defer resp.Body.Close()
p, err := profile.Parse(resp.Body)
require.NoError(t, err)
b, err := json.MarshalIndent(p, "", " ")
require.NoError(t, err)
require.NotEmpty(t, p.SampleType, string(b))
require.NotEmpty(t, p.Sample, string(b))
}
func benchmarkDaemonVersion(b *testing.B, sb testutil.Sandbox) {
buildkitdPath := path.Join(sb.BuildKitBinsDir(), sb.Name(), "buildkitd")
b.StartTimer()
err := exec.CommandContext(context.Background(), buildkitdPath, "--version").Run()
b.StopTimer()
require.NoError(b, err)
}
func benchmarkDaemonSize(b *testing.B, sb testutil.Sandbox) {
buildkitdPath := path.Join(sb.BuildKitBinsDir(), sb.Name(), "buildkitd")
fi, err := os.Stat(buildkitdPath)
require.NoError(b, err)
testutil.ReportMetric(b, float64(fi.Size()), testutil.MetricBytes)
}