(t *testing.T)
| 797 | } |
| 798 | |
| 799 | func TestLinkBufferPeekOutOfMemory(t *testing.T) { |
| 800 | bufCap := 1024 * 8 |
| 801 | bufNodes := 100 |
| 802 | magicN := uint64(2024) |
| 803 | buf := NewLinkBuffer(bufCap) |
| 804 | MustTrue(t, buf.IsEmpty()) |
| 805 | Equal(t, cap(buf.write.buf), bufCap) |
| 806 | Equal(t, buf.memorySize(), bufCap) |
| 807 | |
| 808 | var p []byte |
| 809 | var err error |
| 810 | // write data that cross multi nodes |
| 811 | for n := 0; n < bufNodes; n++ { |
| 812 | p, err = buf.Malloc(bufCap) |
| 813 | MustNil(t, err) |
| 814 | Equal(t, len(p), bufCap) |
| 815 | binary.BigEndian.PutUint64(p, magicN) |
| 816 | } |
| 817 | Equal(t, buf.MallocLen(), bufCap*bufNodes) |
| 818 | buf.Flush() |
| 819 | Equal(t, buf.MallocLen(), 0) |
| 820 | |
| 821 | // peak data that in single node |
| 822 | for i := 0; i < 10; i++ { |
| 823 | p, err = buf.Peek(bufCap) |
| 824 | Equal(t, binary.BigEndian.Uint64(p), magicN) |
| 825 | MustNil(t, err) |
| 826 | Equal(t, len(p), bufCap) |
| 827 | Equal(t, buf.memorySize(), bufCap*bufNodes) |
| 828 | } |
| 829 | |
| 830 | // peak data that cross nodes |
| 831 | memorySize := 0 |
| 832 | for i := 0; i < 1024; i++ { |
| 833 | p, err = buf.Peek(bufCap + 1) |
| 834 | MustNil(t, err) |
| 835 | Equal(t, binary.BigEndian.Uint64(p), magicN) |
| 836 | Equal(t, len(p), bufCap+1) |
| 837 | if memorySize == 0 { |
| 838 | memorySize = buf.memorySize() |
| 839 | t.Logf("after Peek: memorySize=%d", memorySize) |
| 840 | } else { |
| 841 | Equal(t, buf.memorySize(), memorySize) |
| 842 | } |
| 843 | } |
| 844 | } |
| 845 | |
| 846 | func TestMallocAck(t *testing.T) { |
| 847 | sLen := 1024 * 7 |
nothing calls this directly
no test coverage detected
searching dependent graphs…