]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Test both sqlite file and in-memory leecher storages
authorMatt Joiner <anacrolix@gmail.com>
Tue, 13 Oct 2020 02:34:05 +0000 (13:34 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Tue, 13 Oct 2020 02:34:05 +0000 (13:34 +1100)
test/transfer_test.go

index 3cd788c3b6b2372c4c837c7a45cef8c2e1a4ca1a..7462a547c53b53fa3af380373c4da99447c17750 100644 (file)
@@ -271,6 +271,29 @@ func TestClientTransferSmallCacheDefaultReadahead(t *testing.T) {
        testClientTransferSmallCache(t, false, -1)
 }
 
+func sqliteClientStorageFactory(connPathMaker func(dataDir string) string) storageFactory {
+       return func(dataDir string) storage.ClientImplCloser {
+               path := connPathMaker(dataDir)
+               log.Printf("opening sqlite db at %q", path)
+               conn, err := sqlite.OpenConn(path, 0)
+               if err != nil {
+                       panic(err)
+               }
+               prov, err := sqliteStorage.NewProvider(conn)
+               if err != nil {
+                       panic(err)
+               }
+               return struct {
+                       storage.ClientImpl
+                       io.Closer
+               }{
+                       storage.NewResourcePieces(prov),
+                       conn,
+               }
+
+       }
+}
+
 func TestClientTransferVarious(t *testing.T) {
        // Leecher storage
        for _, ls := range []struct {
@@ -281,25 +304,12 @@ func TestClientTransferVarious(t *testing.T) {
                        Wrapper: fileCachePieceResourceStorage,
                })},
                {"Boltdb", storage.NewBoltDB},
-               {"Sqlite", func(dataDir string) storage.ClientImplCloser {
-                       path := filepath.Join(dataDir, "sqlite.db")
-                       log.Printf("creating sqlite db at %q", path)
-                       conn, err := sqlite.OpenConn(fmt.Sprintf("file:%s", path), 0)
-                       if err != nil {
-                               panic(err)
-                       }
-                       prov, err := sqliteStorage.NewProvider(conn)
-                       if err != nil {
-                               panic(err)
-                       }
-                       return struct {
-                               storage.ClientImpl
-                               io.Closer
-                       }{
-                               storage.NewResourcePieces(prov),
-                               conn,
-                       }
-               }},
+               {"SqliteFile", sqliteClientStorageFactory(func(dataDir string) string {
+                       return "file:" + filepath.Join(dataDir, "sqlite.db")
+               })},
+               {"SqliteMemory", sqliteClientStorageFactory(func(dataDir string) string {
+                       return "file:memory:?mode=memory"
+               })},
        } {
                t.Run(fmt.Sprintf("LeecherStorage=%s", ls.name), func(t *testing.T) {
                        // Seeder storage