fix(files): fix fd closing issue
This commit is contained in:
parent
5e8567d470
commit
1b0bf9c5fd
6 changed files with 72 additions and 18 deletions
|
@ -8,6 +8,7 @@ import (
|
|||
"path/filepath"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/ihexxa/quickshare/src/client"
|
||||
q "github.com/ihexxa/quickshare/src/handlers"
|
||||
|
@ -130,7 +131,13 @@ func TestFileHandlers(t *testing.T) {
|
|||
for i := 0; i < 2; i++ {
|
||||
assertUploadOK(t, filePath, content, addr, token)
|
||||
|
||||
err = fs.Sync()
|
||||
// file operation(deleting tmp file) may be async
|
||||
// so creating tmp file in the 2nd time may conflict with the first time if it is not deleted yet
|
||||
// checking file until it is deleted
|
||||
// TODO: use fs.Stat() to avoid flaky testing...
|
||||
time.Sleep(1000)
|
||||
|
||||
err = fs.Close()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -83,20 +83,20 @@ func assertUploadOK(t *testing.T, filePath, content, addr string, token *http.Co
|
|||
fileSize := int64(len([]byte(content)))
|
||||
res, _, errs := cl.Create(filePath, fileSize)
|
||||
if len(errs) > 0 {
|
||||
t.Error(errs)
|
||||
t.Fatal(errs)
|
||||
return false
|
||||
} else if res.StatusCode != 200 {
|
||||
t.Error(res.StatusCode)
|
||||
t.Fatal(res.StatusCode)
|
||||
return false
|
||||
}
|
||||
|
||||
base64Content := base64.StdEncoding.EncodeToString([]byte(content))
|
||||
res, _, errs = cl.UploadChunk(filePath, base64Content, 0)
|
||||
if len(errs) > 0 {
|
||||
t.Error(errs)
|
||||
t.Fatal(errs)
|
||||
return false
|
||||
} else if res.StatusCode != 200 {
|
||||
t.Error(res.StatusCode)
|
||||
t.Fatal(res.StatusCode)
|
||||
return false
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue