From 7032acc12cbb69bfe294bdd59796ec3d4c0a2b6a Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Wed, 20 Nov 2013 14:42:32 +0100 Subject: [PATCH] graph_test: Clean up drivers allocated in tempGraph() If we don't do this we leak devicemapper pools with the dm backend. Upstream-commit: 7192be47c5a787094c6450b904622159c85b70de Component: engine --- components/engine/graph_test.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/components/engine/graph_test.go b/components/engine/graph_test.go index c7b295c0e8..3d08feaf6f 100644 --- a/components/engine/graph_test.go +++ b/components/engine/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 {