]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Fix some tests that didn't hold lock while deferring actions
authorMatt Joiner <anacrolix@gmail.com>
Wed, 13 Aug 2025 01:57:26 +0000 (11:57 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Wed, 13 Aug 2025 01:57:26 +0000 (11:57 +1000)
deferrwl_test.go
peerconn_test.go

index 8d08ede65220f1c67f0bbbc9318cf0f5e54238dc..55297384e1d0c42c0c89603748bc9f397251ab17 100644 (file)
@@ -9,6 +9,7 @@ import (
 func TestUniqueDeferOnce(t *testing.T) {
        var p1, p2 Piece
        var mu lockWithDeferreds
+       mu.Lock()
        mu.DeferUniqueUnaryFunc(&p1, p1.publishStateChange)
        mu.DeferUniqueUnaryFunc(&p1, p1.publishStateChange)
        qt.Assert(t, qt.HasLen(mu.unlockActions, 1))
index 876ed883ee8579d3f7cc221fffad2569f6ab8e08..4a4e7740f72c99d7a3acf9545ce3a65646f9c577 100644 (file)
@@ -28,7 +28,9 @@ func TestSendBitfieldThenHave(t *testing.T) {
        cl.initLogger()
        c := cl.newConnection(nil, newConnectionOpts{network: "io.Pipe"})
        c.setTorrent(cl.newTorrentForTesting())
+       cl.lock()
        err := c.t.setInfo(&metainfo.Info{Pieces: make([]byte, metainfo.HashSize*3)})
+       cl.unlock()
        qt.Assert(t, qt.IsNil(err))
        r, w := io.Pipe()
        // c.r = r