Skip to content

Commit 0f65c57

Browse files
author
Zhou Hao
authored
Merge pull request #607 from liangchenye/kill
add test case for KillNonCreateRunHaveNoEffect
2 parents 14d1be7 + 0ddb5cd commit 0f65c57

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

Diff for: validation/kill.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func main() {
4949
// kill a created
5050
{stoppedConfig, containerID, util.LifecycleActionCreate | util.LifecycleActionDelete, true, specerror.NewError(specerror.KillSignalImplement, fmt.Errorf("`kill` operation MUST send the specified signal to the container process"), rspecs.Version)},
5151
// kill a stopped
52-
{stoppedConfig, containerID, util.LifecycleActionCreate | util.LifecycleActionStart | util.LifecycleActionDelete, false, specerror.NewError(specerror.KillSignalImplement, fmt.Errorf("`kill` operation MUST send the specified signal to the container process"), rspecs.Version)},
52+
{stoppedConfig, containerID, util.LifecycleActionCreate | util.LifecycleActionStart | util.LifecycleActionDelete, false, specerror.NewError(specerror.KillNonCreateRunGenError, fmt.Errorf("attempting to send a signal to a container that is neither `created` nor `running` MUST generate an error"), rspecs.Version)},
5353
// kill a running
5454
{runningConfig, containerID, util.LifecycleActionCreate | util.LifecycleActionStart | util.LifecycleActionDelete, true, specerror.NewError(specerror.KillSignalImplement, fmt.Errorf("`kill` operation MUST send the specified signal to the container process"), rspecs.Version)},
5555
}

Diff for: validation/kill_no_effect.go

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"reflect"
7+
"time"
8+
9+
"github.com/mndrix/tap-go"
10+
rspecs "github.com/opencontainers/runtime-spec/specs-go"
11+
"github.com/opencontainers/runtime-tools/specerror"
12+
"github.com/opencontainers/runtime-tools/validation/util"
13+
uuid "github.com/satori/go.uuid"
14+
)
15+
16+
func main() {
17+
t := tap.New()
18+
t.Header(0)
19+
bundleDir, err := util.PrepareBundle()
20+
if err != nil {
21+
util.Fatal(err)
22+
}
23+
defer os.RemoveAll(bundleDir)
24+
25+
targetErr := specerror.NewError(specerror.KillNonCreateRunHaveNoEffect, fmt.Errorf("attempting to send a signal to a container that is neither `created` nor `running` MUST have no effect on the container"), rspecs.Version)
26+
containerID := uuid.NewV4().String()
27+
g := util.GetDefaultGenerator()
28+
g.SetProcessArgs([]string{"true"})
29+
30+
config := util.LifecycleConfig{
31+
Config: g,
32+
BundleDir: bundleDir,
33+
Actions: util.LifecycleActionCreate | util.LifecycleActionStart | util.LifecycleActionDelete,
34+
PreCreate: func(r *util.Runtime) error {
35+
r.SetID(containerID)
36+
return nil
37+
},
38+
PreDelete: func(r *util.Runtime) error {
39+
err := util.WaitingForStatus(*r, util.LifecycleStatusStopped, time.Second*5, time.Second*1)
40+
if err != nil {
41+
return err
42+
}
43+
currentState, err := r.State()
44+
if err != nil {
45+
return err
46+
}
47+
r.Kill("KILL")
48+
newState, err := r.State()
49+
if err != nil || !reflect.DeepEqual(newState, currentState) {
50+
return targetErr
51+
}
52+
return nil
53+
},
54+
}
55+
err = util.RuntimeLifecycleValidate(config)
56+
if err != nil && err != targetErr {
57+
util.Fatal(err)
58+
} else {
59+
util.SpecErrorOK(t, err == nil, targetErr, nil)
60+
}
61+
t.AutoPlan()
62+
}

0 commit comments

Comments
 (0)