Commit eedf4e5e authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Make memory pressure test resilient to random processes statting files

in the mount.
parent f2a679a9
...@@ -3,31 +3,43 @@ package fuse ...@@ -3,31 +3,43 @@ package fuse
import ( import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"log"
"os" "os"
"strings" "regexp"
"sync" "sync"
"testing" "testing"
"time" "time"
) )
var _ = log.Println
// This test checks that highly concurrent loads don't use a lot of // This test checks that highly concurrent loads don't use a lot of
// memory if it is not needed: The input buffer needs to accomodata // memory if it is not needed: The input buffer needs to accomodata
// the max write size, but it is only really needed when we are // the max write size, but it is only really needed when we are
// processing writes. // processing writes.
type DelayFs struct { type DelayFs struct {
DefaultFileSystem DefaultFileSystem
fileRegex *regexp.Regexp
dirRegex *regexp.Regexp
} }
func (d *DelayFs) GetAttr(name string, c *Context) (*Attr, Status) { func (d *DelayFs) GetAttr(name string, c *Context) (*Attr, Status) {
if name == "" || strings.HasSuffix(name, "dir") { if name == "" || d.dirRegex.MatchString(name) {
return &Attr{Mode: S_IFDIR | 0755}, OK return &Attr{Mode: S_IFDIR | 0755}, OK
} }
time.Sleep(time.Second) if d.fileRegex.MatchString(name) {
return &Attr{Mode: S_IFREG | 0644}, OK time.Sleep(time.Second)
return &Attr{Mode: S_IFREG | 0644}, OK
}
return nil, ENOENT
} }
func TestMemoryPressure(t *testing.T) { func TestMemoryPressure(t *testing.T) {
fs := &DelayFs{} fs := &DelayFs{
fileRegex: regexp.MustCompile("^dir[0-9]*/file[0-9]*$"),
dirRegex: regexp.MustCompile("^dir[0-9]*$"),
}
dir, err := ioutil.TempDir("", "go-fuse") dir, err := ioutil.TempDir("", "go-fuse")
CheckSuccess(err) CheckSuccess(err)
...@@ -54,7 +66,7 @@ func TestMemoryPressure(t *testing.T) { ...@@ -54,7 +66,7 @@ func TestMemoryPressure(t *testing.T) {
for i := 0; i < 10*_MAX_READERS; i++ { for i := 0; i < 10*_MAX_READERS; i++ {
wg.Add(1) wg.Add(1)
go func(x int) { go func(x int) {
fn := fmt.Sprintf("%s/%ddir/file%d", dir, x, x) fn := fmt.Sprintf("%s/dir%d/file%d", dir, x, x)
_, err := os.Lstat(fn) _, err := os.Lstat(fn)
if err != nil { if err != nil {
t.Errorf("parallel stat %q: %v", fn, err) t.Errorf("parallel stat %q: %v", fn, err)
...@@ -66,7 +78,7 @@ func TestMemoryPressure(t *testing.T) { ...@@ -66,7 +78,7 @@ func TestMemoryPressure(t *testing.T) {
created := bufs.createdBuffers + state.outstandingReadBufs created := bufs.createdBuffers + state.outstandingReadBufs
t.Logf("Have %d read bufs", state.outstandingReadBufs) t.Logf("Have %d read bufs", state.outstandingReadBufs)
if created > 2*_MAX_READERS { if created > _MAX_READERS {
t.Errorf("created %d buffers, max reader %d", created, _MAX_READERS) t.Errorf("created %d buffers, max reader %d", created, _MAX_READERS)
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment