2014-11-16 20:13:20 +00:00
|
|
|
// Copyright (C) 2014 The Syncthing Authors.
|
2014-10-21 05:37:38 +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-10-21 05:37:38 +00:00
|
|
|
|
|
|
|
// +build integration
|
|
|
|
|
2014-12-17 11:31:03 +00:00
|
|
|
package integration
|
2014-10-21 05:37:38 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"encoding/json"
|
|
|
|
"log"
|
|
|
|
"testing"
|
|
|
|
|
2015-01-13 12:22:56 +00:00
|
|
|
"github.com/syncthing/protocol"
|
2014-10-21 05:37:38 +00:00
|
|
|
"github.com/syncthing/syncthing/internal/config"
|
|
|
|
"github.com/syncthing/syncthing/internal/osutil"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestManyPeers(t *testing.T) {
|
|
|
|
log.Println("Cleaning...")
|
2015-03-29 10:55:27 +00:00
|
|
|
err := removeAll("s1", "s2", "h1/index*", "h2/index*")
|
2014-10-21 05:37:38 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Println("Generating files...")
|
2014-11-29 22:41:06 +00:00
|
|
|
err = generateFiles("s1", 200, 20, "../LICENSE")
|
2014-10-21 05:37:38 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
receiver := syncthingProcess{ // id2
|
2015-01-11 08:26:20 +00:00
|
|
|
instance: "2",
|
|
|
|
argv: []string{"-home", "h2"},
|
|
|
|
port: 8082,
|
|
|
|
apiKey: apiKey,
|
2014-10-21 05:37:38 +00:00
|
|
|
}
|
|
|
|
err = receiver.start()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer receiver.stop()
|
|
|
|
|
2015-04-06 08:23:27 +00:00
|
|
|
resp, err := receiver.get("/rest/system/config")
|
2014-10-21 05:37:38 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if resp.StatusCode != 200 {
|
|
|
|
t.Fatalf("Code %d != 200", resp.StatusCode)
|
|
|
|
}
|
|
|
|
|
|
|
|
var cfg config.Configuration
|
|
|
|
json.NewDecoder(resp.Body).Decode(&cfg)
|
|
|
|
resp.Body.Close()
|
|
|
|
|
|
|
|
for len(cfg.Devices) < 100 {
|
|
|
|
bs := make([]byte, 16)
|
|
|
|
ReadRand(bs)
|
|
|
|
id := protocol.NewDeviceID(bs)
|
|
|
|
cfg.Devices = append(cfg.Devices, config.DeviceConfiguration{DeviceID: id})
|
|
|
|
cfg.Folders[0].Devices = append(cfg.Folders[0].Devices, config.FolderDeviceConfiguration{DeviceID: id})
|
|
|
|
}
|
|
|
|
|
|
|
|
osutil.Rename("h2/config.xml", "h2/config.xml.orig")
|
|
|
|
defer osutil.Rename("h2/config.xml.orig", "h2/config.xml")
|
|
|
|
|
|
|
|
var buf bytes.Buffer
|
|
|
|
json.NewEncoder(&buf).Encode(cfg)
|
2015-04-06 08:23:27 +00:00
|
|
|
resp, err = receiver.post("/rest/system/config", &buf)
|
2014-10-21 05:37:38 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if resp.StatusCode != 200 {
|
|
|
|
t.Fatalf("Code %d != 200", resp.StatusCode)
|
|
|
|
}
|
|
|
|
resp.Body.Close()
|
|
|
|
|
|
|
|
log.Println("Starting up...")
|
|
|
|
sender := syncthingProcess{ // id1
|
2015-01-11 08:26:20 +00:00
|
|
|
instance: "1",
|
|
|
|
argv: []string{"-home", "h1"},
|
|
|
|
port: 8081,
|
|
|
|
apiKey: apiKey,
|
2014-10-21 05:37:38 +00:00
|
|
|
}
|
|
|
|
err = sender.start()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer sender.stop()
|
|
|
|
|
2015-05-23 20:56:43 +00:00
|
|
|
err = awaitCompletion("default", sender, receiver)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
2014-10-21 05:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
log.Println("Comparing directories...")
|
|
|
|
err = compareDirectories("s1", "s2")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|