From be3f32e962a83835977c0b7dbcb688057a279e8e Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Tue, 7 Nov 2017 16:00:08 +1100 Subject: [PATCH] Fix a lot of noisy logging and test warnings --- client_test.go | 16 +++++----------- main_test.go | 16 +++++++++++++--- piece.go | 7 +++---- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/client_test.go b/client_test.go index 539bb448..c8994b6c 100644 --- a/client_test.go +++ b/client_test.go @@ -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() diff --git a/main_test.go b/main_test.go index b86d42fc..2add01b5 100644 --- a/main_test.go +++ b/main_test.go @@ -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) } diff --git a/piece.go b/piece.go index 55e813af..d5130d7b 100644 --- a/piece.go +++ b/piece.go @@ -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 { -- 2.48.1