From 1da335f784882292fb55b25bf255ec5f45072ea4 Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Wed, 16 Oct 2013 20:10:20 +0000 Subject: [PATCH] Hack: don't run integration tests in /var/lib/docker/unit-tests; add missing cleanups in a few tests --- api_test.go | 1 + runtime_test.go | 49 ++++++++++++++++++++++++++++++++++--------------- server_test.go | 1 + z_final_test.go | 2 +- 4 files changed, 37 insertions(+), 16 deletions(-) diff --git a/api_test.go b/api_test.go index 7223411b2d..35ecf574e0 100644 --- a/api_test.go +++ b/api_test.go @@ -91,6 +91,7 @@ func TestGetInfo(t *testing.T) { func TestGetEvents(t *testing.T) { runtime := mkRuntime(t) + defer nuke(runtime) srv := &Server{ runtime: runtime, events: make([]utils.JSONMessage, 0, 64), diff --git a/runtime_test.go b/runtime_test.go index dfb6306c5f..79b39ddb89 100644 --- a/runtime_test.go +++ b/runtime_test.go @@ -74,12 +74,6 @@ func cleanup(runtime *Runtime) error { return nil } -func cleanupLast(runtime *Runtime) error { - cleanup(runtime) - runtime.deviceSet.Shutdown() - return nil -} - func layerArchive(tarfile string) (io.Reader, error) { // FIXME: need to close f somewhere f, err := os.Open(tarfile) @@ -178,11 +172,20 @@ func init() { log.Fatalf("Unable to cleanup devmapper: %s", err) } - // Make it our Store root - if runtime, err := NewRuntimeFromDirectory(unitTestStoreBase, false); err != nil { + // Setup the base runtime, which will be duplicated for each test. + // (no tests are run directly in the base) + setupBaseImage() + + // Create the "global runtime" with a long-running daemon for integration tests + spawnGlobalDaemon() + startFds, startGoroutines = utils.GetTotalUsedFds(), runtime.NumGoroutine() +} + + +func setupBaseImage() { + runtime, err := NewRuntimeFromDirectory(unitTestStoreBase, false) + if err != nil { log.Fatalf("Unable to create a runtime for tests:", err) - } else { - globalRuntime = runtime } // Create a device, which triggers the initiation of the base FS @@ -192,29 +195,45 @@ func init() { // Create the "Server" srv := &Server{ - runtime: globalRuntime, + runtime: runtime, enableCors: false, pullingPool: make(map[string]struct{}), pushingPool: make(map[string]struct{}), } + // If the unit test is not found, try to download it. - if img, err := globalRuntime.repositories.LookupImage(unitTestImageName); err != nil || img.ID != unitTestImageID { + if img, err := runtime.repositories.LookupImage(unitTestImageName); err != nil || img.ID != unitTestImageID { // Retrieve the Image if err := srv.ImagePull(unitTestImageName, "", os.Stdout, utils.NewStreamFormatter(false), nil, nil, true); err != nil { log.Fatalf("Unable to pull the test image:", err) } } +} + + +func spawnGlobalDaemon() { + if globalRuntime != nil { + utils.Debugf("Global runtime already exists. Skipping.") + return + } + globalRuntime = mkRuntime(log.New(os.Stderr, "", 0)) + srv := &Server{ + runtime: globalRuntime, + enableCors: false, + pullingPool: make(map[string]struct{}), + pushingPool: make(map[string]struct{}), + } + // Spawn a Daemon go func() { + utils.Debugf("Spawning global daemon for integration tests") if err := ListenAndServe(testDaemonProto, testDaemonAddr, srv, os.Getenv("DEBUG") != ""); err != nil { log.Fatalf("Unable to spawn the test daemon:", err) } }() - // Give some time to ListenAndServer to actually start + // FIXME: use inmem transports instead of tcp time.Sleep(time.Second) - - startFds, startGoroutines = utils.GetTotalUsedFds(), runtime.NumGoroutine() } // FIXME: test that ImagePull(json=true) send correct json output diff --git a/server_test.go b/server_test.go index ee9549d7b7..c13754b5ea 100644 --- a/server_test.go +++ b/server_test.go @@ -351,6 +351,7 @@ func TestPools(t *testing.T) { func TestLogEvent(t *testing.T) { runtime := mkRuntime(t) + defer nuke(runtime) srv := &Server{ runtime: runtime, events: make([]utils.JSONMessage, 0, 64), diff --git a/z_final_test.go b/z_final_test.go index c52f87cddb..837b5d13e6 100644 --- a/z_final_test.go +++ b/z_final_test.go @@ -11,7 +11,7 @@ func displayFdGoroutines(t *testing.T) { } func TestFinal(t *testing.T) { - cleanupLast(globalRuntime) + nuke(globalRuntime) t.Logf("Start Fds: %d, Start Goroutines: %d", startFds, startGoroutines) displayFdGoroutines(t) }