Skip to content

Commit 6f6f966

Browse files
committed
Add benchmark for register and graph
Signed-off-by: Derek McGowan <derek@mcg.dev>
1 parent b8ec79b commit 6f6f966

1 file changed

Lines changed: 42 additions & 19 deletions

File tree

plugin_test.go

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,27 @@ func mockPluginFilter(*Registration) bool {
2626
return false
2727
}
2828

29-
// TestContainerdPlugin tests the logic of Graph, use the containerd's plugin
30-
func TestContainerdPlugin(t *testing.T) {
31-
// Plugin types commonly used by containerd
32-
const (
33-
InternalPlugin Type = "io.containerd.internal.v1"
34-
RuntimePlugin Type = "io.containerd.runtime.v1"
35-
RuntimePluginV2 Type = "io.containerd.runtime.v2"
36-
ServicePlugin Type = "io.containerd.service.v1"
37-
GRPCPlugin Type = "io.containerd.grpc.v1"
38-
SnapshotPlugin Type = "io.containerd.snapshotter.v1"
39-
TaskMonitorPlugin Type = "io.containerd.monitor.v1"
40-
DiffPlugin Type = "io.containerd.differ.v1"
41-
MetadataPlugin Type = "io.containerd.metadata.v1"
42-
ContentPlugin Type = "io.containerd.content.v1"
43-
GCPlugin Type = "io.containerd.gc.v1"
44-
LeasePlugin Type = "io.containerd.lease.v1"
45-
TracingProcessorPlugin Type = "io.containerd.tracing.processor.v1"
46-
)
29+
// Plugin types commonly used by containerd
30+
const (
31+
InternalPlugin Type = "io.containerd.internal.v1"
32+
RuntimePlugin Type = "io.containerd.runtime.v1"
33+
RuntimePluginV2 Type = "io.containerd.runtime.v2"
34+
ServicePlugin Type = "io.containerd.service.v1"
35+
GRPCPlugin Type = "io.containerd.grpc.v1"
36+
SnapshotPlugin Type = "io.containerd.snapshotter.v1"
37+
TaskMonitorPlugin Type = "io.containerd.monitor.v1"
38+
DiffPlugin Type = "io.containerd.differ.v1"
39+
MetadataPlugin Type = "io.containerd.metadata.v1"
40+
ContentPlugin Type = "io.containerd.content.v1"
41+
GCPlugin Type = "io.containerd.gc.v1"
42+
LeasePlugin Type = "io.containerd.lease.v1"
43+
TracingProcessorPlugin Type = "io.containerd.tracing.processor.v1"
44+
)
45+
46+
func testRegistry() Registry {
4747

4848
var register Registry
49-
register = register.Register(&Registration{
49+
return register.Register(&Registration{
5050
Type: TaskMonitorPlugin,
5151
ID: "cgroups",
5252
}).Register(&Registration{
@@ -223,7 +223,11 @@ func TestContainerdPlugin(t *testing.T) {
223223
TracingProcessorPlugin,
224224
},
225225
})
226+
}
226227

228+
// TestContainerdPlugin tests the logic of Graph, use the containerd's plugin
229+
func TestContainerdPlugin(t *testing.T) {
230+
register := testRegistry()
227231
ordered := register.Graph(mockPluginFilter)
228232
expectedURI := []string{
229233
"io.containerd.monitor.v1.cgroups",
@@ -512,3 +516,22 @@ func testPlugin(t Type, id string, i interface{}, err error) *Plugin {
512516
err: err,
513517
}
514518
}
519+
520+
func BenchmarkGraph(b *testing.B) {
521+
register := testRegistry()
522+
b.ResetTimer()
523+
for i := 0; i < b.N; i++ {
524+
register.Graph(mockPluginFilter)
525+
}
526+
}
527+
528+
func BenchmarkUnique(b *testing.B) {
529+
register := testRegistry()
530+
b.ResetTimer()
531+
for i := 0; i < b.N; i++ {
532+
checkUnique(register, &Registration{
533+
Type: InternalPlugin,
534+
ID: "new",
535+
})
536+
}
537+
}

0 commit comments

Comments
 (0)