From 7192be47c5a787094c6450b904622159c85b70de Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Wed, 20 Nov 2013 14:42:32 +0100 Subject: [PATCH 1/2] graph_test: Clean up drivers allocated in tempGraph() If we don't do this we leak devicemapper pools with the dm backend. --- graph_test.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/graph_test.go b/graph_test.go index c7b295c0e8..3d08feaf6f 100644 --- a/graph_test.go +++ b/graph_test.go @@ -16,7 +16,7 @@ import ( func TestInit(t *testing.T) { graph := tempGraph(t) - defer os.RemoveAll(graph.Root) + defer nukeGraph(graph) // Root should exist if _, err := os.Stat(graph.Root); err != nil { t.Fatal(err) @@ -32,7 +32,7 @@ func TestInit(t *testing.T) { // Test that Register can be interrupted cleanly without side effects func TestInterruptedRegister(t *testing.T) { graph := tempGraph(t) - defer os.RemoveAll(graph.Root) + defer nukeGraph(graph) badArchive, w := io.Pipe() // Use a pipe reader as a fake archive which never yields data image := &Image{ ID: GenerateID(), @@ -59,7 +59,7 @@ func TestInterruptedRegister(t *testing.T) { // create multiple, check the amount of images and paths, etc..) func TestGraphCreate(t *testing.T) { graph := tempGraph(t) - defer os.RemoveAll(graph.Root) + defer nukeGraph(graph) archive, err := fakeTar() if err != nil { t.Fatal(err) @@ -90,7 +90,7 @@ func TestGraphCreate(t *testing.T) { func TestRegister(t *testing.T) { graph := tempGraph(t) - defer os.RemoveAll(graph.Root) + defer nukeGraph(graph) archive, err := fakeTar() if err != nil { t.Fatal(err) @@ -124,7 +124,7 @@ func TestRegister(t *testing.T) { // Test that an image can be deleted by its shorthand prefix func TestDeletePrefix(t *testing.T) { graph := tempGraph(t) - defer os.RemoveAll(graph.Root) + defer nukeGraph(graph) img := createTestImage(graph, t) if err := graph.Delete(utils.TruncateID(img.ID)); err != nil { t.Fatal(err) @@ -146,7 +146,7 @@ func createTestImage(graph *Graph, t *testing.T) *Image { func TestDelete(t *testing.T) { graph := tempGraph(t) - defer os.RemoveAll(graph.Root) + defer nukeGraph(graph) archive, err := fakeTar() if err != nil { t.Fatal(err) @@ -210,7 +210,7 @@ func TestByParent(t *testing.T) { archive3, _ := fakeTar() graph := tempGraph(t) - defer os.RemoveAll(graph.Root) + defer nukeGraph(graph) parentImage := &Image{ ID: GenerateID(), Comment: "parent", @@ -271,6 +271,11 @@ func tempGraph(t *testing.T) *Graph { return graph } +func nukeGraph(graph *Graph) { + graph.driver.Cleanup() + os.RemoveAll(graph.Root) +} + func testArchive(t *testing.T) archive.Archive { archive, err := fakeTar() if err != nil { From cfdc284abee59057d6c6f7bc751d5648d8f8688e Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Wed, 20 Nov 2013 14:52:06 +0100 Subject: [PATCH 2/2] tags test: cleanup driver If not we leak a devicemapper pool --- tags_unit_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/tags_unit_test.go b/tags_unit_test.go index bd8622d46d..1341b989fe 100644 --- a/tags_unit_test.go +++ b/tags_unit_test.go @@ -47,6 +47,7 @@ func TestLookupImage(t *testing.T) { } defer os.RemoveAll(tmp) store := mkTestTagStore(tmp, t) + defer store.graph.driver.Cleanup() if img, err := store.LookupImage(testImageName); err != nil { t.Fatal(err)