test: Clean and unflake ignore / manupeers / reconnect / override tests

This commit is contained in:
Jakob Borg 2017-11-13 00:54:21 +01:00
parent fd5f9f8968
commit 9e11d7b201
4 changed files with 15 additions and 255 deletions

View File

@ -9,10 +9,12 @@
package integration package integration
import ( import (
"io/ioutil"
"log" "log"
"os" "os"
"path/filepath" "path/filepath"
"testing" "testing"
"time"
) )
func TestIgnores(t *testing.T) { func TestIgnores(t *testing.T) {
@ -31,7 +33,6 @@ func TestIgnores(t *testing.T) {
dirs := []string{"d1", "d2", "d3", "d4", "d11", "d12", "d13", "d14"} dirs := []string{"d1", "d2", "d3", "d4", "d11", "d12", "d13", "d14"}
files := []string{"f1", "f2", "f3", "f4", "f11", "f12", "f13", "f14", "d1/f1.TXT"} files := []string{"f1", "f2", "f3", "f4", "f11", "f12", "f13", "f14", "d1/f1.TXT"}
all := append(files, dirs...)
for _, dir := range dirs { for _, dir := range dirs {
err := os.Mkdir(filepath.Join("s1", dir), 0755) err := os.Mkdir(filepath.Join("s1", dir), 0755)
@ -48,16 +49,6 @@ func TestIgnores(t *testing.T) {
fd.Close() fd.Close()
} }
var syms []string
if symlinksSupported() {
syms = []string{"s1", "s2", "s3", "s4", "s11", "s12", "s13", "s14"}
for _, sym := range syms {
p := filepath.Join("s1", sym)
os.Symlink(p, p)
}
all = append(all, syms...)
}
// Rescan and verify that we see them all // Rescan and verify that we see them all
if err := p.Rescan("default"); err != nil { if err := p.Rescan("default"); err != nil {
@ -68,22 +59,16 @@ func TestIgnores(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
expected := len(all) // nothing is ignored expected := len(files) // nothing is ignored
if m.LocalFiles != expected { if m.LocalFiles != expected {
t.Fatalf("Incorrect number of files after initial scan, %d != %d", m.LocalFiles, expected) t.Fatalf("Incorrect number of files after initial scan, %d != %d", m.LocalFiles, expected)
} }
// Add some of them to an ignore file // Add some of them to an ignore file
fd, err := os.Create("s1/.stignore") err = ioutil.WriteFile("s1/.stignore",
if err != nil { []byte("f1*\nf2\nd1*\nd2\ns1*\ns2\n(?i)*.txt"), // [fds][34] only non-ignored items
t.Fatal(err) 0644)
}
_, err = fd.WriteString("f1*\nf2\nd1*\nd2\ns1*\ns2\n(?i)*.txt") // [fds][34] only non-ignored items
if err != nil {
t.Fatal(err)
}
err = fd.Close()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -98,25 +83,15 @@ func TestIgnores(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
expected = len(all) * 2 / 8 // two out of eight items of each type should remain expected = len(files) * 2 / 8 // two out of eight items should remain
if m.LocalFiles != expected { if m.LocalFiles != expected {
t.Fatalf("Incorrect number of files after first ignore, %d != %d", m.LocalFiles, expected) t.Fatalf("Incorrect number of files after first ignore, %d != %d", m.LocalFiles, expected)
} }
// Change the pattern to include some of the files and dirs previously ignored // Change the pattern to include some of the files and dirs previously ignored
fd, err = os.Create("s1/.stignore") time.Sleep(1100 * time.Millisecond)
if err != nil { err = ioutil.WriteFile("s1/.stignore", []byte("f2\nd2\ns2\n"), 0644)
t.Fatal(err)
}
_, err = fd.WriteString("f2\nd2\ns2\n")
if err != nil {
t.Fatal(err)
}
err = fd.Close()
if err != nil {
t.Fatal(err)
}
// Rescan and verify that we see them // Rescan and verify that we see them
@ -128,7 +103,7 @@ func TestIgnores(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
expected = len(all)*7/8 + 1 // seven out of eight items of each type should remain, plus the foo.TXT expected = len(files)*7/8 + 1 // seven out of eight items should remain, plus the foo.TXT
if m.LocalFiles != expected { if m.LocalFiles != expected {
t.Fatalf("Incorrect number of files after second ignore, %d != %d", m.LocalFiles, expected) t.Fatalf("Incorrect number of files after second ignore, %d != %d", m.LocalFiles, expected)
} }

View File

@ -35,6 +35,7 @@ func TestManyPeers(t *testing.T) {
receiver := startInstance(t, 2) receiver := startInstance(t, 2)
defer checkedStop(t, receiver) defer checkedStop(t, receiver)
receiver.ResumeAll()
bs, err := receiver.Get("/rest/system/config") bs, err := receiver.Get("/rest/system/config")
if err != nil { if err != nil {
@ -66,6 +67,7 @@ func TestManyPeers(t *testing.T) {
sender := startInstance(t, 1) sender := startInstance(t, 1)
defer checkedStop(t, sender) defer checkedStop(t, sender)
sender.ResumeAll()
rc.AwaitSync("default", sender, receiver) rc.AwaitSync("default", sender, receiver)

View File

@ -1,220 +0,0 @@
// 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"
"os"
"testing"
"github.com/syncthing/syncthing/lib/fs"
"github.com/syncthing/syncthing/lib/config"
"github.com/syncthing/syncthing/lib/protocol"
"github.com/syncthing/syncthing/lib/rc"
)
func TestAddDeviceWithoutRestart(t *testing.T) {
log.Println("Cleaning...")
err := removeAll("s1", "h1/index*", "s4", "h4/index*")
if err != nil {
t.Fatal(err)
}
log.Println("Generating files...")
err = generateFiles("s1", 100, 18, "../LICENSE")
if err != nil {
t.Fatal(err)
}
p1 := startInstance(t, 1)
defer checkedStop(t, p1)
p4 := startInstance(t, 4)
defer checkedStop(t, p4)
if ok, err := p1.ConfigInSync(); err != nil || !ok {
t.Fatal("p1 should be in sync;", ok, err)
}
if ok, err := p4.ConfigInSync(); err != nil || !ok {
t.Fatal("p4 should be in sync;", ok, err)
}
// Add the p1 device to p4. Back up and restore p4's config first.
log.Println("Adding p1 to p4...")
os.Remove("h4/config.xml.orig")
os.Rename("h4/config.xml", "h4/config.xml.orig")
defer os.Rename("h4/config.xml.orig", "h4/config.xml")
cfg, err := p4.GetConfig()
if err != nil {
t.Fatal(err)
}
devCfg := config.DeviceConfiguration{
DeviceID: p1.ID(),
Name: "s1",
Addresses: []string{"127.0.0.1:22001"},
Compression: protocol.CompressMetadata,
}
cfg.Devices = append(cfg.Devices, devCfg)
cfg.Folders[0].Devices = append(cfg.Folders[0].Devices, config.FolderDeviceConfiguration{DeviceID: p1.ID()})
if err = p4.PostConfig(cfg); err != nil {
t.Fatal(err)
}
// The change should not require a restart, so the config should be "in sync"
if ok, err := p4.ConfigInSync(); err != nil || !ok {
t.Fatal("p4 should be in sync;", ok, err)
}
// Wait for the devices to connect and sync.
log.Println("Waiting for p1 and p4 to connect and sync...")
rc.AwaitSync("default", p1, p4)
}
func TestFolderWithoutRestart(t *testing.T) {
log.Println("Cleaning...")
err := removeAll("testfolder-p1", "testfolder-p4", "h1/index*", "h4/index*")
if err != nil {
t.Fatal(err)
}
defer removeAll("testfolder-p1", "testfolder-p4")
if err := generateFiles("testfolder-p1", 50, 18, "../LICENSE"); err != nil {
t.Fatal(err)
}
p1 := startInstance(t, 1)
defer checkedStop(t, p1)
p4 := startInstance(t, 4)
defer checkedStop(t, p4)
if ok, err := p1.ConfigInSync(); err != nil || !ok {
t.Fatal("p1 should be in sync;", ok, err)
}
if ok, err := p4.ConfigInSync(); err != nil || !ok {
t.Fatal("p4 should be in sync;", ok, err)
}
// Add a new folder to p1, shared with p4. Back up and restore the config
// first.
log.Println("Adding testfolder to p1...")
os.Remove("h1/config.xml.orig")
os.Rename("h1/config.xml", "h1/config.xml.orig")
defer os.Rename("h1/config.xml.orig", "h1/config.xml")
cfg, err := p1.GetConfig()
if err != nil {
t.Fatal(err)
}
newFolder := config.FolderConfiguration{
ID: "testfolder",
FilesystemType: fs.FilesystemTypeBasic,
Path: "testfolder-p1",
RescanIntervalS: 86400,
Copiers: 1,
Hashers: 1,
Pullers: 1,
Devices: []config.FolderDeviceConfiguration{{DeviceID: p4.ID()}},
}
newDevice := config.DeviceConfiguration{
DeviceID: p4.ID(),
Name: "p4",
Addresses: []string{"dynamic"},
Compression: protocol.CompressMetadata,
}
cfg.Folders = append(cfg.Folders, newFolder)
cfg.Devices = append(cfg.Devices, newDevice)
if err = p1.PostConfig(cfg); err != nil {
t.Fatal(err)
}
// Add a new folder to p4, shared with p1. Back up and restore the config
// first.
log.Println("Adding testfolder to p4...")
os.Remove("h4/config.xml.orig")
os.Rename("h4/config.xml", "h4/config.xml.orig")
defer os.Rename("h4/config.xml.orig", "h4/config.xml")
cfg, err = p4.GetConfig()
if err != nil {
t.Fatal(err)
}
newFolder.Path = "testfolder-p4"
newFolder.Devices = []config.FolderDeviceConfiguration{{DeviceID: p1.ID()}}
newDevice.DeviceID = p1.ID()
newDevice.Name = "p1"
newDevice.Addresses = []string{"127.0.0.1:22001"}
cfg.Folders = append(cfg.Folders, newFolder)
cfg.Devices = append(cfg.Devices, newDevice)
if err = p4.PostConfig(cfg); err != nil {
t.Fatal(err)
}
// The change should not require a restart, so the config should be "in sync"
if ok, err := p1.ConfigInSync(); err != nil || !ok {
t.Fatal("p1 should be in sync;", ok, err)
}
if ok, err := p4.ConfigInSync(); err != nil || !ok {
t.Fatal("p4 should be in sync;", ok, err)
}
// The folder should start and scan - wait for the event that signals this
// has happened.
log.Println("Waiting for testfolder to scan...")
since := 0
outer:
for {
events, err := p4.Events(since)
if err != nil {
t.Fatal(err)
}
for _, event := range events {
if event.Type == "StateChanged" {
data := event.Data.(map[string]interface{})
folder := data["folder"].(string)
from := data["from"].(string)
to := data["to"].(string)
if folder == "testfolder" && from == "scanning" && to == "idle" {
break outer
}
}
since = event.ID
}
}
// It should sync to the other side successfully
log.Println("Waiting for p1 and p4 to connect and sync...")
rc.AwaitSync("testfolder", p1, p4)
}

View File

@ -68,6 +68,9 @@ func TestOverride(t *testing.T) {
slave := startInstance(t, 2) slave := startInstance(t, 2)
defer checkedStop(t, slave) defer checkedStop(t, slave)
master.ResumeAll()
slave.ResumeAll()
log.Println("Syncing...") log.Println("Syncing...")
rc.AwaitSync("default", master, slave) rc.AwaitSync("default", master, slave)