Fix: coverage, remove SafeIsClosed

This commit is contained in:
kayos@tcp.direct 2023-05-26 21:59:34 -07:00
parent 92c0b3d0fd
commit 71a95f9a2f
Signed by: kayos
GPG Key ID: 4B841471B4BEE979
2 changed files with 4 additions and 23 deletions

View File

@ -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 {

View File

@ -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")
}
})
}