mirror of
https://github.com/octoleo/syncthing.git
synced 2025-01-22 22:58:25 +00:00
parent
2b622d0774
commit
1cb55904bc
@ -847,6 +847,10 @@ func (m *model) NeedFolderFiles(folder string, page, perpage int) ([]db.FileInfo
|
|||||||
if runnerOk {
|
if runnerOk {
|
||||||
progressNames, queuedNames, skipped := runner.Jobs(page, perpage)
|
progressNames, queuedNames, skipped := runner.Jobs(page, perpage)
|
||||||
|
|
||||||
|
progress = make([]db.FileInfoTruncated, len(progressNames))
|
||||||
|
queued = make([]db.FileInfoTruncated, len(queuedNames))
|
||||||
|
seen = make(map[string]struct{}, len(progressNames)+len(queuedNames))
|
||||||
|
|
||||||
for i, name := range progressNames {
|
for i, name := range progressNames {
|
||||||
if f, ok := rf.GetGlobalTruncated(name); ok {
|
if f, ok := rf.GetGlobalTruncated(name); ok {
|
||||||
progress[i] = f
|
progress[i] = f
|
||||||
|
@ -13,6 +13,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@ -947,3 +948,46 @@ func TestRequestDeleteChanged(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestNeedFolderFiles(t *testing.T) {
|
||||||
|
m, fc, fcfg := setupModelWithConnection()
|
||||||
|
tfs := fcfg.Filesystem()
|
||||||
|
tmpDir := tfs.URI()
|
||||||
|
defer cleanupModelAndRemoveDir(m, tmpDir)
|
||||||
|
|
||||||
|
sub := events.Default.Subscribe(events.RemoteIndexUpdated)
|
||||||
|
defer events.Default.Unsubscribe(sub)
|
||||||
|
|
||||||
|
errPreventSync := errors.New("you aren't getting any of this")
|
||||||
|
fc.mut.Lock()
|
||||||
|
fc.requestFn = func(string, string, int64, int, []byte, bool) ([]byte, error) {
|
||||||
|
return nil, errPreventSync
|
||||||
|
}
|
||||||
|
fc.mut.Unlock()
|
||||||
|
|
||||||
|
data := []byte("foo")
|
||||||
|
num := 20
|
||||||
|
for i := 0; i < num; i++ {
|
||||||
|
fc.addFile(strconv.Itoa(i), 0644, protocol.FileInfoTypeFile, data)
|
||||||
|
}
|
||||||
|
fc.sendIndexUpdate()
|
||||||
|
|
||||||
|
select {
|
||||||
|
case <-sub.C():
|
||||||
|
case <-time.After(5 * time.Second):
|
||||||
|
t.Fatal("Timed out before receiving index")
|
||||||
|
}
|
||||||
|
|
||||||
|
progress, queued, rest := m.NeedFolderFiles(fcfg.ID, 1, 100)
|
||||||
|
if got := len(progress) + len(queued) + len(rest); got != num {
|
||||||
|
t.Errorf("Got %v needed items, expected %v", got, num)
|
||||||
|
}
|
||||||
|
|
||||||
|
exp := 10
|
||||||
|
for page := 1; page < 3; page++ {
|
||||||
|
progress, queued, rest := m.NeedFolderFiles(fcfg.ID, page, exp)
|
||||||
|
if got := len(progress) + len(queued) + len(rest); got != exp {
|
||||||
|
t.Errorf("Got %v needed items on page %v, expected %v", got, page, exp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user