|
@@ -5,6 +5,7 @@ import (
|
|
"io/ioutil"
|
|
"io/ioutil"
|
|
"os"
|
|
"os"
|
|
"testing"
|
|
"testing"
|
|
|
|
+ "time"
|
|
|
|
|
|
"github.com/docker/libkv/store"
|
|
"github.com/docker/libkv/store"
|
|
"github.com/docker/libnetwork/config"
|
|
"github.com/docker/libnetwork/config"
|
|
@@ -34,7 +35,9 @@ func TestBoltdbBackend(t *testing.T) {
|
|
defer os.Remove(defaultLocalStoreConfig.Client.Address)
|
|
defer os.Remove(defaultLocalStoreConfig.Client.Address)
|
|
testLocalBackend(t, "", "", nil)
|
|
testLocalBackend(t, "", "", nil)
|
|
defer os.Remove("/tmp/boltdb.db")
|
|
defer os.Remove("/tmp/boltdb.db")
|
|
- testLocalBackend(t, "boltdb", "/tmp/boltdb.db", &store.Config{Bucket: "testBackend"})
|
|
|
|
|
|
+ config := &store.Config{Bucket: "testBackend", ConnectionTimeout: 3 * time.Second}
|
|
|
|
+ testLocalBackend(t, "boltdb", "/tmp/boltdb.db", config)
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
func testLocalBackend(t *testing.T, provider, url string, storeConfig *store.Config) {
|
|
func testLocalBackend(t *testing.T, provider, url string, storeConfig *store.Config) {
|
|
@@ -91,6 +94,28 @@ func OptionBoltdbWithRandomDBFile() ([]config.Option, error) {
|
|
cfgOptions := []config.Option{}
|
|
cfgOptions := []config.Option{}
|
|
cfgOptions = append(cfgOptions, config.OptionLocalKVProvider("boltdb"))
|
|
cfgOptions = append(cfgOptions, config.OptionLocalKVProvider("boltdb"))
|
|
cfgOptions = append(cfgOptions, config.OptionLocalKVProviderURL(tmp.Name()))
|
|
cfgOptions = append(cfgOptions, config.OptionLocalKVProviderURL(tmp.Name()))
|
|
- cfgOptions = append(cfgOptions, config.OptionLocalKVProviderConfig(&store.Config{Bucket: "testBackend"}))
|
|
|
|
|
|
+ sCfg := &store.Config{Bucket: "testBackend", ConnectionTimeout: 3 * time.Second}
|
|
|
|
+ cfgOptions = append(cfgOptions, config.OptionLocalKVProviderConfig(sCfg))
|
|
return cfgOptions, nil
|
|
return cfgOptions, nil
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+func TestLocalStoreLockTimeout(t *testing.T) {
|
|
|
|
+ cfgOptions, err := OptionBoltdbWithRandomDBFile()
|
|
|
|
+ if err != nil {
|
|
|
|
+ t.Fatalf("Error getting random boltdb configs %v", err)
|
|
|
|
+ }
|
|
|
|
+ ctrl, err := New(cfgOptions...)
|
|
|
|
+ if err != nil {
|
|
|
|
+ t.Fatalf("Error new controller: %v", err)
|
|
|
|
+ }
|
|
|
|
+ // Use the same boltdb file without closing the previous controller
|
|
|
|
+ _, err = New(cfgOptions...)
|
|
|
|
+ if err == nil {
|
|
|
|
+ t.Fatalf("Multiple boldtdb connection must fail")
|
|
|
|
+ }
|
|
|
|
+ store := ctrl.(*controller).localStore.KVStore()
|
|
|
|
+ if store == nil {
|
|
|
|
+ t.Fatalf("Invalid LocalStore access connection")
|
|
|
|
+ }
|
|
|
|
+ store.Close()
|
|
|
|
+}
|