bfs:同一个Hash同时只能有一个Writer,避免多线程读冲突

This commit is contained in:
GoEdgeLab
2024-04-27 18:27:49 +08:00
parent 7b75c508c6
commit 501f9b6712
5 changed files with 62 additions and 14 deletions

View File

@@ -8,6 +8,32 @@ import (
"testing"
)
func TestBlocksFile_OpenFileWriter_SameHash(t *testing.T) {
bFile, openErr := bfs.OpenBlocksFile("testdata/test.b", bfs.DefaultBlockFileOptions)
if openErr != nil {
if os.IsNotExist(openErr) {
return
}
t.Fatal(openErr)
}
{
writer, err := bFile.OpenFileWriter(bfs.Hash("123456"), -1, false)
if err != nil {
t.Fatal(err)
}
_ = writer.Close()
}
{
writer, err := bFile.OpenFileWriter(bfs.Hash("123456"), -1, false)
if err != nil {
t.Fatal(err)
}
_ = writer.Close()
}
}
func TestBlocksFile_RemoveAll(t *testing.T) {
bFile, err := bfs.OpenBlocksFile("testdata/test.b", bfs.DefaultBlockFileOptions)
if err != nil {
@@ -16,6 +42,9 @@ func TestBlocksFile_RemoveAll(t *testing.T) {
}
t.Fatal(err)
}
defer func() {
_ = bFile.Close()
}()
err = bFile.RemoveAll()
if err != nil {