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 TestUseSourcesSqliteStorageClosed(t *testing.T) {
18 cfg := torrent.TestingConfig(t)
19 storage, err := sqliteStorage.NewDirectStorage(sqliteStorage.NewDirectStorageOpts{})
21 cfg.DefaultStorage = storage
22 c.Assert(err, qt.IsNil)
23 cl, err := torrent.NewClient(cfg)
24 c.Assert(err, qt.IsNil)
26 l, err := net.Listen("tcp", "localhost:0")
27 c.Assert(err, qt.IsNil)
29 // We need at least once piece to trigger a call to storage to determine completion state.
30 i := metainfo.Info{Pieces: make([]byte, metainfo.HashSize)}
31 mi := metainfo.MetaInfo{}
32 mi.InfoBytes, err = bencode.Marshal(i)
33 c.Assert(err, qt.IsNil)
35 Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
42 if err != http.ErrServerClosed {
46 // Close storage prematurely.
48 tor, _, err := cl.AddTorrentSpec(&torrent.TorrentSpec{
49 InfoHash: mi.HashInfoBytes(),
50 Sources: []string{"http://" + l.Addr().String()},
52 c.Assert(err, qt.IsNil)