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,
|
2017-02-09 06:52:18 +00:00
|
|
|
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
2014-08-05 09:12:20 +00:00
|
|
|
|
2021-08-17 08:10:41 +00:00
|
|
|
//go:build integration
|
2014-08-05 13:50:05 +00:00
|
|
|
// +build integration
|
|
|
|
|
2014-12-17 11:31:03 +00:00
|
|
|
package integration
|
2014-08-05 09:12:20 +00:00
|
|
|
|
|
|
|
import (
|
2014-08-25 15:45:13 +00:00
|
|
|
"log"
|
2014-08-05 09:12:20 +00:00
|
|
|
"testing"
|
|
|
|
"time"
|
2020-09-07 07:35:37 +00:00
|
|
|
|
|
|
|
"github.com/syncthing/syncthing/lib/rc"
|
2014-08-05 09:12:20 +00:00
|
|
|
)
|
|
|
|
|
2017-11-12 23:36:37 +00:00
|
|
|
func TestReconnectReceiverDuringTransfer(t *testing.T) {
|
2017-11-17 12:11:45 +00:00
|
|
|
testReconnectDuringTransfer(t, false, true)
|
2014-08-05 09:12:20 +00:00
|
|
|
}
|
|
|
|
|
2017-11-12 23:36:37 +00:00
|
|
|
func TestReconnectSenderDuringTransfer(t *testing.T) {
|
2017-11-17 12:11:45 +00:00
|
|
|
testReconnectDuringTransfer(t, true, false)
|
2014-08-05 09:12:20 +00:00
|
|
|
}
|
|
|
|
|
2017-11-17 12:11:45 +00:00
|
|
|
func testReconnectDuringTransfer(t *testing.T, restartSender, restartReceiver bool) {
|
2014-08-25 15:45:13 +00:00
|
|
|
log.Println("Cleaning...")
|
2015-03-29 10:55:27 +00:00
|
|
|
err := removeAll("s1", "s2", "h1/index*", "h2/index*")
|
2014-08-05 09:12:20 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2014-08-25 15:45:13 +00:00
|
|
|
log.Println("Generating files...")
|
2017-11-17 12:11:45 +00:00
|
|
|
err = generateFiles("s1", 250, 20, "../LICENSE")
|
2014-08-05 09:12:20 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2014-08-25 15:45:13 +00:00
|
|
|
log.Println("Starting up...")
|
2015-06-18 13:22:45 +00:00
|
|
|
sender := startInstance(t, 1)
|
|
|
|
defer func() {
|
|
|
|
// We need a closure over sender, since we'll update it later to point
|
|
|
|
// at another process.
|
|
|
|
checkedStop(t, sender)
|
|
|
|
}()
|
|
|
|
|
|
|
|
receiver := startInstance(t, 2)
|
|
|
|
defer func() {
|
2020-09-07 07:35:37 +00:00
|
|
|
// We need a closure over sender, since we'll update it later to
|
2015-06-18 13:22:45 +00:00
|
|
|
// point at another process.
|
|
|
|
checkedStop(t, receiver)
|
|
|
|
}()
|
2014-08-05 09:12:20 +00:00
|
|
|
|
2017-11-12 23:36:37 +00:00
|
|
|
// Set rate limits
|
|
|
|
cfg, err := receiver.GetConfig()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2017-11-17 12:11:45 +00:00
|
|
|
cfg.Options.MaxRecvKbps = 750
|
|
|
|
cfg.Options.MaxSendKbps = 750
|
|
|
|
cfg.Options.LimitBandwidthInLan = true
|
2017-11-12 23:36:37 +00:00
|
|
|
if err := receiver.PostConfig(cfg); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
sender.ResumeAll()
|
|
|
|
receiver.ResumeAll()
|
|
|
|
|
2015-05-23 20:56:43 +00:00
|
|
|
var prevBytes int
|
2014-08-05 09:12:20 +00:00
|
|
|
for {
|
2015-06-18 13:22:45 +00:00
|
|
|
recv, err := receiver.Model("default")
|
2014-08-05 09:12:20 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-09-07 07:35:37 +00:00
|
|
|
if recv.InSyncBytes > 0 && recv.InSyncBytes == recv.GlobalBytes && rc.InSync("default", receiver, sender) {
|
2015-05-23 20:56:43 +00:00
|
|
|
// Receiver is done
|
2014-08-05 09:12:20 +00:00
|
|
|
break
|
2015-05-23 20:56:43 +00:00
|
|
|
} else if recv.InSyncBytes > prevBytes+recv.GlobalBytes/10 {
|
|
|
|
// Receiver has made progress
|
|
|
|
prevBytes = recv.InSyncBytes
|
2014-08-05 09:12:20 +00:00
|
|
|
|
2017-11-17 12:11:45 +00:00
|
|
|
if restartReceiver {
|
|
|
|
log.Printf("Stopping receiver...")
|
|
|
|
receiver.Stop()
|
|
|
|
receiver = startInstance(t, 2)
|
|
|
|
receiver.ResumeAll()
|
2014-08-05 09:12:20 +00:00
|
|
|
}
|
|
|
|
|
2017-11-17 12:11:45 +00:00
|
|
|
if restartSender {
|
|
|
|
log.Printf("Stopping sender...")
|
|
|
|
sender.Stop()
|
|
|
|
sender = startInstance(t, 1)
|
|
|
|
sender.ResumeAll()
|
2014-08-05 09:12:20 +00:00
|
|
|
}
|
|
|
|
}
|
2014-10-06 08:44:46 +00:00
|
|
|
|
2017-11-17 12:11:45 +00:00
|
|
|
time.Sleep(250 * time.Millisecond)
|
2014-08-05 09:12:20 +00:00
|
|
|
}
|
|
|
|
|
2017-11-12 23:36:37 +00:00
|
|
|
// Reset rate limits
|
|
|
|
cfg, err = receiver.GetConfig()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
cfg.Options.MaxRecvKbps = 0
|
|
|
|
cfg.Options.MaxSendKbps = 0
|
2017-11-17 12:11:45 +00:00
|
|
|
cfg.Options.LimitBandwidthInLan = false
|
2017-11-12 23:36:37 +00:00
|
|
|
if err := receiver.PostConfig(cfg); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2015-06-18 13:22:45 +00:00
|
|
|
checkedStop(t, sender)
|
|
|
|
checkedStop(t, receiver)
|
2014-09-04 21:31:22 +00:00
|
|
|
|
2014-08-25 15:45:13 +00:00
|
|
|
log.Println("Comparing directories...")
|
2014-08-05 09:12:20 +00:00
|
|
|
err = compareDirectories("s1", "s2")
|
|
|
|
if err != nil {
|
2020-09-07 07:35:37 +00:00
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := checkRemoteInSync("default", receiver, sender); err != nil {
|
|
|
|
t.Error(err)
|
2014-08-05 09:12:20 +00:00
|
|
|
}
|
|
|
|
}
|