对本地数据库文件进行加锁

This commit is contained in:
刘祥超
2023-03-07 16:22:32 +08:00
parent 44d1a2415c
commit d7e6da8d2c
8 changed files with 188 additions and 34 deletions

View File

@@ -0,0 +1,24 @@
// Copyright 2023 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
package fileutils_test
import (
"github.com/TeaOSLab/EdgeNode/internal/utils/fileutils"
"testing"
)
func TestLocker_Lock(t *testing.T) {
var path = "/tmp/file-test"
var locker = fileutils.NewLocker(path)
err := locker.Lock()
if err != nil {
t.Fatal(err)
}
_ = locker.Release()
var locker2 = fileutils.NewLocker(path)
err = locker2.Lock()
if err != nil {
t.Fatal(err)
}
}