libnetwork to make use of boltdb ConnectionTimeout to avoid deadlock
Signed-off-by: Madhu Venugopal <madhu@docker.com>
This commit is contained in:
parent
dd6b8cb408
commit
27397dcbdf
|
@ -3,6 +3,7 @@ package libnetwork
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
"github.com/docker/libkv/store"
|
"github.com/docker/libkv/store"
|
||||||
|
@ -11,13 +12,15 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
defaultBoltTimeout = 3 * time.Second
|
||||||
defaultLocalStoreConfig = config.DatastoreCfg{
|
defaultLocalStoreConfig = config.DatastoreCfg{
|
||||||
Embedded: true,
|
Embedded: true,
|
||||||
Client: config.DatastoreClientCfg{
|
Client: config.DatastoreClientCfg{
|
||||||
Provider: "boltdb",
|
Provider: "boltdb",
|
||||||
Address: defaultPrefix + "/boltdb.db",
|
Address: defaultPrefix + "/boltdb.db",
|
||||||
Config: &store.Config{
|
Config: &store.Config{
|
||||||
Bucket: "libnetwork",
|
Bucket: "libnetwork",
|
||||||
|
ConnectionTimeout: defaultBoltTimeout,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -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()
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue