| ... | ... |
@@ -87,45 +87,63 @@ func init() {
|
| 87 | 87 |
|
| 88 | 88 |
NetworkBridgeIface = unitTestNetworkBridge |
| 89 | 89 |
|
| 90 |
- // Make it our Store root |
|
| 91 |
- if runtime, err := NewRuntimeFromDirectory(unitTestStoreBase, false); err != nil {
|
|
| 92 |
- log.Fatalf("Unable to create a runtime for tests:", err)
|
|
| 93 |
- } else {
|
|
| 94 |
- globalRuntime = runtime |
|
| 95 |
- } |
|
| 90 |
+ // Setup the base runtime, which will be duplicated for each test. |
|
| 91 |
+ // (no tests are run directly in the base) |
|
| 92 |
+ setupBaseImage() |
|
| 96 | 93 |
|
| 97 |
- // Cleanup any leftover container |
|
| 98 |
- for _, container := range globalRuntime.List() {
|
|
| 99 |
- if err := globalRuntime.Destroy(container); err != nil {
|
|
| 100 |
- log.Fatalf("Error destroying leftover container: %s", err)
|
|
| 101 |
- } |
|
| 94 |
+ // Create the "global runtime" with a long-running daemon for integration tests |
|
| 95 |
+ spawnGlobalDaemon() |
|
| 96 |
+ startFds, startGoroutines = utils.GetTotalUsedFds(), runtime.NumGoroutine() |
|
| 97 |
+} |
|
| 98 |
+ |
|
| 99 |
+ |
|
| 100 |
+func setupBaseImage() {
|
|
| 101 |
+ runtime, err := NewRuntimeFromDirectory(unitTestStoreBase, false) |
|
| 102 |
+ if err != nil {
|
|
| 103 |
+ log.Fatalf("Unable to create a runtime for tests:", err)
|
|
| 102 | 104 |
} |
| 103 | 105 |
|
| 104 | 106 |
// Create the "Server" |
| 105 | 107 |
srv := &Server{
|
| 106 |
- runtime: globalRuntime, |
|
| 108 |
+ runtime: runtime, |
|
| 107 | 109 |
enableCors: false, |
| 108 | 110 |
pullingPool: make(map[string]struct{}),
|
| 109 | 111 |
pushingPool: make(map[string]struct{}),
|
| 110 | 112 |
} |
| 113 |
+ |
|
| 111 | 114 |
// If the unit test is not found, try to download it. |
| 112 |
- if img, err := globalRuntime.repositories.LookupImage(unitTestImageName); err != nil || img.ID != unitTestImageID {
|
|
| 115 |
+ if img, err := runtime.repositories.LookupImage(unitTestImageName); err != nil || img.ID != unitTestImageID {
|
|
| 113 | 116 |
// Retrieve the Image |
| 114 | 117 |
if err := srv.ImagePull(unitTestImageName, "", os.Stdout, utils.NewStreamFormatter(false), nil, nil, true); err != nil {
|
| 115 | 118 |
log.Fatalf("Unable to pull the test image:", err)
|
| 116 | 119 |
} |
| 117 | 120 |
} |
| 121 |
+} |
|
| 122 |
+ |
|
| 123 |
+ |
|
| 124 |
+func spawnGlobalDaemon() {
|
|
| 125 |
+ if globalRuntime != nil {
|
|
| 126 |
+ utils.Debugf("Global runtime already exists. Skipping.")
|
|
| 127 |
+ return |
|
| 128 |
+ } |
|
| 129 |
+ globalRuntime = mkRuntime(log.New(os.Stderr, "", 0)) |
|
| 130 |
+ srv := &Server{
|
|
| 131 |
+ runtime: globalRuntime, |
|
| 132 |
+ enableCors: false, |
|
| 133 |
+ pullingPool: make(map[string]struct{}),
|
|
| 134 |
+ pushingPool: make(map[string]struct{}),
|
|
| 135 |
+ } |
|
| 136 |
+ |
|
| 118 | 137 |
// Spawn a Daemon |
| 119 | 138 |
go func() {
|
| 139 |
+ utils.Debugf("Spawning global daemon for integration tests")
|
|
| 120 | 140 |
if err := ListenAndServe(testDaemonProto, testDaemonAddr, srv, os.Getenv("DEBUG") != ""); err != nil {
|
| 121 | 141 |
log.Fatalf("Unable to spawn the test daemon:", err)
|
| 122 | 142 |
} |
| 123 | 143 |
}() |
| 124 |
- |
|
| 125 | 144 |
// Give some time to ListenAndServer to actually start |
| 145 |
+ // FIXME: use inmem transports instead of tcp |
|
| 126 | 146 |
time.Sleep(time.Second) |
| 127 |
- |
|
| 128 |
- startFds, startGoroutines = utils.GetTotalUsedFds(), runtime.NumGoroutine() |
|
| 129 | 147 |
} |
| 130 | 148 |
|
| 131 | 149 |
// FIXME: test that ImagePull(json=true) send correct json output |