From b92d253d60316018d3faefc312255e26c442fe88 Mon Sep 17 00:00:00 2001 From: Alessandro Boch Date: Thu, 11 Jun 2015 14:52:24 -0700 Subject: [PATCH] Make sure sandbox files are removed after tests - and check for error on sandbox.Destroy() in tests Signed-off-by: Alessandro Boch --- libnetwork/sandbox/sandbox_test.go | 26 ++++++++++++++++++++++---- libnetwork/sandboxdata_test.go | 12 +++++++++++- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/libnetwork/sandbox/sandbox_test.go b/libnetwork/sandbox/sandbox_test.go index 6dd4d5e97d..32f89a76ed 100644 --- a/libnetwork/sandbox/sandbox_test.go +++ b/libnetwork/sandbox/sandbox_test.go @@ -65,7 +65,10 @@ func TestSandboxCreate(t *testing.T) { verifySandbox(t, s, []string{"0", "1", "2"}) runtime.LockOSThread() - s.Destroy() + err = s.Destroy() + if err != nil { + t.Fatal(err) + } verifyCleanup(t, s, true) } @@ -90,7 +93,13 @@ func TestSandboxCreateTwice(t *testing.T) { t.Fatalf("Failed to create a new sandbox: %v", err) } runtime.LockOSThread() - s.Destroy() + + err = s.Destroy() + if err != nil { + t.Fatal(err) + } + GC() + verifyCleanup(t, s, false) } func TestSandboxGC(t *testing.T) { @@ -104,7 +113,10 @@ func TestSandboxGC(t *testing.T) { t.Fatalf("Failed to create a new sandbox: %v", err) } - s.Destroy() + err = s.Destroy() + if err != nil { + t.Fatal(err) + } GC() verifyCleanup(t, s, false) @@ -168,5 +180,11 @@ func TestAddRemoveInterface(t *testing.T) { verifySandbox(t, s, []string{"1", "2", "3"}) runtime.LockOSThread() - s.Destroy() + err = s.Destroy() + if err != nil { + t.Fatal(err) + } + + GC() + verifyCleanup(t, s, false) } diff --git a/libnetwork/sandboxdata_test.go b/libnetwork/sandboxdata_test.go index 3b76326c3a..58d5a0d40a 100644 --- a/libnetwork/sandboxdata_test.go +++ b/libnetwork/sandboxdata_test.go @@ -1,6 +1,10 @@ package libnetwork -import "testing" +import ( + "testing" + + "github.com/docker/libnetwork/sandbox" +) func createEmptyCtrlr() *controller { return &controller{sandboxes: sandboxTable{}} @@ -31,6 +35,8 @@ func TestSandboxAddEmpty(t *testing.T) { if len(ctrlr.sandboxes) != 0 { t.Fatalf("controller sandboxes is not empty. len = %d", len(ctrlr.sandboxes)) } + + sandbox.GC() } func TestSandboxAddMultiPrio(t *testing.T) { @@ -90,6 +96,8 @@ func TestSandboxAddMultiPrio(t *testing.T) { if len(ctrlr.sandboxes) != 0 { t.Fatalf("controller sandboxes is not empty. len = %d", len(ctrlr.sandboxes)) } + + sandbox.GC() } func TestSandboxAddSamePrio(t *testing.T) { @@ -127,4 +135,6 @@ func TestSandboxAddSamePrio(t *testing.T) { if len(ctrlr.sandboxes) != 0 { t.Fatalf("controller sandboxes is not empty. len = %d", len(ctrlr.sandboxes)) } + + sandbox.GC() }