2014-11-16 20:13:20 +00:00
|
|
|
// Copyright (C) 2014 The Syncthing Authors.
|
2014-09-29 19:43:32 +00:00
|
|
|
//
|
2015-03-07 20:36:35 +00:00
|
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
// You can obtain one at http://mozilla.org/MPL/2.0/.
|
2014-09-28 11:00:38 +00:00
|
|
|
|
|
|
|
package model
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2015-01-13 12:22:56 +00:00
|
|
|
"github.com/syncthing/protocol"
|
2014-09-28 11:00:38 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestDeviceActivity(t *testing.T) {
|
2014-12-08 15:19:08 +00:00
|
|
|
n0 := protocol.DeviceID([32]byte{1, 2, 3, 4})
|
|
|
|
n1 := protocol.DeviceID([32]byte{5, 6, 7, 8})
|
|
|
|
n2 := protocol.DeviceID([32]byte{9, 10, 11, 12})
|
2014-09-28 11:00:38 +00:00
|
|
|
devices := []protocol.DeviceID{n0, n1, n2}
|
|
|
|
na := newDeviceActivity()
|
|
|
|
|
|
|
|
if lb := na.leastBusy(devices); lb != n0 {
|
|
|
|
t.Errorf("Least busy device should be n0 (%v) not %v", n0, lb)
|
|
|
|
}
|
|
|
|
if lb := na.leastBusy(devices); lb != n0 {
|
|
|
|
t.Errorf("Least busy device should still be n0 (%v) not %v", n0, lb)
|
|
|
|
}
|
|
|
|
|
|
|
|
na.using(na.leastBusy(devices))
|
|
|
|
if lb := na.leastBusy(devices); lb != n1 {
|
|
|
|
t.Errorf("Least busy device should be n1 (%v) not %v", n1, lb)
|
|
|
|
}
|
|
|
|
|
|
|
|
na.using(na.leastBusy(devices))
|
|
|
|
if lb := na.leastBusy(devices); lb != n2 {
|
|
|
|
t.Errorf("Least busy device should be n2 (%v) not %v", n2, lb)
|
|
|
|
}
|
|
|
|
|
|
|
|
na.using(na.leastBusy(devices))
|
|
|
|
if lb := na.leastBusy(devices); lb != n0 {
|
|
|
|
t.Errorf("Least busy device should be n0 (%v) not %v", n0, lb)
|
|
|
|
}
|
|
|
|
|
|
|
|
na.done(n1)
|
|
|
|
if lb := na.leastBusy(devices); lb != n1 {
|
|
|
|
t.Errorf("Least busy device should be n1 (%v) not %v", n1, lb)
|
|
|
|
}
|
|
|
|
|
|
|
|
na.done(n2)
|
|
|
|
if lb := na.leastBusy(devices); lb != n1 {
|
|
|
|
t.Errorf("Least busy device should still be n1 (%v) not %v", n1, lb)
|
|
|
|
}
|
|
|
|
|
|
|
|
na.done(n0)
|
|
|
|
if lb := na.leastBusy(devices); lb != n0 {
|
|
|
|
t.Errorf("Least busy device should be n0 (%v) not %v", n0, lb)
|
|
|
|
}
|
|
|
|
}
|