Fix a lot of noisy logging and test warnings

This commit is contained in:
Matt Joiner 2017-11-07 16:00:08 +11:00
parent 62b1e1b749
commit be3f32e962
3 changed files with 21 additions and 18 deletions

View File

@ -33,17 +33,11 @@ import (
func TestingConfig() *Config {
return &Config{
ListenAddr: "localhost:0",
NoDHT: true,
DataDir: func() string {
ret, err := ioutil.TempDir(tempDir, "")
if err != nil {
panic(err)
}
return ret
}(),
ListenAddr: "localhost:0",
NoDHT: true,
DataDir: tempDir(),
DisableTrackers: true,
Debug: true,
// Debug: true,
}
}
@ -109,7 +103,7 @@ func TestTorrentInitialState(t *testing.T) {
pieceStateChanges: pubsub.NewPubSub(),
}
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.
tor.cl = new(Client)
tor.cl.mu.Lock()

View File

@ -7,20 +7,30 @@ import (
"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() {
log.SetFlags(log.LstdFlags | log.Llongfile)
var err error
tempDir, err = ioutil.TempDir("", "torrent.test")
pkgTempDir, err = ioutil.TempDir("", "torrent.test")
if err != nil {
panic(err)
}
}
func tempDir() string {
ret, err := ioutil.TempDir(pkgTempDir, "")
if err != nil {
panic(err)
}
return ret
}
func TestMain(m *testing.M) {
code := m.Run()
os.RemoveAll(tempDir)
os.RemoveAll(pkgTempDir)
// select {}
os.Exit(code)
}

View File

@ -2,7 +2,6 @@ package torrent
import (
"fmt"
"log"
"sync"
"github.com/anacrolix/missinggo/bitmap"
@ -174,13 +173,13 @@ func (p *Piece) VerifyData() {
if p.hashing {
target++
}
log.Printf("target: %d", target)
// log.Printf("target: %d", target)
p.t.queuePieceCheck(p.index)
for p.numVerifies < target {
log.Printf("got %d verifies", p.numVerifies)
// log.Printf("got %d verifies", p.numVerifies)
p.t.cl.event.Wait()
}
log.Print("done")
// log.Print("done")
}
func (p *Piece) queuedForHash() bool {