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-08-05 09:12:20 +00:00
|
|
|
|
2014-08-05 13:50:05 +00:00
|
|
|
// +build integration
|
|
|
|
|
2014-08-05 09:12:20 +00:00
|
|
|
package integration_test
|
|
|
|
|
|
|
|
import (
|
2014-08-25 15:45:13 +00:00
|
|
|
"log"
|
2014-10-06 09:13:00 +00:00
|
|
|
"strings"
|
2014-08-05 09:12:20 +00:00
|
|
|
"sync"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestRestartReceiverDuringTransfer(t *testing.T) {
|
|
|
|
testRestartDuringTransfer(t, false, true, 0, 0)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRestartSenderDuringTransfer(t *testing.T) {
|
|
|
|
testRestartDuringTransfer(t, true, false, 0, 0)
|
|
|
|
}
|
|
|
|
|
2014-09-04 21:31:22 +00:00
|
|
|
func TestRestartSenderAndReceiverDuringTransfer(t *testing.T) {
|
2014-09-16 21:14:19 +00:00
|
|
|
// Give the receiver some time to rot with needed files but
|
|
|
|
// without any peer. This triggers
|
|
|
|
// https://github.com/syncthing/syncthing/issues/463
|
2014-09-04 21:31:22 +00:00
|
|
|
testRestartDuringTransfer(t, true, true, 10*time.Second, 0)
|
|
|
|
}
|
|
|
|
|
2014-08-05 09:12:20 +00:00
|
|
|
func testRestartDuringTransfer(t *testing.T, restartSender, restartReceiver bool, senderDelay, receiverDelay time.Duration) {
|
2014-08-25 15:45:13 +00:00
|
|
|
log.Println("Cleaning...")
|
2014-09-16 21:14:19 +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...")
|
2014-09-16 21:14:19 +00:00
|
|
|
err = generateFiles("s1", 1000, 22, "../bin/syncthing")
|
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...")
|
2014-08-05 09:12:20 +00:00
|
|
|
sender := syncthingProcess{ // id1
|
2014-09-16 21:14:19 +00:00
|
|
|
log: "1.out",
|
|
|
|
argv: []string{"-home", "h1"},
|
|
|
|
port: 8081,
|
|
|
|
apiKey: apiKey,
|
2014-08-05 09:12:20 +00:00
|
|
|
}
|
2014-10-06 10:03:49 +00:00
|
|
|
err = sender.start()
|
2014-08-05 09:12:20 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
receiver := syncthingProcess{ // id2
|
2014-09-16 21:14:19 +00:00
|
|
|
log: "2.out",
|
|
|
|
argv: []string{"-home", "h2"},
|
|
|
|
port: 8082,
|
|
|
|
apiKey: apiKey,
|
2014-08-05 09:12:20 +00:00
|
|
|
}
|
2014-10-06 10:03:49 +00:00
|
|
|
err = receiver.start()
|
2014-08-05 09:12:20 +00:00
|
|
|
if err != nil {
|
2014-09-16 21:14:19 +00:00
|
|
|
sender.stop()
|
2014-08-05 09:12:20 +00:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
var prevComp int
|
|
|
|
for {
|
|
|
|
comp, err := sender.peerCompletion()
|
|
|
|
if err != nil {
|
2014-10-06 09:13:00 +00:00
|
|
|
if strings.Contains(err.Error(), "use of closed network connection") {
|
|
|
|
time.Sleep(250 * time.Millisecond)
|
|
|
|
continue
|
|
|
|
}
|
2014-08-05 09:12:20 +00:00
|
|
|
sender.stop()
|
|
|
|
receiver.stop()
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
curComp := comp[id2]
|
|
|
|
|
|
|
|
if curComp == 100 {
|
|
|
|
sender.stop()
|
|
|
|
receiver.stop()
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
if curComp > prevComp {
|
|
|
|
if restartReceiver {
|
2014-08-25 15:45:13 +00:00
|
|
|
log.Printf("Stopping receiver...")
|
2014-08-05 09:12:20 +00:00
|
|
|
receiver.stop()
|
|
|
|
}
|
|
|
|
|
|
|
|
if restartSender {
|
2014-08-25 15:45:13 +00:00
|
|
|
log.Printf("Stopping sender...")
|
2014-08-05 09:12:20 +00:00
|
|
|
sender.stop()
|
|
|
|
}
|
|
|
|
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
|
|
|
|
if restartReceiver {
|
|
|
|
wg.Add(1)
|
|
|
|
go func() {
|
|
|
|
time.Sleep(receiverDelay)
|
2014-08-25 15:45:13 +00:00
|
|
|
log.Printf("Starting receiver...")
|
2014-08-05 09:12:20 +00:00
|
|
|
receiver.start()
|
|
|
|
wg.Done()
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
|
|
|
if restartSender {
|
|
|
|
wg.Add(1)
|
|
|
|
go func() {
|
|
|
|
time.Sleep(senderDelay)
|
2014-08-25 15:45:13 +00:00
|
|
|
log.Printf("Starting sender...")
|
2014-08-05 09:12:20 +00:00
|
|
|
sender.start()
|
|
|
|
wg.Done()
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
|
|
|
wg.Wait()
|
|
|
|
|
|
|
|
prevComp = curComp
|
|
|
|
}
|
2014-10-06 08:44:46 +00:00
|
|
|
|
|
|
|
time.Sleep(250 * time.Millisecond)
|
2014-08-05 09:12:20 +00:00
|
|
|
}
|
|
|
|
|
2014-09-04 21:31:22 +00:00
|
|
|
sender.stop()
|
|
|
|
receiver.stop()
|
|
|
|
|
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 {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|