Updating tests to use controller.Stop() to cleanup states
Signed-off-by: Madhu Venugopal <madhu@docker.com>
This commit is contained in:
parent
27397dcbdf
commit
08d9578e48
5 changed files with 29 additions and 13 deletions
|
@ -92,6 +92,7 @@ func createTestNetwork(t *testing.T, network string) (libnetwork.NetworkControll
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
defer c.Stop()
|
||||||
|
|
||||||
netOption := options.Generic{
|
netOption := options.Generic{
|
||||||
netlabel.GenericData: options.Generic{
|
netlabel.GenericData: options.Generic{
|
||||||
|
@ -179,6 +180,7 @@ func TestCreateDeleteNetwork(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
defer c.Stop()
|
||||||
|
|
||||||
badBody, err := json.Marshal("bad body")
|
badBody, err := json.Marshal("bad body")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -253,6 +255,7 @@ func TestGetNetworksAndEndpoints(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
defer c.Stop()
|
||||||
|
|
||||||
ops := options.Generic{
|
ops := options.Generic{
|
||||||
netlabel.GenericData: map[string]string{
|
netlabel.GenericData: map[string]string{
|
||||||
|
@ -522,6 +525,7 @@ func TestProcGetServices(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
defer c.Stop()
|
||||||
|
|
||||||
// Create 2 networks
|
// Create 2 networks
|
||||||
netName1 := "production"
|
netName1 := "production"
|
||||||
|
@ -999,6 +1003,7 @@ func TestDetectGetNetworksInvalidQueryComposition(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
defer c.Stop()
|
||||||
|
|
||||||
vars := map[string]string{urlNwName: "x", urlNwPID: "y"}
|
vars := map[string]string{urlNwName: "x", urlNwPID: "y"}
|
||||||
_, errRsp := procGetNetworks(c, vars, nil)
|
_, errRsp := procGetNetworks(c, vars, nil)
|
||||||
|
@ -1106,6 +1111,7 @@ func TestCreateDeleteEndpoints(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
defer c.Stop()
|
||||||
|
|
||||||
nc := networkCreate{Name: "firstNet", NetworkType: bridgeNetType}
|
nc := networkCreate{Name: "firstNet", NetworkType: bridgeNetType}
|
||||||
body, err := json.Marshal(nc)
|
body, err := json.Marshal(nc)
|
||||||
|
@ -1228,6 +1234,7 @@ func TestJoinLeave(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
defer c.Stop()
|
||||||
|
|
||||||
nb, err := json.Marshal(networkCreate{Name: "network", NetworkType: bridgeNetType})
|
nb, err := json.Marshal(networkCreate{Name: "network", NetworkType: bridgeNetType})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -1667,6 +1674,7 @@ func TestHttpHandlerUninit(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
defer c.Stop()
|
||||||
|
|
||||||
h := &httpHandler{c: c}
|
h := &httpHandler{c: c}
|
||||||
h.initRouter()
|
h.initRouter()
|
||||||
|
@ -1733,6 +1741,7 @@ func TestHttpHandlerBadBody(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
defer c.Stop()
|
||||||
handleRequest := NewHTTPHandler(c)
|
handleRequest := NewHTTPHandler(c)
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", "/v1.19/networks", &localReader{beBad: true})
|
req, err := http.NewRequest("POST", "/v1.19/networks", &localReader{beBad: true})
|
||||||
|
@ -1765,6 +1774,7 @@ func TestEndToEnd(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
defer c.Stop()
|
||||||
|
|
||||||
handleRequest := NewHTTPHandler(c)
|
handleRequest := NewHTTPHandler(c)
|
||||||
|
|
||||||
|
@ -2213,6 +2223,7 @@ func TestEndToEndErrorMessage(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
defer c.Stop()
|
||||||
handleRequest := NewHTTPHandler(c)
|
handleRequest := NewHTTPHandler(c)
|
||||||
|
|
||||||
body := []byte{}
|
body := []byte{}
|
||||||
|
|
|
@ -487,6 +487,9 @@ func (c *controller) loadDriver(networkType string) (*driverData, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *controller) Stop() {
|
func (c *controller) Stop() {
|
||||||
|
if c.localStore != nil {
|
||||||
|
c.localStore.KVStore().Close()
|
||||||
|
}
|
||||||
c.stopExternalKeyListener()
|
c.stopExternalKeyListener()
|
||||||
osl.GC()
|
osl.GC()
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ func TestDriverRegistration(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
defer c.Stop()
|
||||||
err = c.(*controller).RegisterDriver(bridgeNetType, nil, driverapi.Capability{})
|
err = c.(*controller).RegisterDriver(bridgeNetType, nil, driverapi.Capability{})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("Expecting the RegisterDriver to fail for %s", bridgeNetType)
|
t.Fatalf("Expecting the RegisterDriver to fail for %s", bridgeNetType)
|
||||||
|
|
|
@ -53,7 +53,9 @@ func TestMain(m *testing.M) {
|
||||||
|
|
||||||
libnetwork.SetTestDataStore(controller, datastore.NewCustomDataStore(datastore.NewMockStore()))
|
libnetwork.SetTestDataStore(controller, datastore.NewCustomDataStore(datastore.NewMockStore()))
|
||||||
|
|
||||||
os.Exit(m.Run())
|
x := m.Run()
|
||||||
|
controller.Stop()
|
||||||
|
os.Exit(x)
|
||||||
}
|
}
|
||||||
|
|
||||||
func createController() error {
|
func createController() error {
|
||||||
|
@ -2071,12 +2073,13 @@ func TestInvalidRemoteDriver(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
controller, err := libnetwork.New()
|
ctrlr, err := libnetwork.New()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
defer ctrlr.Stop()
|
||||||
|
|
||||||
_, err = controller.NewNetwork("invalid-network-driver", "dummy",
|
_, err = ctrlr.NewNetwork("invalid-network-driver", "dummy",
|
||||||
libnetwork.NetworkOptionGeneric(getEmptyGenericOption()))
|
libnetwork.NetworkOptionGeneric(getEmptyGenericOption()))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("Expected to fail. But instead succeeded")
|
t.Fatal("Expected to fail. But instead succeeded")
|
||||||
|
|
|
@ -15,20 +15,21 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestZooKeeperBackend(t *testing.T) {
|
func TestZooKeeperBackend(t *testing.T) {
|
||||||
if err := testNewController(t, "zk", "127.0.0.1:2181"); err != nil {
|
c, err := testNewController(t, "zk", "127.0.0.1:2181")
|
||||||
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
c.Stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
func testNewController(t *testing.T, provider, url string) error {
|
func testNewController(t *testing.T, provider, url string) (NetworkController, error) {
|
||||||
cfgOptions, err := OptionBoltdbWithRandomDBFile()
|
cfgOptions, err := OptionBoltdbWithRandomDBFile()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return nil, err
|
||||||
}
|
}
|
||||||
cfgOptions = append(cfgOptions, config.OptionKVProvider(provider))
|
cfgOptions = append(cfgOptions, config.OptionKVProvider(provider))
|
||||||
cfgOptions = append(cfgOptions, config.OptionKVProviderURL(url))
|
cfgOptions = append(cfgOptions, config.OptionKVProviderURL(url))
|
||||||
_, err = New(cfgOptions...)
|
return New(cfgOptions...)
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBoltdbBackend(t *testing.T) {
|
func TestBoltdbBackend(t *testing.T) {
|
||||||
|
@ -51,6 +52,7 @@ func testLocalBackend(t *testing.T, provider, url string, storeConfig *store.Con
|
||||||
genericOption[netlabel.GenericData] = driverOptions
|
genericOption[netlabel.GenericData] = driverOptions
|
||||||
cfgOptions = append(cfgOptions, config.OptionDriverConfig("host", genericOption))
|
cfgOptions = append(cfgOptions, config.OptionDriverConfig("host", genericOption))
|
||||||
|
|
||||||
|
fmt.Printf("URL : %s\n", url)
|
||||||
ctrl, err := New(cfgOptions...)
|
ctrl, err := New(cfgOptions...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Error new controller: %v", err)
|
t.Fatalf("Error new controller: %v", err)
|
||||||
|
@ -108,14 +110,10 @@ func TestLocalStoreLockTimeout(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Error new controller: %v", err)
|
t.Fatalf("Error new controller: %v", err)
|
||||||
}
|
}
|
||||||
|
defer ctrl.Stop()
|
||||||
// Use the same boltdb file without closing the previous controller
|
// Use the same boltdb file without closing the previous controller
|
||||||
_, err = New(cfgOptions...)
|
_, err = New(cfgOptions...)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("Multiple boldtdb connection must fail")
|
t.Fatalf("Multiple boldtdb connection must fail")
|
||||||
}
|
}
|
||||||
store := ctrl.(*controller).localStore.KVStore()
|
|
||||||
if store == nil {
|
|
||||||
t.Fatalf("Invalid LocalStore access connection")
|
|
||||||
}
|
|
||||||
store.Close()
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue