github.com/anacrolix/torrent@v1.61.0/deferrwl_test.go (about)

     1  package torrent
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/go-quicktest/qt"
     7  )
     8  
     9  func TestUniqueDeferOnce(t *testing.T) {
    10  	var p1, p2 Piece
    11  	var mu lockWithDeferreds
    12  	mu.Lock()
    13  	mu.DeferUniqueUnaryFunc(&p1, p1.publishStateChange)
    14  	mu.DeferUniqueUnaryFunc(&p1, p1.publishStateChange)
    15  	qt.Assert(t, qt.HasLen(mu.unlockActions, 1))
    16  	mu.DeferUniqueUnaryFunc(&p2, p2.publishStateChange)
    17  	qt.Assert(t, qt.HasLen(mu.unlockActions, 2))
    18  }