Fix a lot of noisy logging and test warnings
This commit is contained in:
parent
62b1e1b749
commit
be3f32e962
|
@ -35,15 +35,9 @@ func TestingConfig() *Config {
|
||||||
return &Config{
|
return &Config{
|
||||||
ListenAddr: "localhost:0",
|
ListenAddr: "localhost:0",
|
||||||
NoDHT: true,
|
NoDHT: true,
|
||||||
DataDir: func() string {
|
DataDir: tempDir(),
|
||||||
ret, err := ioutil.TempDir(tempDir, "")
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return ret
|
|
||||||
}(),
|
|
||||||
DisableTrackers: true,
|
DisableTrackers: true,
|
||||||
Debug: true,
|
// Debug: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,7 +103,7 @@ func TestTorrentInitialState(t *testing.T) {
|
||||||
pieceStateChanges: pubsub.NewPubSub(),
|
pieceStateChanges: pubsub.NewPubSub(),
|
||||||
}
|
}
|
||||||
tor.chunkSize = 2
|
tor.chunkSize = 2
|
||||||
tor.storageOpener = storage.NewClient(storage.NewFileWithCompletion("/dev/null", storage.NewMapPieceCompletion()))
|
tor.storageOpener = storage.NewClient(storage.NewFileWithCompletion(tempDir(), storage.NewMapPieceCompletion()))
|
||||||
// Needed to lock for asynchronous piece verification.
|
// Needed to lock for asynchronous piece verification.
|
||||||
tor.cl = new(Client)
|
tor.cl = new(Client)
|
||||||
tor.cl.mu.Lock()
|
tor.cl.mu.Lock()
|
||||||
|
|
16
main_test.go
16
main_test.go
|
@ -7,20 +7,30 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
var tempDir string
|
// A top-level temp dir that lasts for the duration of the package tests, and
|
||||||
|
// is removed at completion.
|
||||||
|
var pkgTempDir string
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
log.SetFlags(log.LstdFlags | log.Llongfile)
|
log.SetFlags(log.LstdFlags | log.Llongfile)
|
||||||
var err error
|
var err error
|
||||||
tempDir, err = ioutil.TempDir("", "torrent.test")
|
pkgTempDir, err = ioutil.TempDir("", "torrent.test")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func tempDir() string {
|
||||||
|
ret, err := ioutil.TempDir(pkgTempDir, "")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
code := m.Run()
|
code := m.Run()
|
||||||
os.RemoveAll(tempDir)
|
os.RemoveAll(pkgTempDir)
|
||||||
// select {}
|
// select {}
|
||||||
os.Exit(code)
|
os.Exit(code)
|
||||||
}
|
}
|
||||||
|
|
7
piece.go
7
piece.go
|
@ -2,7 +2,6 @@ package torrent
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/anacrolix/missinggo/bitmap"
|
"github.com/anacrolix/missinggo/bitmap"
|
||||||
|
@ -174,13 +173,13 @@ func (p *Piece) VerifyData() {
|
||||||
if p.hashing {
|
if p.hashing {
|
||||||
target++
|
target++
|
||||||
}
|
}
|
||||||
log.Printf("target: %d", target)
|
// log.Printf("target: %d", target)
|
||||||
p.t.queuePieceCheck(p.index)
|
p.t.queuePieceCheck(p.index)
|
||||||
for p.numVerifies < target {
|
for p.numVerifies < target {
|
||||||
log.Printf("got %d verifies", p.numVerifies)
|
// log.Printf("got %d verifies", p.numVerifies)
|
||||||
p.t.cl.event.Wait()
|
p.t.cl.event.Wait()
|
||||||
}
|
}
|
||||||
log.Print("done")
|
// log.Print("done")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Piece) queuedForHash() bool {
|
func (p *Piece) queuedForHash() bool {
|
||||||
|
|
Loading…
Reference in New Issue