diff --git a/app/main.go b/app/main.go index 2f3c037d..85ba3d16 100644 --- a/app/main.go +++ b/app/main.go @@ -8,6 +8,7 @@ import ( "strings" "time" + "github.com/coreos/bbolt" "github.com/gorilla/sessions" "github.com/hashicorp/logutils" "github.com/jessevdk/go-flags" @@ -150,7 +151,7 @@ func makeBoltStore(siteNames []string) store.Interface { for _, site := range siteNames { sites = append(sites, store.BoltSite{SiteID: site, FileName: fmt.Sprintf("%s/%s.db", opts.BoltPath, site)}) } - result, err := store.NewBoltDB(sites...) + result, err := store.NewBoltDB(bolt.Options{Timeout: 30 * time.Second}, sites...) if err != nil { log.Fatalf("[ERROR] can't initialize data store, %+v", err) } diff --git a/app/migrator/disqus_test.go b/app/migrator/disqus_test.go index a2ff2ce7..1c5740a6 100644 --- a/app/migrator/disqus_test.go +++ b/app/migrator/disqus_test.go @@ -6,6 +6,7 @@ import ( "testing" "time" + "github.com/coreos/bbolt" "github.com/stretchr/testify/require" "github.com/stretchr/testify/assert" @@ -14,7 +15,7 @@ import ( func TestDisqus_Import(t *testing.T) { defer os.Remove("/tmp/remark-test.db") - dataStore, err := store.NewBoltDB(store.BoltSite{FileName: "/tmp/remark-test.db", SiteID: "test"}) + dataStore, err := store.NewBoltDB(bolt.Options{}, store.BoltSite{FileName: "/tmp/remark-test.db", SiteID: "test"}) require.Nil(t, err, "create store") d := Disqus{CommentCreator: dataStore} err = d.Import(strings.NewReader(xmlTest), "test") diff --git a/app/migrator/migrator_test.go b/app/migrator/migrator_test.go index 80e081f4..203205da 100644 --- a/app/migrator/migrator_test.go +++ b/app/migrator/migrator_test.go @@ -5,6 +5,7 @@ import ( "os" "testing" + "github.com/coreos/bbolt" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -20,7 +21,7 @@ func TestMigrator_ImportDisqus(t *testing.T) { err := ioutil.WriteFile("/tmp/disqus-test.xml", []byte(xmlTest), 0600) require.Nil(t, err) - dataStore, err := store.NewBoltDB(store.BoltSite{FileName: "/tmp/remark-test.db", SiteID: "test"}) + dataStore, err := store.NewBoltDB(bolt.Options{}, store.BoltSite{FileName: "/tmp/remark-test.db", SiteID: "test"}) require.Nil(t, err, "create store") err = ImportComments(ImportParams{ @@ -48,7 +49,7 @@ func TestMigrator_ImportRemark(t *testing.T) { err := ioutil.WriteFile("/tmp/disqus-test.r42", []byte(data), 0600) require.Nil(t, err) - dataStore, err := store.NewBoltDB(store.BoltSite{FileName: "/tmp/remark-test.db", SiteID: "radio-t"}) + dataStore, err := store.NewBoltDB(bolt.Options{}, store.BoltSite{FileName: "/tmp/remark-test.db", SiteID: "radio-t"}) require.Nil(t, err, "create store") err = ImportComments(ImportParams{ diff --git a/app/migrator/remark_test.go b/app/migrator/remark_test.go index 3d243a8e..1302e195 100644 --- a/app/migrator/remark_test.go +++ b/app/migrator/remark_test.go @@ -7,6 +7,7 @@ import ( "testing" "time" + "github.com/coreos/bbolt" "github.com/stretchr/testify/assert" "github.com/umputun/remark/app/store" @@ -39,7 +40,7 @@ func TestRemark_Import(t *testing.T) { buf.WriteString(r2) os.Remove(testDb) - b, err := store.NewBoltDB(store.BoltSite{SiteID: "radio-t", FileName: testDb}) + b, err := store.NewBoltDB(bolt.Options{}, store.BoltSite{SiteID: "radio-t", FileName: testDb}) assert.Nil(t, err) r := Remark{CommentCreator: b} err = r.Import(buf, "radio-t") @@ -57,7 +58,7 @@ func TestRemark_Import(t *testing.T) { func prep(t *testing.T) *store.Service { os.Remove(testDb) - boltStore, err := store.NewBoltDB(store.BoltSite{SiteID: "radio-t", FileName: testDb}) + boltStore, err := store.NewBoltDB(bolt.Options{}, store.BoltSite{SiteID: "radio-t", FileName: testDb}) assert.Nil(t, err) b := &store.Service{Interface: boltStore} diff --git a/app/rest/api/rest_test.go b/app/rest/api/rest_test.go index d4902b41..fb247948 100644 --- a/app/rest/api/rest_test.go +++ b/app/rest/api/rest_test.go @@ -13,6 +13,7 @@ import ( "testing" "time" + "github.com/coreos/bbolt" "github.com/gorilla/sessions" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -409,7 +410,7 @@ func TestServer_FileServer(t *testing.T) { } func prep(t *testing.T) (srv *Rest, port int) { - dataStore, err := store.NewBoltDB(store.BoltSite{FileName: testDb, SiteID: "radio-t"}) + dataStore, err := store.NewBoltDB(bolt.Options{}, store.BoltSite{FileName: testDb, SiteID: "radio-t"}) require.Nil(t, err) srv = &Rest{ DataService: store.Service{Interface: dataStore, EditDuration: 5 * time.Minute}, diff --git a/app/store/bolt.go b/app/store/bolt.go index 9ae54ccf..1904d181 100644 --- a/app/store/bolt.go +++ b/app/store/bolt.go @@ -47,12 +47,12 @@ type BoltSite struct { } // NewBoltDB makes persistent boltdb-based store -func NewBoltDB(sites ...BoltSite) (*BoltDB, error) { +func NewBoltDB(options bolt.Options, sites ...BoltSite) (*BoltDB, error) { log.Printf("[INFO] bolt store for sites %+v", sites) result := BoltDB{dbs: make(map[string]*bolt.DB)} for _, site := range sites { - db, err := bolt.Open(site.FileName, 0600, &bolt.Options{Timeout: 30 * time.Second}) + db, err := bolt.Open(site.FileName, 0600, &options) // bolt.Options{Timeout: 30 * time.Second} if err != nil { return nil, errors.Wrapf(err, "failed to make boltdb for %s", site.FileName) } diff --git a/app/store/bolt_test.go b/app/store/bolt_test.go index 8664bc2f..cb24de5a 100644 --- a/app/store/bolt_test.go +++ b/app/store/bolt_test.go @@ -5,6 +5,7 @@ import ( "testing" "time" + "github.com/coreos/bbolt" "github.com/stretchr/testify/assert" ) @@ -193,7 +194,7 @@ func TestBoltDB_GetForUser(t *testing.T) { func prep(t *testing.T) *Service { os.Remove(testDb) - boltStore, err := NewBoltDB(BoltSite{FileName: "/tmp/test-remark.db", SiteID: "radio-t"}) + boltStore, err := NewBoltDB(bolt.Options{}, BoltSite{FileName: "/tmp/test-remark.db", SiteID: "radio-t"}) assert.Nil(t, err) b := &Service{Interface: boltStore} diff --git a/app/store/service_test.go b/app/store/service_test.go index 25d7da85..b10f57bc 100644 --- a/app/store/service_test.go +++ b/app/store/service_test.go @@ -5,6 +5,7 @@ import ( "testing" "time" + "github.com/coreos/bbolt" "github.com/stretchr/testify/assert" ) @@ -92,7 +93,7 @@ func TestService_EditComment(t *testing.T) { func TestService_EditCommentDurationFailed(t *testing.T) { defer os.Remove(testDb) - blt, err := NewBoltDB(BoltSite{FileName: "/tmp/test-remark.db", SiteID: "radio-t"}) + blt, err := NewBoltDB(bolt.Options{}, BoltSite{FileName: "/tmp/test-remark.db", SiteID: "radio-t"}) assert.Nil(t, err) comment := Comment{