mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-10 20:50:25 +08:00
bfs:同一个Hash同时只能有一个Writer,避免多线程读冲突
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user