test: Mend the transfer benchmark

This commit is contained in:
Jakob Borg 2018-02-03 10:28:37 +01:00
parent c0ab669142
commit 2fdf9bc55d
2 changed files with 26 additions and 9 deletions

View File

@ -88,6 +88,8 @@ func benchmarkTransfer(t *testing.T, files, sizeExp int) {
var t0, t1 time.Time
lastEvent := 0
oneItemFinished := false
loop:
for {
evs, err := receiver.Events(lastEvent)
@ -99,22 +101,34 @@ loop:
}
for _, ev := range evs {
if ev.Type == "StateChanged" {
lastEvent = ev.ID
switch ev.Type {
case "ItemFinished":
oneItemFinished = true
continue
case "StateChanged":
data := ev.Data.(map[string]interface{})
if data["folder"].(string) != "default" {
continue
}
log.Println(ev)
if data["to"].(string) == "syncing" {
switch data["to"].(string) {
case "syncing":
t0 = ev.Time
continue
case "idle":
if !oneItemFinished {
continue
}
if !t0.IsZero() && data["to"].(string) == "idle" {
if !t0.IsZero() {
t1 = ev.Time
break loop
}
}
lastEvent = ev.ID
}
}
time.Sleep(250 * time.Millisecond)

View File

@ -453,7 +453,10 @@ func startWalker(dir string, res chan<- fileInfo, abort <-chan struct{}) chan er
f = fileInfo{
name: rn,
mode: info.Mode(),
mod: info.ModTime().Truncate(time.Microsecond).UnixNano(),
// comparing timestamps with better precision than a second
// is problematic as there is rounding and truncatign going
// on at every level
mod: info.ModTime().Unix(),
size: info.Size(),
}
sum, err := md5file(path)