Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (registry Registry) Graph(filter DisableFilter) []Registration {
func children(reg *Registration, registry []*Registration, added, disabled map[*Registration]bool, ordered *[]Registration) {
for _, t := range reg.Requires {
for _, r := range registry {
if !disabled[r] && r.URI() != reg.URI() && (t == "*" || r.Type == t) {
if (t == "*" || r.Type == t) && r != reg && !disabled[r] {
children(r, registry, added, disabled, ordered)
if !added[r] {
*ordered = append(*ordered, *r)
Expand Down Expand Up @@ -170,7 +170,7 @@ func (registry Registry) Register(r *Registration) Registry {

func checkUnique(registry Registry, r *Registration) error {
for _, registered := range registry {
if r.URI() == registered.URI() {
if r.Type == registered.Type && r.ID == registered.ID {
return fmt.Errorf("%s: %w", r.URI(), ErrIDRegistered)
}
}
Expand Down
61 changes: 42 additions & 19 deletions plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,27 @@ func mockPluginFilter(*Registration) bool {
return false
}

// TestContainerdPlugin tests the logic of Graph, use the containerd's plugin
func TestContainerdPlugin(t *testing.T) {
// Plugin types commonly used by containerd
const (
InternalPlugin Type = "io.containerd.internal.v1"
RuntimePlugin Type = "io.containerd.runtime.v1"
RuntimePluginV2 Type = "io.containerd.runtime.v2"
ServicePlugin Type = "io.containerd.service.v1"
GRPCPlugin Type = "io.containerd.grpc.v1"
SnapshotPlugin Type = "io.containerd.snapshotter.v1"
TaskMonitorPlugin Type = "io.containerd.monitor.v1"
DiffPlugin Type = "io.containerd.differ.v1"
MetadataPlugin Type = "io.containerd.metadata.v1"
ContentPlugin Type = "io.containerd.content.v1"
GCPlugin Type = "io.containerd.gc.v1"
LeasePlugin Type = "io.containerd.lease.v1"
TracingProcessorPlugin Type = "io.containerd.tracing.processor.v1"
)
// Plugin types commonly used by containerd
const (
InternalPlugin Type = "io.containerd.internal.v1"
RuntimePlugin Type = "io.containerd.runtime.v1"
RuntimePluginV2 Type = "io.containerd.runtime.v2"
ServicePlugin Type = "io.containerd.service.v1"
GRPCPlugin Type = "io.containerd.grpc.v1"
SnapshotPlugin Type = "io.containerd.snapshotter.v1"
TaskMonitorPlugin Type = "io.containerd.monitor.v1"
DiffPlugin Type = "io.containerd.differ.v1"
MetadataPlugin Type = "io.containerd.metadata.v1"
ContentPlugin Type = "io.containerd.content.v1"
GCPlugin Type = "io.containerd.gc.v1"
LeasePlugin Type = "io.containerd.lease.v1"
TracingProcessorPlugin Type = "io.containerd.tracing.processor.v1"
)

func testRegistry() Registry {

var register Registry
register = register.Register(&Registration{
return register.Register(&Registration{
Type: TaskMonitorPlugin,
ID: "cgroups",
}).Register(&Registration{
Expand Down Expand Up @@ -223,7 +223,11 @@ func TestContainerdPlugin(t *testing.T) {
TracingProcessorPlugin,
},
})
}

// TestContainerdPlugin tests the logic of Graph, use the containerd's plugin
func TestContainerdPlugin(t *testing.T) {
register := testRegistry()
ordered := register.Graph(mockPluginFilter)
expectedURI := []string{
"io.containerd.monitor.v1.cgroups",
Expand Down Expand Up @@ -512,3 +516,22 @@ func testPlugin(t Type, id string, i interface{}, err error) *Plugin {
err: err,
}
}

func BenchmarkGraph(b *testing.B) {
register := testRegistry()
b.ResetTimer()
for i := 0; i < b.N; i++ {
register.Graph(mockPluginFilter)
}
}

func BenchmarkUnique(b *testing.B) {
register := testRegistry()
b.ResetTimer()
for i := 0; i < b.N; i++ {
checkUnique(register, &Registration{
Type: InternalPlugin,
ID: "new",
})
}
}
Loading