Skip to content

Commit

Permalink
core/services/ocr2/plugins/llo: use write lock during mock read close…
Browse files Browse the repository at this point in the history
…r Reads (#14276)
  • Loading branch information
jmank88 authored Aug 29, 2024
1 parent 7c248e7 commit 81733d9
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (h *mockHTTPClient) SetResponse(resp *http.Response, err error) {

type MockReadCloser struct {
data []byte
mu sync.RWMutex
mu sync.Mutex
reader *bytes.Reader
}

Expand All @@ -71,17 +71,17 @@ func NewMockReadCloser(data []byte) *MockReadCloser {

// Read reads from the underlying data
func (m *MockReadCloser) Read(p []byte) (int, error) {
m.mu.RLock()
defer m.mu.RUnlock()
m.mu.Lock()
defer m.mu.Unlock()
return m.reader.Read(p)
}

// Close resets the reader to the beginning of the data
func (m *MockReadCloser) Close() error {
m.mu.Lock()
defer m.mu.Unlock()
m.reader.Seek(0, io.SeekStart)
return nil
_, err := m.reader.Seek(0, io.SeekStart)
return err
}

func Test_ChannelDefinitionCache_Integration(t *testing.T) {
Expand Down

0 comments on commit 81733d9

Please sign in to comment.