mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-19 20:40:26 +08:00
bfs:弹出BFile的时候确保没有正在被使用
This commit is contained in:
@@ -4,10 +4,43 @@ package bfs_test
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeNode/internal/utils/bfs"
|
||||
"github.com/iwind/TeaGo/assert"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestBlocksFile_CanClose(t *testing.T) {
|
||||
var a = assert.NewAssertion(t)
|
||||
|
||||
bFile, openErr := bfs.OpenBlocksFile("testdata/test.b", bfs.DefaultBlockFileOptions)
|
||||
if openErr != nil {
|
||||
if os.IsNotExist(openErr) {
|
||||
return
|
||||
}
|
||||
t.Fatal(openErr)
|
||||
}
|
||||
|
||||
reader, err := bFile.OpenFileReader(bfs.Hash("123456"), false)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
a.IsTrue(!bFile.CanClose())
|
||||
|
||||
err = reader.Close()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// duplicated close
|
||||
err = reader.Close()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
a.IsTrue(bFile.CanClose())
|
||||
}
|
||||
|
||||
func TestBlocksFile_OpenFileWriter_SameHash(t *testing.T) {
|
||||
bFile, openErr := bfs.OpenBlocksFile("testdata/test.b", bfs.DefaultBlockFileOptions)
|
||||
if openErr != nil {
|
||||
|
||||
Reference in New Issue
Block a user