forked from syncthing/syncthing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reconnect_test.go
120 lines (101 loc) · 2.59 KB
/
reconnect_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// Copyright (C) 2014 The Syncthing Authors.
//
// 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 https://mozilla.org/MPL/2.0/.
// +build integration
package integration
import (
"log"
"testing"
"time"
)
func TestReconnectReceiverDuringTransfer(t *testing.T) {
testReconnectDuringTransfer(t, false, true)
}
func TestReconnectSenderDuringTransfer(t *testing.T) {
testReconnectDuringTransfer(t, true, false)
}
func testReconnectDuringTransfer(t *testing.T, restartSender, restartReceiver bool) {
log.Println("Cleaning...")
err := removeAll("s1", "s2", "h1/index*", "h2/index*")
if err != nil {
t.Fatal(err)
}
log.Println("Generating files...")
err = generateFiles("s1", 250, 20, "../LICENSE")
if err != nil {
t.Fatal(err)
}
log.Println("Starting up...")
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() {
// We need a receiver over sender, since we'll update it later to
// point at another process.
checkedStop(t, receiver)
}()
// Set rate limits
cfg, err := receiver.GetConfig()
if err != nil {
t.Fatal(err)
}
cfg.Options.MaxRecvKbps = 750
cfg.Options.MaxSendKbps = 750
cfg.Options.LimitBandwidthInLan = true
if err := receiver.PostConfig(cfg); err != nil {
t.Fatal(err)
}
sender.ResumeAll()
receiver.ResumeAll()
var prevBytes int
for {
recv, err := receiver.Model("default")
if err != nil {
t.Fatal(err)
}
if recv.InSyncBytes > 0 && recv.InSyncBytes == recv.GlobalBytes {
// Receiver is done
break
} else if recv.InSyncBytes > prevBytes+recv.GlobalBytes/10 {
// Receiver has made progress
prevBytes = recv.InSyncBytes
if restartReceiver {
log.Printf("Stopping receiver...")
receiver.Stop()
receiver = startInstance(t, 2)
receiver.ResumeAll()
}
if restartSender {
log.Printf("Stopping sender...")
sender.Stop()
sender = startInstance(t, 1)
sender.ResumeAll()
}
}
time.Sleep(250 * time.Millisecond)
}
// Reset rate limits
cfg, err = receiver.GetConfig()
if err != nil {
t.Fatal(err)
}
cfg.Options.MaxRecvKbps = 0
cfg.Options.MaxSendKbps = 0
cfg.Options.LimitBandwidthInLan = false
if err := receiver.PostConfig(cfg); err != nil {
t.Fatal(err)
}
checkedStop(t, sender)
checkedStop(t, receiver)
log.Println("Comparing directories...")
err = compareDirectories("s1", "s2")
if err != nil {
t.Fatal(err)
}
}