mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-01 22:02:26 -05:00
[bugfix] Close reader gracefully when streaming recache of remote media to fileserver api caller (#1281)
* close pipereader on failed data function * gently slurp the bytes * readability updates * go fmt * tidy up file server tests + add more cases * start moving io wrappers to separate iotools package. Remove use of buffering while piping recache stream Signed-off-by: kim <grufwub@gmail.com> * add license text Signed-off-by: kim <grufwub@gmail.com> Co-authored-by: kim <grufwub@gmail.com>
This commit is contained in:
parent
0871f5d181
commit
6ebdc306ed
8 changed files with 503 additions and 214 deletions
|
@ -19,6 +19,7 @@
|
|||
package media_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"io"
|
||||
"path"
|
||||
|
@ -143,9 +144,13 @@ func (suite *GetFileTestSuite) TestGetRemoteFileUncachedInterrupted() {
|
|||
suite.NotNil(content)
|
||||
|
||||
// only read the first kilobyte and then stop
|
||||
b := make([]byte, 1024)
|
||||
_, err = content.Content.Read(b)
|
||||
suite.NoError(err)
|
||||
b := make([]byte, 0, 1024)
|
||||
if !testrig.WaitFor(func() bool {
|
||||
read, err := io.CopyN(bytes.NewBuffer(b), content.Content, 1024)
|
||||
return err == nil && read == 1024
|
||||
}) {
|
||||
suite.FailNow("timed out trying to read first 1024 bytes")
|
||||
}
|
||||
|
||||
// close the reader
|
||||
suite.NoError(content.Content.Close())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue