Only buffer file names, not full &FileInfo

This commit is contained in:
Jakob Borg
2014-12-30 09:31:34 +01:00
parent 34deb82aea
commit 2496185629
5 changed files with 68 additions and 82 deletions

View File

@@ -18,25 +18,15 @@ package model
import (
"fmt"
"testing"
"github.com/syncthing/syncthing/internal/protocol"
)
var (
f1 = &protocol.FileInfo{Name: "f1"}
f2 = &protocol.FileInfo{Name: "f2"}
f3 = &protocol.FileInfo{Name: "f3"}
f4 = &protocol.FileInfo{Name: "f4"}
f5 = &protocol.FileInfo{Name: "f5"}
)
func TestJobQueue(t *testing.T) {
// Some random actions
q := NewJobQueue()
q.Push(f1)
q.Push(f2)
q.Push(f3)
q.Push(f4)
q.Push("f1")
q.Push("f2")
q.Push("f3")
q.Push("f4")
progress, queued := q.Jobs()
if len(progress) != 0 || len(queued) != 4 {
@@ -44,8 +34,8 @@ func TestJobQueue(t *testing.T) {
}
for i := 1; i < 5; i++ {
n := q.Pop()
if n == nil || n.Name != fmt.Sprintf("f%d", i) {
n, ok := q.Pop()
if !ok || n != fmt.Sprintf("f%d", i) {
t.Fatal("Wrong element")
}
progress, queued = q.Jobs()
@@ -65,7 +55,7 @@ func TestJobQueue(t *testing.T) {
t.Fatal("Wrong length")
}
q.Done(f5) // Does not exist
q.Done("f5") // Does not exist
progress, queued = q.Jobs()
if len(progress) != 0 || len(queued) != 4 {
t.Fatal("Wrong length")
@@ -90,8 +80,8 @@ func TestJobQueue(t *testing.T) {
t.Fatal("Wrong length")
}
n := q.Pop()
if n == nil || n.Name != s {
n, ok := q.Pop()
if !ok || n != s {
t.Fatal("Wrong element")
}
progress, queued = q.Jobs()
@@ -99,24 +89,26 @@ func TestJobQueue(t *testing.T) {
t.Fatal("Wrong length")
}
q.Done(f5) // Does not exist
q.Done("f5") // Does not exist
progress, queued = q.Jobs()
if len(progress) != 5-i || len(queued) != i-1 {
t.Fatal("Wrong length")
}
}
if len(q.progress) != 4 || q.Pop() != nil {
_, ok := q.Pop()
if len(q.progress) != 4 || ok {
t.Fatal("Wrong length")
}
q.Done(f1)
q.Done(f2)
q.Done(f3)
q.Done(f4)
q.Done(f5) // Does not exist
q.Done("f1")
q.Done("f2")
q.Done("f3")
q.Done("f4")
q.Done("f5") // Does not exist
if len(q.progress) != 0 || q.Pop() != nil {
_, ok = q.Pop()
if len(q.progress) != 0 || ok {
t.Fatal("Wrong length")
}
@@ -125,7 +117,7 @@ func TestJobQueue(t *testing.T) {
t.Fatal("Wrong length")
}
q.Bump("")
q.Done(f5) // Does not exist
q.Done("f5") // Does not exist
progress, queued = q.Jobs()
if len(progress) != 0 || len(queued) != 0 {
t.Fatal("Wrong length")
@@ -178,8 +170,8 @@ func BenchmarkJobQueueBump(b *testing.B) {
files := genFiles(b.N)
q := NewJobQueue()
for j := range files {
q.Push(&files[j])
for _, f := range files {
q.Push(f.Name)
}
b.ResetTimer()
@@ -194,11 +186,11 @@ func BenchmarkJobQueuePushPopDone10k(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
q := NewJobQueue()
for j := range files {
q.Push(&files[j])
for _, f := range files {
q.Push(f.Name)
}
for range files {
n := q.Pop()
n, _ := q.Pop()
q.Done(n)
}
}