Add tests for client (#33)

* fix(fs/local): force closing fds and add backoffs, unit tests

* test(client/web): add unit tests
This commit is contained in:
Hexxa 2021-01-30 10:01:38 +08:00 committed by GitHub
parent 1ff1e2024e
commit ea3400aca6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 301 additions and 70 deletions

View file

@ -99,6 +99,16 @@ func (fs *LocalFS) translate(name string) (string, error) {
}
func (fs *LocalFS) Create(path string) error {
fs.opensMtx.Lock()
defer fs.opensMtx.Unlock()
if len(fs.opens) > fs.opensLimit {
err := fs.closeOpens(true, map[string]bool{})
if err != nil {
return fmt.Errorf("too many opens and fail to clean: %w", err)
}
return ErrTooManyOpens
}
fullpath, err := fs.translate(path)
if err != nil {
return err
@ -109,12 +119,6 @@ func (fs *LocalFS) Create(path string) error {
return err
}
fs.opensMtx.Lock()
defer fs.opensMtx.Unlock()
if len(fs.opens) > fs.opensLimit {
return ErrTooManyOpens
}
fs.opens[fullpath] = &fileInfo{
lastAccess: time.Now(),
fd: fd,