1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Hack: don't run integration tests in /var/lib/docker/unit-tests; add missing cleanups in a few tests

This commit is contained in:
Solomon Hykes 2013-10-16 20:10:20 +00:00
parent 95ccb78aa7
commit 240d5b3fa1
4 changed files with 42 additions and 22 deletions

View file

@ -112,6 +112,7 @@ func TestGetInfo(t *testing.T) {
func TestGetEvents(t *testing.T) { func TestGetEvents(t *testing.T) {
runtime := mkRuntime(t) runtime := mkRuntime(t)
defer nuke(runtime)
srv := &Server{ srv := &Server{
runtime: runtime, runtime: runtime,
events: make([]utils.JSONMessage, 0, 64), events: make([]utils.JSONMessage, 0, 64),

View file

@ -87,45 +87,63 @@ func init() {
NetworkBridgeIface = unitTestNetworkBridge NetworkBridgeIface = unitTestNetworkBridge
// Make it our Store root // Setup the base runtime, which will be duplicated for each test.
if runtime, err := NewRuntimeFromDirectory(unitTestStoreBase, false); err != nil { // (no tests are run directly in the base)
log.Fatalf("Unable to create a runtime for tests:", err) setupBaseImage()
} else {
globalRuntime = runtime
}
// Cleanup any leftover container // Create the "global runtime" with a long-running daemon for integration tests
for _, container := range globalRuntime.List() { spawnGlobalDaemon()
if err := globalRuntime.Destroy(container); err != nil { startFds, startGoroutines = utils.GetTotalUsedFds(), runtime.NumGoroutine()
log.Fatalf("Error destroying leftover container: %s", err) }
}
func setupBaseImage() {
runtime, err := NewRuntimeFromDirectory(unitTestStoreBase, false)
if err != nil {
log.Fatalf("Unable to create a runtime for tests:", err)
} }
// Create the "Server" // Create the "Server"
srv := &Server{
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 := 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{ srv := &Server{
runtime: globalRuntime, runtime: globalRuntime,
enableCors: false, enableCors: false,
pullingPool: make(map[string]struct{}), pullingPool: make(map[string]struct{}),
pushingPool: 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 {
// 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)
}
}
// Spawn a Daemon // Spawn a Daemon
go func() { go func() {
utils.Debugf("Spawning global daemon for integration tests")
if err := ListenAndServe(testDaemonProto, testDaemonAddr, srv, os.Getenv("DEBUG") != ""); err != nil { if err := ListenAndServe(testDaemonProto, testDaemonAddr, srv, os.Getenv("DEBUG") != ""); err != nil {
log.Fatalf("Unable to spawn the test daemon:", err) log.Fatalf("Unable to spawn the test daemon:", err)
} }
}() }()
// Give some time to ListenAndServer to actually start // Give some time to ListenAndServer to actually start
// FIXME: use inmem transports instead of tcp
time.Sleep(time.Second) time.Sleep(time.Second)
startFds, startGoroutines = utils.GetTotalUsedFds(), runtime.NumGoroutine()
} }
// FIXME: test that ImagePull(json=true) send correct json output // FIXME: test that ImagePull(json=true) send correct json output

View file

@ -351,6 +351,7 @@ func TestPools(t *testing.T) {
func TestLogEvent(t *testing.T) { func TestLogEvent(t *testing.T) {
runtime := mkRuntime(t) runtime := mkRuntime(t)
defer nuke(runtime)
srv := &Server{ srv := &Server{
runtime: runtime, runtime: runtime,
events: make([]utils.JSONMessage, 0, 64), events: make([]utils.JSONMessage, 0, 64),

View file

@ -11,7 +11,7 @@ func displayFdGoroutines(t *testing.T) {
} }
func TestFinal(t *testing.T) { func TestFinal(t *testing.T) {
cleanup(globalRuntime) nuke(globalRuntime)
t.Logf("Start Fds: %d, Start Goroutines: %d", startFds, startGoroutines) t.Logf("Start Fds: %d, Start Goroutines: %d", startFds, startGoroutines)
displayFdGoroutines(t) displayFdGoroutines(t)
} }