2021-06-23 07:24:50 +00:00
|
|
|
//go:build !wasm
|
2021-10-28 08:53:04 +00:00
|
|
|
// +build !wasm
|
2021-06-23 07:24:50 +00:00
|
|
|
|
|
|
|
package torrent
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
2023-05-12 03:47:47 +00:00
|
|
|
|
|
|
|
"github.com/anacrolix/torrent/internal/testutil"
|
|
|
|
"github.com/anacrolix/torrent/storage"
|
2021-06-23 07:24:50 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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())
|
|
|
|
}
|