aboutsummaryrefslogtreecommitdiffstats
path: root/rlp/encode_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'rlp/encode_test.go')
-rw-r--r--rlp/encode_test.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/rlp/encode_test.go b/rlp/encode_test.go
index 60bd95692..b550d4303 100644
--- a/rlp/encode_test.go
+++ b/rlp/encode_test.go
@@ -23,6 +23,7 @@ import (
"io"
"io/ioutil"
"math/big"
+ "sync"
"testing"
)
@@ -306,3 +307,25 @@ func TestEncodeToReaderPiecewise(t *testing.T) {
return output, nil
})
}
+
+// This is a regression test verifying that encReader
+// returns its encbuf to the pool only once.
+func TestEncodeToReaderReturnToPool(t *testing.T) {
+ buf := make([]byte, 50)
+ wg := new(sync.WaitGroup)
+ for i := 0; i < 5; i++ {
+ wg.Add(1)
+ go func() {
+ for i := 0; i < 1000; i++ {
+ _, r, _ := EncodeToReader("foo")
+ ioutil.ReadAll(r)
+ r.Read(buf)
+ r.Read(buf)
+ r.Read(buf)
+ r.Read(buf)
+ }
+ wg.Done()
+ }()
+ }
+ wg.Wait()
+}