summaryrefslogtreecommitdiff
path: root/libpod/container_graph_test.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2019-01-04 10:41:05 -0800
committerGitHub <noreply@github.com>2019-01-04 10:41:05 -0800
commitbf5f779331870d31863c486619daae3fcea458eb (patch)
treeaafcacc17883a8df4734bed0aadbaca59a9882fe /libpod/container_graph_test.go
parent6868b5aa1444404113bc6a4582203fbbf89490c2 (diff)
parent56c5c89408f89fc3733692786d66eb44133b2c59 (diff)
downloadpodman-bf5f779331870d31863c486619daae3fcea458eb.tar.gz
podman-bf5f779331870d31863c486619daae3fcea458eb.tar.bz2
podman-bf5f779331870d31863c486619daae3fcea458eb.zip
Merge pull request #1235 from mheon/shm_locking
SHM locking for Libpod
Diffstat (limited to 'libpod/container_graph_test.go')
-rw-r--r--libpod/container_graph_test.go160
1 files changed, 87 insertions, 73 deletions
diff --git a/libpod/container_graph_test.go b/libpod/container_graph_test.go
index 25461f1f4..d1a52658d 100644
--- a/libpod/container_graph_test.go
+++ b/libpod/container_graph_test.go
@@ -1,10 +1,9 @@
package libpod
import (
- "io/ioutil"
- "os"
"testing"
+ "github.com/containers/libpod/libpod/lock"
"github.com/stretchr/testify/assert"
)
@@ -17,11 +16,12 @@ func TestBuildContainerGraphNoCtrsIsEmpty(t *testing.T) {
}
func TestBuildContainerGraphOneCtr(t *testing.T) {
- tmpDir, err := ioutil.TempDir("", tmpDirPrefix)
- assert.NoError(t, err)
- defer os.RemoveAll(tmpDir)
+ manager, err := lock.NewInMemoryManager(16)
+ if err != nil {
+ t.Fatalf("Error setting up locks: %v", err)
+ }
- ctr1, err := getTestCtr1(tmpDir)
+ ctr1, err := getTestCtr1(manager)
assert.NoError(t, err)
graph, err := buildContainerGraph([]*Container{ctr1})
@@ -39,13 +39,14 @@ func TestBuildContainerGraphOneCtr(t *testing.T) {
}
func TestBuildContainerGraphTwoCtrNoEdge(t *testing.T) {
- tmpDir, err := ioutil.TempDir("", tmpDirPrefix)
- assert.NoError(t, err)
- defer os.RemoveAll(tmpDir)
+ manager, err := lock.NewInMemoryManager(16)
+ if err != nil {
+ t.Fatalf("Error setting up locks: %v", err)
+ }
- ctr1, err := getTestCtr1(tmpDir)
+ ctr1, err := getTestCtr1(manager)
assert.NoError(t, err)
- ctr2, err := getTestCtr2(tmpDir)
+ ctr2, err := getTestCtr2(manager)
assert.NoError(t, err)
graph, err := buildContainerGraph([]*Container{ctr1, ctr2})
@@ -64,13 +65,14 @@ func TestBuildContainerGraphTwoCtrNoEdge(t *testing.T) {
}
func TestBuildContainerGraphTwoCtrOneEdge(t *testing.T) {
- tmpDir, err := ioutil.TempDir("", tmpDirPrefix)
- assert.NoError(t, err)
- defer os.RemoveAll(tmpDir)
+ manager, err := lock.NewInMemoryManager(16)
+ if err != nil {
+ t.Fatalf("Error setting up locks: %v", err)
+ }
- ctr1, err := getTestCtr1(tmpDir)
+ ctr1, err := getTestCtr1(manager)
assert.NoError(t, err)
- ctr2, err := getTestCtr2(tmpDir)
+ ctr2, err := getTestCtr2(manager)
assert.NoError(t, err)
ctr2.config.UserNsCtr = ctr1.config.ID
@@ -85,13 +87,14 @@ func TestBuildContainerGraphTwoCtrOneEdge(t *testing.T) {
}
func TestBuildContainerGraphTwoCtrCycle(t *testing.T) {
- tmpDir, err := ioutil.TempDir("", tmpDirPrefix)
- assert.NoError(t, err)
- defer os.RemoveAll(tmpDir)
+ manager, err := lock.NewInMemoryManager(16)
+ if err != nil {
+ t.Fatalf("Error setting up locks: %v", err)
+ }
- ctr1, err := getTestCtr1(tmpDir)
+ ctr1, err := getTestCtr1(manager)
assert.NoError(t, err)
- ctr2, err := getTestCtr2(tmpDir)
+ ctr2, err := getTestCtr2(manager)
assert.NoError(t, err)
ctr2.config.UserNsCtr = ctr1.config.ID
ctr1.config.NetNsCtr = ctr2.config.ID
@@ -101,15 +104,16 @@ func TestBuildContainerGraphTwoCtrCycle(t *testing.T) {
}
func TestBuildContainerGraphThreeCtrNoEdges(t *testing.T) {
- tmpDir, err := ioutil.TempDir("", tmpDirPrefix)
- assert.NoError(t, err)
- defer os.RemoveAll(tmpDir)
+ manager, err := lock.NewInMemoryManager(16)
+ if err != nil {
+ t.Fatalf("Error setting up locks: %v", err)
+ }
- ctr1, err := getTestCtr1(tmpDir)
+ ctr1, err := getTestCtr1(manager)
assert.NoError(t, err)
- ctr2, err := getTestCtr2(tmpDir)
+ ctr2, err := getTestCtr2(manager)
assert.NoError(t, err)
- ctr3, err := getTestCtrN("3", tmpDir)
+ ctr3, err := getTestCtrN("3", manager)
assert.NoError(t, err)
graph, err := buildContainerGraph([]*Container{ctr1, ctr2, ctr3})
@@ -132,15 +136,16 @@ func TestBuildContainerGraphThreeCtrNoEdges(t *testing.T) {
}
func TestBuildContainerGraphThreeContainersTwoInCycle(t *testing.T) {
- tmpDir, err := ioutil.TempDir("", tmpDirPrefix)
- assert.NoError(t, err)
- defer os.RemoveAll(tmpDir)
+ manager, err := lock.NewInMemoryManager(16)
+ if err != nil {
+ t.Fatalf("Error setting up locks: %v", err)
+ }
- ctr1, err := getTestCtr1(tmpDir)
+ ctr1, err := getTestCtr1(manager)
assert.NoError(t, err)
- ctr2, err := getTestCtr2(tmpDir)
+ ctr2, err := getTestCtr2(manager)
assert.NoError(t, err)
- ctr3, err := getTestCtrN("3", tmpDir)
+ ctr3, err := getTestCtrN("3", manager)
assert.NoError(t, err)
ctr1.config.UserNsCtr = ctr2.config.ID
ctr2.config.IPCNsCtr = ctr1.config.ID
@@ -150,15 +155,16 @@ func TestBuildContainerGraphThreeContainersTwoInCycle(t *testing.T) {
}
func TestBuildContainerGraphThreeContainersCycle(t *testing.T) {
- tmpDir, err := ioutil.TempDir("", tmpDirPrefix)
- assert.NoError(t, err)
- defer os.RemoveAll(tmpDir)
+ manager, err := lock.NewInMemoryManager(16)
+ if err != nil {
+ t.Fatalf("Error setting up locks: %v", err)
+ }
- ctr1, err := getTestCtr1(tmpDir)
+ ctr1, err := getTestCtr1(manager)
assert.NoError(t, err)
- ctr2, err := getTestCtr2(tmpDir)
+ ctr2, err := getTestCtr2(manager)
assert.NoError(t, err)
- ctr3, err := getTestCtrN("3", tmpDir)
+ ctr3, err := getTestCtrN("3", manager)
assert.NoError(t, err)
ctr1.config.UserNsCtr = ctr2.config.ID
ctr2.config.IPCNsCtr = ctr3.config.ID
@@ -169,15 +175,16 @@ func TestBuildContainerGraphThreeContainersCycle(t *testing.T) {
}
func TestBuildContainerGraphThreeContainersNoCycle(t *testing.T) {
- tmpDir, err := ioutil.TempDir("", tmpDirPrefix)
- assert.NoError(t, err)
- defer os.RemoveAll(tmpDir)
+ manager, err := lock.NewInMemoryManager(16)
+ if err != nil {
+ t.Fatalf("Error setting up locks: %v", err)
+ }
- ctr1, err := getTestCtr1(tmpDir)
+ ctr1, err := getTestCtr1(manager)
assert.NoError(t, err)
- ctr2, err := getTestCtr2(tmpDir)
+ ctr2, err := getTestCtr2(manager)
assert.NoError(t, err)
- ctr3, err := getTestCtrN("3", tmpDir)
+ ctr3, err := getTestCtrN("3", manager)
assert.NoError(t, err)
ctr1.config.UserNsCtr = ctr2.config.ID
ctr1.config.NetNsCtr = ctr3.config.ID
@@ -194,17 +201,18 @@ func TestBuildContainerGraphThreeContainersNoCycle(t *testing.T) {
}
func TestBuildContainerGraphFourContainersNoEdges(t *testing.T) {
- tmpDir, err := ioutil.TempDir("", tmpDirPrefix)
- assert.NoError(t, err)
- defer os.RemoveAll(tmpDir)
+ manager, err := lock.NewInMemoryManager(16)
+ if err != nil {
+ t.Fatalf("Error setting up locks: %v", err)
+ }
- ctr1, err := getTestCtr1(tmpDir)
+ ctr1, err := getTestCtr1(manager)
assert.NoError(t, err)
- ctr2, err := getTestCtr2(tmpDir)
+ ctr2, err := getTestCtr2(manager)
assert.NoError(t, err)
- ctr3, err := getTestCtrN("3", tmpDir)
+ ctr3, err := getTestCtrN("3", manager)
assert.NoError(t, err)
- ctr4, err := getTestCtrN("4", tmpDir)
+ ctr4, err := getTestCtrN("4", manager)
assert.NoError(t, err)
graph, err := buildContainerGraph([]*Container{ctr1, ctr2, ctr3, ctr4})
@@ -231,18 +239,20 @@ func TestBuildContainerGraphFourContainersNoEdges(t *testing.T) {
}
func TestBuildContainerGraphFourContainersTwoInCycle(t *testing.T) {
- tmpDir, err := ioutil.TempDir("", tmpDirPrefix)
- assert.NoError(t, err)
- defer os.RemoveAll(tmpDir)
+ manager, err := lock.NewInMemoryManager(16)
+ if err != nil {
+ t.Fatalf("Error setting up locks: %v", err)
+ }
- ctr1, err := getTestCtr1(tmpDir)
+ ctr1, err := getTestCtr1(manager)
assert.NoError(t, err)
- ctr2, err := getTestCtr2(tmpDir)
+ ctr2, err := getTestCtr2(manager)
assert.NoError(t, err)
- ctr3, err := getTestCtrN("3", tmpDir)
+ ctr3, err := getTestCtrN("3", manager)
assert.NoError(t, err)
- ctr4, err := getTestCtrN("4", tmpDir)
+ ctr4, err := getTestCtrN("4", manager)
assert.NoError(t, err)
+
ctr1.config.IPCNsCtr = ctr2.config.ID
ctr2.config.UserNsCtr = ctr1.config.ID
@@ -251,18 +261,20 @@ func TestBuildContainerGraphFourContainersTwoInCycle(t *testing.T) {
}
func TestBuildContainerGraphFourContainersAllInCycle(t *testing.T) {
- tmpDir, err := ioutil.TempDir("", tmpDirPrefix)
- assert.NoError(t, err)
- defer os.RemoveAll(tmpDir)
+ manager, err := lock.NewInMemoryManager(16)
+ if err != nil {
+ t.Fatalf("Error setting up locks: %v", err)
+ }
- ctr1, err := getTestCtr1(tmpDir)
+ ctr1, err := getTestCtr1(manager)
assert.NoError(t, err)
- ctr2, err := getTestCtr2(tmpDir)
+ ctr2, err := getTestCtr2(manager)
assert.NoError(t, err)
- ctr3, err := getTestCtrN("3", tmpDir)
+ ctr3, err := getTestCtrN("3", manager)
assert.NoError(t, err)
- ctr4, err := getTestCtrN("4", tmpDir)
+ ctr4, err := getTestCtrN("4", manager)
assert.NoError(t, err)
+
ctr1.config.IPCNsCtr = ctr2.config.ID
ctr2.config.UserNsCtr = ctr3.config.ID
ctr3.config.NetNsCtr = ctr4.config.ID
@@ -273,18 +285,20 @@ func TestBuildContainerGraphFourContainersAllInCycle(t *testing.T) {
}
func TestBuildContainerGraphFourContainersNoneInCycle(t *testing.T) {
- tmpDir, err := ioutil.TempDir("", tmpDirPrefix)
- assert.NoError(t, err)
- defer os.RemoveAll(tmpDir)
+ manager, err := lock.NewInMemoryManager(16)
+ if err != nil {
+ t.Fatalf("Error setting up locks: %v", err)
+ }
- ctr1, err := getTestCtr1(tmpDir)
+ ctr1, err := getTestCtr1(manager)
assert.NoError(t, err)
- ctr2, err := getTestCtr2(tmpDir)
+ ctr2, err := getTestCtr2(manager)
assert.NoError(t, err)
- ctr3, err := getTestCtrN("3", tmpDir)
+ ctr3, err := getTestCtrN("3", manager)
assert.NoError(t, err)
- ctr4, err := getTestCtrN("4", tmpDir)
+ ctr4, err := getTestCtrN("4", manager)
assert.NoError(t, err)
+
ctr1.config.IPCNsCtr = ctr2.config.ID
ctr1.config.NetNsCtr = ctr3.config.ID
ctr2.config.UserNsCtr = ctr3.config.ID