forked from anacrolix/torrent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client-nowasm_test.go
71 lines (65 loc) · 1.76 KB
/
client-nowasm_test.go
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
70
71
//go:build !wasm
// +build !wasm
package torrent
import (
"os"
"testing"
qt "github.com/frankban/quicktest"
"github.com/stretchr/testify/require"
"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)
require.NoError(t, err)
ci := storage.NewFileWithCompletion(cfg.DataDir, pc)
defer ci.Close()
cfg.DefaultStorage = ci
cl, err := NewClient(cfg)
require.NoError(t, err)
cl.Close()
// And again, https://github.com/anacrolix/torrent/issues/158
cl, err = NewClient(cfg)
require.NoError(t, 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)
c := qt.New(t)
c.Assert(err, qt.IsNil)
defer logErr(comp.Close, "closing bolt piece completion")
mmapStorage := storage.NewMMapWithCompletion(dir, comp)
defer logErr(mmapStorage.Close, "closing mmap storage")
cfg.DefaultStorage = mmapStorage
cl, err := NewClient(cfg)
c.Assert(err, qt.IsNil)
defer cl.Close()
tor, new, err := cl.AddTorrentSpec(TorrentSpecFromMetaInfo(mi))
c.Assert(err, qt.IsNil)
c.Assert(new, qt.IsTrue)
c.Assert(cl.WaitAll(), qt.IsTrue)
tor.Drop()
_, new, err = cl.AddTorrentSpec(TorrentSpecFromMetaInfo(mi))
c.Assert(err, qt.IsNil)
c.Assert(new, qt.IsTrue)
c.Assert(cl.WaitAll(), qt.IsTrue)
}