client_test.go | 16 +++++----------- main_test.go | 16 +++++++++++++--- piece.go | 7 +++---- diff --git a/client_test.go b/client_test.go index 539bb4480382ca6b00a5bb7264e0643dab12458e..c8994b6c08a1e87ca46327f12302b89d8128ca47 100644 --- a/client_test.go +++ b/client_test.go @@ -33,17 +33,11 @@ ) 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 @@ infoHash: mi.HashInfoBytes(), 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 b86d42fc101307b664538d689dab30d6abd9f3ab..2add01b53c43acfb8156bbf4c96310f2d910eaec 100644 --- a/main_test.go +++ b/main_test.go @@ -7,20 +7,30 @@ "os" "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 55e813af572e2438ce658a9a51e2ebbe4890ea04..d5130d7b734d20bb45b075fc3b1eb15de5ba9a93 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 @@ target := p.numVerifies + 1 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 {