8 qt "github.com/frankban/quicktest"
10 "github.com/anacrolix/torrent"
11 "github.com/anacrolix/torrent/bencode"
12 "github.com/anacrolix/torrent/metainfo"
13 sqliteStorage "github.com/anacrolix/torrent/storage/sqlite"
16 func TestSqliteStorageClosed(t *testing.T) {
18 cfg := torrent.TestingConfig(t)
19 storage, err := sqliteStorage.NewDirectStorage(sqliteStorage.NewDirectStorageOpts{})
21 cfg.DefaultStorage = storage
23 c.Assert(err, qt.IsNil)
24 cl, err := torrent.NewClient(cfg)
25 c.Assert(err, qt.IsNil)
27 l, err := net.Listen("tcp", "localhost:0")
28 c.Assert(err, qt.IsNil)
30 // We need at least once piece to trigger a call to storage to determine completion state. We
31 // need non-zero content length to trigger piece hashing.
33 Pieces: make([]byte, metainfo.HashSize),
35 Files: []metainfo.FileInfo{
39 mi := metainfo.MetaInfo{}
40 mi.InfoBytes, err = bencode.Marshal(i)
41 c.Assert(err, qt.IsNil)
43 Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
50 if err != http.ErrServerClosed {
54 // Close storage prematurely.
56 tor, _, err := cl.AddTorrentSpec(&torrent.TorrentSpec{
57 InfoHash: mi.HashInfoBytes(),
58 Sources: []string{"http://" + l.Addr().String()},
60 c.Assert(err, qt.IsNil)