forked from anacrolix/torrent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client-nowasm_test.go
55 lines (50 loc) · 1.38 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
//go:build !wasm
// +build !wasm
package torrent
import (
"os"
"testing"
"github.com/anacrolix/torrent/internal/testutil"
"github.com/anacrolix/torrent/storage"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
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 os.RemoveAll(dir)
cfg := TestingConfig(t)
cfg.Seed = false
cfg.Debug = true
cfg.DataDir = dir
comp, err := storage.NewBoltPieceCompletion(dir)
require.NoError(t, err)
defer comp.Close()
cfg.DefaultStorage = storage.NewMMapWithCompletion(dir, comp)
cl, err := NewClient(cfg)
require.NoError(t, err)
defer cl.Close()
tor, new, err := cl.AddTorrentSpec(TorrentSpecFromMetaInfo(mi))
require.NoError(t, err)
assert.True(t, new)
require.True(t, cl.WaitAll())
tor.Drop()
_, new, err = cl.AddTorrentSpec(TorrentSpecFromMetaInfo(mi))
require.NoError(t, err)
assert.True(t, new)
require.True(t, cl.WaitAll())
}