lib/model: Optimise locking around conn-close and puller states (#5954)
This commit is contained in:
@@ -254,6 +254,7 @@ func TestCopierFinder(t *testing.T) {
|
||||
|
||||
pulls := []pullBlockState{<-pullChan, <-pullChan, <-pullChan, <-pullChan}
|
||||
finish := <-finisherChan
|
||||
defer cleanupSharedPullerState(finish)
|
||||
|
||||
select {
|
||||
case <-pullChan:
|
||||
@@ -293,7 +294,6 @@ func TestCopierFinder(t *testing.T) {
|
||||
t.Errorf("Block %d mismatch: %s != %s", eq, blks[eq-1].String(), blocks[eq].String())
|
||||
}
|
||||
}
|
||||
finish.fd.Close()
|
||||
}
|
||||
|
||||
func TestWeakHash(t *testing.T) {
|
||||
@@ -389,7 +389,7 @@ func TestWeakHash(t *testing.T) {
|
||||
default:
|
||||
}
|
||||
|
||||
finish.fd.Close()
|
||||
cleanupSharedPullerState(finish)
|
||||
if err := ffs.Remove(tempFile); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -409,7 +409,7 @@ func TestWeakHash(t *testing.T) {
|
||||
}
|
||||
|
||||
finish = <-finisherChan
|
||||
finish.fd.Close()
|
||||
cleanupSharedPullerState(finish)
|
||||
|
||||
expectShifted := expectBlocks - expectPulls
|
||||
if finish.copyOriginShifted != expectShifted {
|
||||
@@ -516,9 +516,9 @@ func TestDeregisterOnFailInCopy(t *testing.T) {
|
||||
t.Log("event took", time.Since(t0))
|
||||
|
||||
state.mut.Lock()
|
||||
stateFd := state.fd
|
||||
stateWriter := state.writer
|
||||
state.mut.Unlock()
|
||||
if stateFd != nil {
|
||||
if stateWriter != nil {
|
||||
t.Fatal("File not closed?")
|
||||
}
|
||||
|
||||
@@ -594,9 +594,9 @@ func TestDeregisterOnFailInPull(t *testing.T) {
|
||||
t.Log("event took", time.Since(t0))
|
||||
|
||||
state.mut.Lock()
|
||||
stateFd := state.fd
|
||||
stateWriter := state.writer
|
||||
state.mut.Unlock()
|
||||
if stateFd != nil {
|
||||
if stateWriter != nil {
|
||||
t.Fatal("File not closed?")
|
||||
}
|
||||
|
||||
@@ -906,3 +906,14 @@ func TestSRConflictReplaceFileByLink(t *testing.T) {
|
||||
t.Fatal("Expected request to scan", confls[0], "got", scan)
|
||||
}
|
||||
}
|
||||
|
||||
func cleanupSharedPullerState(s *sharedPullerState) {
|
||||
s.mut.Lock()
|
||||
defer s.mut.Unlock()
|
||||
if s.writer == nil {
|
||||
return
|
||||
}
|
||||
s.writer.mut.Lock()
|
||||
s.writer.fd.Close()
|
||||
s.writer.mut.Unlock()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user