Skip to content

Commit e382a9c

Browse files
committed
added extra cases to Pause/Resume test
Signed-off-by: Plamen Petrov <[email protected]>
1 parent 0508a7b commit e382a9c

File tree

1 file changed

+81
-36
lines changed

1 file changed

+81
-36
lines changed

runtime/service_integ_test.go

+81-36
Original file line numberDiff line numberDiff line change
@@ -2032,8 +2032,9 @@ func TestCreateVM_Isolated(t *testing.T) {
20322032
}
20332033
}
20342034

2035-
func TestPauseResumeVM_Isolated(t *testing.T) {
2035+
func TestPauseResume(t *testing.T) {
20362036
prepareIntegTest(t)
2037+
20372038
client, err := containerd.New(containerdSockPath, containerd.WithDefaultRuntime(firecrackerRuntime))
20382039
require.NoError(t, err, "unable to create client to containerd service at %s, is containerd running?", containerdSockPath)
20392040
defer client.Close()
@@ -2045,25 +2046,74 @@ func TestPauseResumeVM_Isolated(t *testing.T) {
20452046

20462047
fcClient := fccontrol.NewFirecrackerClient(pluginClient.Client())
20472048

2048-
type subtest struct {
2049-
name string
2050-
request proto.CreateVMRequest
2051-
validate func(*testing.T, error)
2052-
stopVM bool
2053-
}
2049+
subtests := []struct {
2050+
name string
2051+
request *proto.CreateVMRequest
2052+
state func(ctx context.Context, resp *proto.CreateVMResponse)
2053+
}{
2054+
{
2055+
name: "PauseVM",
2056+
request: &proto.CreateVMRequest{},
2057+
state: func(ctx context.Context, resp *proto.CreateVMResponse) {
2058+
_, err := fcClient.PauseVM(ctx, &proto.PauseVMRequest{VMID: resp.VMID})
2059+
require.NoError(t, err)
2060+
},
2061+
},
2062+
{
2063+
name: "ResumeVM",
2064+
request: &proto.CreateVMRequest{},
2065+
state: func(ctx context.Context, resp *proto.CreateVMResponse) {
2066+
_, err := fcClient.ResumeVM(ctx, &proto.ResumeVMRequest{VMID: resp.VMID})
2067+
require.NoError(t, err)
2068+
},
2069+
},
2070+
{
2071+
name: "Consecutive PauseVM",
2072+
request: &proto.CreateVMRequest{},
2073+
state: func(ctx context.Context, resp *proto.CreateVMResponse) {
2074+
_, err := fcClient.PauseVM(ctx, &proto.PauseVMRequest{VMID: resp.VMID})
2075+
require.NoError(t, err)
20542076

2055-
subtests := []subtest{
2077+
_, err = fcClient.PauseVM(ctx, &proto.PauseVMRequest{VMID: resp.VMID})
2078+
require.NoError(t, err)
2079+
},
2080+
},
20562081
{
2057-
name: "Happy Case",
2058-
request: proto.CreateVMRequest{},
2059-
validate: func(t *testing.T, err error) {
2082+
name: "Consecutive ResumeVM",
2083+
request: &proto.CreateVMRequest{},
2084+
state: func(ctx context.Context, resp *proto.CreateVMResponse) {
2085+
_, err := fcClient.ResumeVM(ctx, &proto.ResumeVMRequest{VMID: resp.VMID})
2086+
require.NoError(t, err)
2087+
2088+
_, err = fcClient.ResumeVM(ctx, &proto.ResumeVMRequest{VMID: resp.VMID})
2089+
require.NoError(t, err)
2090+
},
2091+
},
2092+
{
2093+
name: "PauseResume",
2094+
request: &proto.CreateVMRequest{},
2095+
state: func(ctx context.Context, resp *proto.CreateVMResponse) {
2096+
_, err := fcClient.PauseVM(ctx, &proto.PauseVMRequest{VMID: resp.VMID})
2097+
require.NoError(t, err)
2098+
2099+
_, err = fcClient.ResumeVM(ctx, &proto.ResumeVMRequest{VMID: resp.VMID})
2100+
require.NoError(t, err)
2101+
},
2102+
},
2103+
{
2104+
name: "ResumePause",
2105+
request: &proto.CreateVMRequest{},
2106+
state: func(ctx context.Context, resp *proto.CreateVMResponse) {
2107+
_, err := fcClient.ResumeVM(ctx, &proto.ResumeVMRequest{VMID: resp.VMID})
2108+
require.NoError(t, err)
2109+
2110+
_, err = fcClient.PauseVM(ctx, &proto.PauseVMRequest{VMID: resp.VMID})
20602111
require.NoError(t, err)
20612112
},
2062-
stopVM: true,
20632113
},
20642114
}
20652115

2066-
runTest := func(t *testing.T, request proto.CreateVMRequest, s subtest) {
2116+
runTest := func(t *testing.T, request *proto.CreateVMRequest, state func(ctx context.Context, resp *proto.CreateVMResponse)) {
20672117
vmID := testNameToVMID(t.Name())
20682118

20692119
tempDir, err := ioutil.TempDir("", vmID)
@@ -2077,48 +2127,43 @@ func TestPauseResumeVM_Isolated(t *testing.T) {
20772127
request.LogFifoPath = logFile
20782128
request.MetricsFifoPath = metricsFile
20792129

2080-
resp, createVMErr := fcClient.CreateVM(ctx, &request)
2130+
resp, createVMErr := fcClient.CreateVM(ctx, request)
20812131

20822132
// Even CreateVM fails, the log file and the metrics file must have some data.
20832133
requireNonEmptyFifo(t, logFile)
20842134
requireNonEmptyFifo(t, metricsFile)
20852135

2086-
// Some test cases are expected to have an error, some are not.
2087-
s.validate(t, createVMErr)
2088-
2089-
_, errPause := fcClient.PauseVM(ctx, &proto.PauseVMRequest{VMID: request.VMID})
2090-
require.NoError(t, errPause)
2136+
// Run test case
2137+
state(ctx, resp)
20912138

2092-
_, errResume := fcClient.ResumeVM(ctx, &proto.ResumeVMRequest{VMID: request.VMID})
2093-
require.NoError(t, errResume)
2139+
// No VM to stop.
2140+
if createVMErr != nil {
2141+
return
2142+
}
20942143

2095-
if createVMErr == nil && s.stopVM {
2096-
// Ensure the response fields are populated correctly
2097-
assert.Equal(t, request.VMID, resp.VMID)
2144+
// Ensure the response fields are populated correctly
2145+
assert.Equal(t, request.VMID, resp.VMID)
20982146

2099-
_, err = fcClient.StopVM(ctx, &proto.StopVMRequest{VMID: request.VMID})
2100-
require.Equal(t, status.Code(err), codes.OK)
2101-
}
2147+
_, err = fcClient.StopVM(ctx, &proto.StopVMRequest{VMID: request.VMID})
2148+
require.Equal(t, status.Code(err), codes.OK)
21022149
}
21032150

2104-
for _, _s := range subtests {
2105-
s := _s
2106-
request := s.request
2107-
t.Run(s.name, func(t *testing.T) {
2108-
runTest(t, request, s)
2151+
for _, subtest := range subtests {
2152+
state := subtest.state
2153+
t.Run(subtest.name, func(t *testing.T) {
2154+
runTest(t, subtest.request, state)
21092155
})
21102156

2111-
requestWithJailer := s.request
2157+
requestWithJailer := subtest.request
21122158
requestWithJailer.JailerConfig = &proto.JailerConfig{
21132159
UID: 30000,
21142160
GID: 30000,
21152161
}
2116-
t.Run(s.name+"/Jailer", func(t *testing.T) {
2117-
runTest(t, requestWithJailer, s)
2162+
t.Run(subtest.name+"/Jailer", func(t *testing.T) {
2163+
runTest(t, requestWithJailer, state)
21182164
})
21192165
}
21202166
}
2121-
21222167
func TestAttach_Isolated(t *testing.T) {
21232168
prepareIntegTest(t)
21242169

0 commit comments

Comments
 (0)