-
-
Notifications
You must be signed in to change notification settings - Fork 667
Expand file tree
/
Copy pathclient-nowasm_test.go
More file actions
69 lines (63 loc) · 1.74 KB
/
Copy pathclient-nowasm_test.go
File metadata and controls
69 lines (63 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//go:build !wasm
// +build !wasm
package torrent
import (
"os"
"testing"
qt "github.com/go-quicktest/qt"
"github.com/anacrolix/torrent/internal/testutil"
"github.com/anacrolix/torrent/storage"
)
func TestBoltPieceCompletionClosedWhenClientClosed(t *testing.T) {
cfg := TestingConfig(t)
pc, err := storage.NewBoltPieceCompletion(cfg.DataDir)
qt.Assert(t, qt.IsNil(err))
ci := storage.NewFileWithCompletion(cfg.DataDir, pc)
defer ci.Close()
cfg.DefaultStorage = ci
cl, err := NewClient(cfg)
qt.Assert(t, qt.IsNil(err), qt.Commentf("%#v", err))
cl.Close()
// And again, https://github.com/anacrolix/torrent/issues/158
cl, err = NewClient(cfg)
qt.Assert(t, qt.IsNil(err))
cl.Close()
}
func TestIssue335(t *testing.T) {
dir, mi := testutil.GreetingTestTorrent()
defer func() {
err := os.RemoveAll(dir)
if err != nil {
t.Fatalf("removing torrent dummy data dir: %v", err)
}
}()
logErr := func(f func() error, msg string) {
err := f()
t.Logf("%s: %v", msg, err)
if err != nil {
t.Fail()
}
}
cfg := TestingConfig(t)
cfg.Seed = false
cfg.Debug = true
cfg.DataDir = dir
comp, err := storage.NewBoltPieceCompletion(dir)
qt.Assert(t, qt.IsNil(err))
defer logErr(comp.Close, "closing bolt piece completion")
mmapStorage := storage.NewMMapWithCompletion(dir, comp)
defer mmapStorage.Close()
cfg.DefaultStorage = mmapStorage
cl, err := NewClient(cfg)
qt.Assert(t, qt.IsNil(err))
defer cl.Close()
tor, new, err := cl.AddTorrentSpec(TorrentSpecFromMetaInfo(mi))
qt.Assert(t, qt.IsNil(err))
qt.Assert(t, qt.IsTrue(new))
qt.Assert(t, qt.IsTrue(cl.WaitAll()))
tor.Drop()
_, new, err = cl.AddTorrentSpec(TorrentSpecFromMetaInfo(mi))
qt.Assert(t, qt.IsNil(err))
qt.Assert(t, qt.IsTrue(new))
qt.Assert(t, qt.IsTrue(cl.WaitAll()))
}