2014-11-16 20:13:20 +00:00
|
|
|
// Copyright (C) 2014 The Syncthing Authors.
|
2014-09-29 19:43:32 +00:00
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify it
|
|
|
|
// under the terms of the GNU General Public License as published by the Free
|
|
|
|
// Software Foundation, either version 3 of the License, or (at your option)
|
|
|
|
// any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
// more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License along
|
|
|
|
// with this program. If not, see <http://www.gnu.org/licenses/>.
|
2014-09-27 18:09:36 +00:00
|
|
|
|
2014-12-17 11:31:03 +00:00
|
|
|
// +build integration,benchmark
|
2014-09-27 18:09:36 +00:00
|
|
|
|
2014-12-17 11:31:03 +00:00
|
|
|
package integration
|
2014-09-27 18:09:36 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestBenchmarkTransfer(t *testing.T) {
|
|
|
|
log.Println("Cleaning...")
|
|
|
|
err := removeAll("s1", "s2", "h1/index", "h2/index")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Println("Generating files...")
|
2014-12-17 11:31:03 +00:00
|
|
|
err = generateFiles("s1", 10000, 22, "../LICENSE")
|
2014-09-27 18:09:36 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2015-02-19 11:15:51 +00:00
|
|
|
expected, err := directoryContents("s1")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2014-09-27 18:09:36 +00:00
|
|
|
|
2014-12-17 11:31:03 +00:00
|
|
|
log.Println("Starting sender...")
|
2014-09-27 18:09:36 +00:00
|
|
|
sender := syncthingProcess{ // id1
|
2015-02-19 11:15:51 +00:00
|
|
|
instance: "1",
|
|
|
|
argv: []string{"-home", "h1"},
|
|
|
|
port: 8081,
|
|
|
|
apiKey: apiKey,
|
2014-09-27 18:09:36 +00:00
|
|
|
}
|
2014-10-06 10:03:49 +00:00
|
|
|
err = sender.start()
|
2014-09-27 18:09:36 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2014-12-17 11:31:03 +00:00
|
|
|
// Make sure the sender has the full index before they connect
|
|
|
|
sender.post("/rest/scan?folder=default", nil)
|
|
|
|
|
|
|
|
log.Println("Starting receiver...")
|
2014-09-27 18:09:36 +00:00
|
|
|
receiver := syncthingProcess{ // id2
|
2015-02-19 11:15:51 +00:00
|
|
|
instance: "2",
|
|
|
|
argv: []string{"-home", "h2"},
|
|
|
|
port: 8082,
|
|
|
|
apiKey: apiKey,
|
2014-09-27 18:09:36 +00:00
|
|
|
}
|
2014-10-06 10:03:49 +00:00
|
|
|
err = receiver.start()
|
2014-09-27 18:09:36 +00:00
|
|
|
if err != nil {
|
|
|
|
sender.stop()
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2014-12-17 11:31:03 +00:00
|
|
|
var t0, t1 time.Time
|
2014-09-27 18:09:36 +00:00
|
|
|
loop:
|
|
|
|
for {
|
|
|
|
evs, err := receiver.events()
|
|
|
|
if err != nil {
|
2014-12-17 11:31:03 +00:00
|
|
|
if isTimeout(err) {
|
2014-09-27 18:09:36 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
sender.stop()
|
|
|
|
receiver.stop()
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, ev := range evs {
|
|
|
|
if ev.Type == "StateChanged" {
|
|
|
|
data := ev.Data.(map[string]interface{})
|
2014-09-28 11:00:38 +00:00
|
|
|
if data["folder"].(string) != "default" {
|
2014-09-27 18:09:36 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
log.Println(ev)
|
|
|
|
if data["to"].(string) == "syncing" {
|
|
|
|
t0 = ev.Time
|
|
|
|
continue
|
|
|
|
}
|
2014-12-17 11:31:03 +00:00
|
|
|
if !t0.IsZero() && data["to"].(string) == "idle" {
|
|
|
|
t1 = ev.Time
|
2014-09-27 18:09:36 +00:00
|
|
|
break loop
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-10-06 08:44:46 +00:00
|
|
|
|
|
|
|
time.Sleep(250 * time.Millisecond)
|
2014-09-27 18:09:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sender.stop()
|
|
|
|
receiver.stop()
|
2014-12-17 11:31:03 +00:00
|
|
|
|
|
|
|
log.Println("Verifying...")
|
|
|
|
|
2015-02-19 11:15:51 +00:00
|
|
|
actual, err := directoryContents("s2")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2014-12-17 11:31:03 +00:00
|
|
|
err = compareDirectoryContents(actual, expected)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Println("Sync took", t1.Sub(t0))
|
2014-09-27 18:09:36 +00:00
|
|
|
}
|