[test] filesystemlayer: 测试内存模式

pull/5/head
q191201771 3 years ago
parent 0a2519eb41
commit 0582391149

@ -9,7 +9,9 @@
package filesystemlayer_test
import (
"bytes"
"fmt"
"runtime"
"sync"
"testing"
@ -110,3 +112,36 @@ func TestCase1(t *testing.T) {
err = fslCtx.Rename("/tmp/lal/hls/test1/1.ts", "/tmp/lal/hls/test1/new1.ts")
assert.Equal(t, filesystemlayer.ErrNotFound, err)
}
func TestFslMemory(t *testing.T) {
buf := bytes.Repeat([]byte("x"), 4096000)
var m runtime.MemStats
runtime.ReadMemStats(&m)
nazalog.Debugf("%+v", m)
fslCtx := filesystemlayer.FslFactory(filesystemlayer.FslTypeMemory)
fp, err := fslCtx.Create("./aaa/b1")
assert.Equal(t, nil, err)
_, err = fp.Write(buf)
assert.Equal(t, nil, err)
runtime.ReadMemStats(&m)
nazalog.Debugf("%+v", m)
fp2, err := fslCtx.Create("./aaa/b2")
assert.Equal(t, nil, err)
_, err = fp2.Write(buf)
assert.Equal(t, nil, err)
runtime.ReadMemStats(&m)
nazalog.Debugf("%+v", m)
err = fslCtx.RemoveAll("./aaa")
assert.Equal(t, nil, err)
runtime.GC()
runtime.ReadMemStats(&m)
nazalog.Debugf("%+v", m)
}

@ -107,6 +107,8 @@ func (f *FslMemory) WriteFile(filename string, data []byte, perm uint32) error {
return err
}
// ---------------------------------------------------------------------------------------------------------------------
func (f *FslMemory) openFile(name string, flag int, perm uint32) (IFile, error) {
f.mu.Lock()
defer f.mu.Unlock()
@ -121,6 +123,8 @@ func (f *FslMemory) openFile(name string, flag int, perm uint32) (IFile, error)
return fi, nil
}
// ---------------------------------------------------------------------------------------------------------------------
func (f *file) Write(b []byte) (n int, err error) {
f.buf = append(f.buf, b...)
return len(b), nil

Loading…
Cancel
Save