Fix: coverage, remove SafeIsClosed
This commit is contained in:
parent
92c0b3d0fd
commit
71a95f9a2f
|
@ -684,19 +684,6 @@ func (c *Buffer) IsClosed() bool {
|
|||
return c.Buffer == nil || c.co == nil
|
||||
}
|
||||
|
||||
// SafeIsClosed is the same as IsClosed but holds a write lock on the buffer while reading.
|
||||
func (c *Buffer) SafeIsClosed() bool {
|
||||
if !c.hasmu() {
|
||||
panic(ErrBufferHasNoMutex)
|
||||
}
|
||||
if !c.mu.TryLock() {
|
||||
return false
|
||||
}
|
||||
closed := c.IsClosed()
|
||||
c.mu.Unlock()
|
||||
return closed
|
||||
}
|
||||
|
||||
// Close implements io.Closer. It returns the buffer to the pool. This
|
||||
func (c *Buffer) Close() error {
|
||||
if c.Buffer == nil {
|
||||
|
|
|
@ -629,13 +629,6 @@ func TestBufferFactory(t *testing.T) {
|
|||
_ = buf.SafeLen()
|
||||
}()
|
||||
}
|
||||
for i := 0; i < 100; i++ {
|
||||
go func() {
|
||||
if clsd := buf.SafeIsClosed(); clsd {
|
||||
t.Errorf("The buffer is closed somehow?")
|
||||
}
|
||||
}()
|
||||
}
|
||||
for i := 0; i < 100; i++ {
|
||||
if _, err := buf.SafeRead([]byte("yeet")); err != nil {
|
||||
t.Errorf("Error reading from buffer: %v", err)
|
||||
|
@ -768,9 +761,7 @@ func TestBufferFactory(t *testing.T) {
|
|||
t.Fatal("The panic is nil")
|
||||
}
|
||||
}()
|
||||
if clsd := buf.SafeIsClosed(); clsd {
|
||||
t.Errorf("The buffer is closed somehow?")
|
||||
}
|
||||
_ = buf.SafeNext(1)
|
||||
}()
|
||||
func() {
|
||||
defer func() {
|
||||
|
@ -867,5 +858,8 @@ func TestBufferFactory(t *testing.T) {
|
|||
if str := buf2.SafeString(); str != "" {
|
||||
t.Fatalf("The string is not empty: %v", str)
|
||||
}
|
||||
if err := buf2.SafeClose(); err == nil {
|
||||
t.Fatal("The error is nil despite nil buffer")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue