Skip to content

Commit f03ab3d

Browse files
committed
Prevent a race condition between these tests
These tests will create a directory under integtest.ShimBaseDir(). Running them in parallel will create a race condition. Signed-off-by: Kazuyoshi Kato <[email protected]>
1 parent 263a604 commit f03ab3d

File tree

1 file changed

+12
-20
lines changed

1 file changed

+12
-20
lines changed

runtime/jailer_integ_test.go

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,28 @@ const (
4040
jailerGID = 300001
4141
)
4242

43+
func assertEmptyShimDir(tb testing.TB, ns, vmID string) {
44+
_, err := os.Stat(filepath.Join(integtest.ShimBaseDir(), ns+"#"+vmID))
45+
assert.Error(tb, err)
46+
assert.True(tb, os.IsNotExist(err))
47+
48+
shimContents, err := os.ReadDir(integtest.ShimBaseDir())
49+
require.NoError(tb, err)
50+
assert.Len(tb, shimContents, 0)
51+
}
52+
4353
func TestJailer_Isolated(t *testing.T) {
4454
integtest.Prepare(t)
4555
t.Run("Without Jailer", func(t *testing.T) {
46-
t.Parallel()
4756
testJailer(t, nil)
4857
})
4958
t.Run("With Jailer", func(t *testing.T) {
50-
t.Parallel()
5159
testJailer(t, &proto.JailerConfig{
5260
UID: jailerUID,
5361
GID: jailerGID,
5462
})
5563
})
5664
t.Run("With Jailer and bind-mount", func(t *testing.T) {
57-
t.Parallel()
5865
testJailer(t, &proto.JailerConfig{
5966
UID: jailerUID,
6067
GID: jailerGID,
@@ -66,18 +73,15 @@ func TestJailer_Isolated(t *testing.T) {
6673
func TestAttachBlockDevice_Isolated(t *testing.T) {
6774
integtest.Prepare(t)
6875
t.Run("Without Jailer", func(t *testing.T) {
69-
t.Parallel()
7076
testAttachBlockDevice(t, nil)
7177
})
7278
t.Run("With Jailer", func(t *testing.T) {
73-
t.Parallel()
7479
testAttachBlockDevice(t, &proto.JailerConfig{
7580
UID: jailerUID,
7681
GID: jailerGID,
7782
})
7883
})
7984
t.Run("With Jailer and bind-mount", func(t *testing.T) {
80-
t.Parallel()
8185
testAttachBlockDevice(t, &proto.JailerConfig{
8286
UID: jailerUID,
8387
GID: jailerGID,
@@ -178,13 +182,7 @@ func testJailer(t *testing.T, jailerConfig *proto.JailerConfig) {
178182
_, err = fcClient.StopVM(ctx, &proto.StopVMRequest{VMID: vmID})
179183
require.NoError(t, err)
180184

181-
_, err = os.Stat(filepath.Join(integtest.ShimBaseDir(), "default#"+vmID))
182-
assert.Error(t, err)
183-
assert.True(t, os.IsNotExist(err))
184-
185-
shimContents, err := os.ReadDir(integtest.ShimBaseDir())
186-
require.NoError(t, err)
187-
assert.Len(t, shimContents, 0)
185+
assertEmptyShimDir(t, "default", vmID)
188186
}
189187

190188
func TestJailerCPUSet_Isolated(t *testing.T) {
@@ -288,11 +286,5 @@ func testAttachBlockDevice(tb testing.TB, jailerConfig *proto.JailerConfig) {
288286
_, err = fcClient.StopVM(ctx, &proto.StopVMRequest{VMID: vmID})
289287
require.NoError(tb, err)
290288

291-
_, err = os.Stat(filepath.Join(integtest.ShimBaseDir(), "default#"+vmID))
292-
assert.Error(tb, err)
293-
assert.True(tb, os.IsNotExist(err))
294-
295-
shimContents, err := os.ReadDir(integtest.ShimBaseDir())
296-
require.NoError(tb, err)
297-
assert.Len(tb, shimContents, 0)
289+
assertEmptyShimDir(tb, "default", vmID)
298290
}

0 commit comments

Comments
 (0)