1 // This infernal language makes me copy conditional compilation expressions around. This test should
2 // run if sqlite storage is enabled, period.
14 qt "github.com/frankban/quicktest"
16 "github.com/anacrolix/torrent"
17 "github.com/anacrolix/torrent/bencode"
18 "github.com/anacrolix/torrent/metainfo"
19 sqliteStorage "github.com/anacrolix/torrent/storage/sqlite"
22 func TestSqliteStorageClosed(t *testing.T) {
24 cfg := torrent.TestingConfig(t)
25 storage, err := sqliteStorage.NewDirectStorage(sqliteStorage.NewDirectStorageOpts{})
27 cfg.DefaultStorage = storage
29 c.Assert(err, qt.IsNil)
30 cl, err := torrent.NewClient(cfg)
31 c.Assert(err, qt.IsNil)
33 l, err := net.Listen("tcp", "localhost:0")
34 c.Assert(err, qt.IsNil)
36 // We need at least once piece to trigger a call to storage to determine completion state. We
37 // need non-zero content length to trigger piece hashing.
39 Pieces: make([]byte, metainfo.HashSize),
41 Files: []metainfo.FileInfo{
45 mi := metainfo.MetaInfo{}
46 mi.InfoBytes, err = bencode.Marshal(i)
47 c.Assert(err, qt.IsNil)
49 Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
56 if err != http.ErrServerClosed {
60 // Close storage prematurely.
62 tor, _, err := cl.AddTorrentSpec(&torrent.TorrentSpec{
63 InfoHash: mi.HashInfoBytes(),
64 Sources: []string{"http://" + l.Addr().String()},
66 c.Assert(err, qt.IsNil)