2016-02-01 19:02:41 +00:00
|
|
|
package supervisor
|
|
|
|
|
|
|
|
import (
|
2016-07-01 16:11:29 +00:00
|
|
|
"flag"
|
2016-02-01 19:02:41 +00:00
|
|
|
"os"
|
|
|
|
"sort"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/docker/containerd/runtime"
|
2016-02-29 18:48:39 +00:00
|
|
|
"github.com/docker/containerd/specs"
|
2016-02-01 19:02:41 +00:00
|
|
|
)
|
|
|
|
|
2016-06-16 21:39:19 +00:00
|
|
|
var (
|
|
|
|
runtimeTool = flag.String("runtime", "runc", "Runtime to use for this test")
|
|
|
|
)
|
|
|
|
|
2016-02-01 19:02:41 +00:00
|
|
|
type testProcess struct {
|
|
|
|
id string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *testProcess) ID() string {
|
|
|
|
return p.id
|
|
|
|
}
|
|
|
|
|
2016-06-09 20:33:26 +00:00
|
|
|
func (p *testProcess) Start() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-02-03 22:30:45 +00:00
|
|
|
func (p *testProcess) CloseStdin() error {
|
|
|
|
return nil
|
2016-02-01 19:02:41 +00:00
|
|
|
}
|
|
|
|
|
2016-02-03 22:30:45 +00:00
|
|
|
func (p *testProcess) Resize(w, h int) error {
|
|
|
|
return nil
|
2016-02-01 19:02:41 +00:00
|
|
|
}
|
|
|
|
|
2016-02-03 22:30:45 +00:00
|
|
|
func (p *testProcess) Stdio() runtime.Stdio {
|
|
|
|
return runtime.Stdio{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *testProcess) SystemPid() int {
|
|
|
|
return -1
|
2016-02-01 19:02:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p *testProcess) ExitFD() int {
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
|
2016-09-19 18:46:33 +00:00
|
|
|
func (p *testProcess) ExitStatus() (uint32, error) {
|
|
|
|
return runtime.UnknownStatus, nil
|
2016-02-01 19:02:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p *testProcess) Container() runtime.Container {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-02-29 18:48:39 +00:00
|
|
|
func (p *testProcess) Spec() specs.ProcessSpec {
|
|
|
|
return specs.ProcessSpec{}
|
2016-02-01 19:02:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p *testProcess) Signal(os.Signal) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *testProcess) Close() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-03-14 23:31:14 +00:00
|
|
|
func (p *testProcess) State() runtime.State {
|
|
|
|
return runtime.Running
|
|
|
|
}
|
|
|
|
|
2016-04-27 19:00:29 +00:00
|
|
|
func (p *testProcess) Wait() {
|
|
|
|
}
|
|
|
|
|
2016-02-01 19:02:41 +00:00
|
|
|
func TestSortProcesses(t *testing.T) {
|
|
|
|
p := []runtime.Process{
|
|
|
|
&testProcess{"ls"},
|
|
|
|
&testProcess{"other"},
|
|
|
|
&testProcess{"init"},
|
|
|
|
&testProcess{"other2"},
|
|
|
|
}
|
|
|
|
s := &processSorter{p}
|
|
|
|
sort.Sort(s)
|
|
|
|
|
|
|
|
if id := p[len(p)-1].ID(); id != "init" {
|
|
|
|
t.Fatalf("expected init but received %q", id)
|
|
|
|
}
|
|
|
|
}
|