Integration test
This commit is contained in:
parent
4ac204b604
commit
b67443eb40
5
integration/.gitignore
vendored
Normal file
5
integration/.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
files-*
|
||||||
|
conf-*
|
||||||
|
md5-*
|
||||||
|
genfiles
|
||||||
|
md5r
|
||||||
37
integration/genfiles.go
Normal file
37
integration/genfiles.go
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/rand"
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
mr "math/rand"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
)
|
||||||
|
|
||||||
|
func name() string {
|
||||||
|
var b [16]byte
|
||||||
|
rand.Reader.Read(b[:])
|
||||||
|
return fmt.Sprintf("%x", b[:])
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
var files int
|
||||||
|
var maxsize int
|
||||||
|
|
||||||
|
flag.IntVar(&files, "files", 1000, "Number of files")
|
||||||
|
flag.IntVar(&maxsize, "maxsize", 1000, "Maximum file size (KB)")
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
for i := 0; i < files; i++ {
|
||||||
|
n := name()
|
||||||
|
p0 := path.Join(string(n[0]), n[0:2])
|
||||||
|
os.MkdirAll(p0, 0755)
|
||||||
|
s := mr.Intn(maxsize * 1024)
|
||||||
|
b := make([]byte, s)
|
||||||
|
rand.Reader.Read(b)
|
||||||
|
p1 := path.Join(p0, n)
|
||||||
|
ioutil.WriteFile(p1, b, 0644)
|
||||||
|
}
|
||||||
|
}
|
||||||
59
integration/md5r.go
Normal file
59
integration/md5r.go
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/md5"
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
flag.Parse()
|
||||||
|
args := flag.Args()
|
||||||
|
|
||||||
|
if len(args) == 0 {
|
||||||
|
args = []string{"."}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, path := range args {
|
||||||
|
err := filepath.Walk(path, walker)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintln(os.Stderr, err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func walker(path string, info os.FileInfo, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !info.IsDir() {
|
||||||
|
sum, err := md5file(path)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
fmt.Printf("%s %s\n", sum, path)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func md5file(fname string) (hash string, err error) {
|
||||||
|
f, err := os.Open(fname)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
h := md5.New()
|
||||||
|
io.Copy(h, f)
|
||||||
|
hb := h.Sum(nil)
|
||||||
|
hash = fmt.Sprintf("%x", hb)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
65
integration/test.sh
Executable file
65
integration/test.sh
Executable file
@ -0,0 +1,65 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
rm -rf files-* conf-* md5-*
|
||||||
|
|
||||||
|
p=$(pwd)
|
||||||
|
|
||||||
|
go build genfiles.go
|
||||||
|
go build md5r.go
|
||||||
|
|
||||||
|
echo "Setting up (keys)..."
|
||||||
|
i1=$(syncthing -c conf-1 2>&1 | awk '/My ID/ {print $6}')
|
||||||
|
echo $i1
|
||||||
|
i2=$(syncthing -c conf-2 2>&1 | awk '/My ID/ {print $6}')
|
||||||
|
echo $i2
|
||||||
|
i3=$(syncthing -c conf-3 2>&1 | awk '/My ID/ {print $6}')
|
||||||
|
echo $i3
|
||||||
|
|
||||||
|
echo "Setting up (files)..."
|
||||||
|
for i in 1 2 3 ; do
|
||||||
|
cat >conf-$i/syncthing.ini <<EOT
|
||||||
|
[repository]
|
||||||
|
dir = $p/files-$i
|
||||||
|
|
||||||
|
[nodes]
|
||||||
|
$i1 = 127.0.0.1:22001
|
||||||
|
$i2 = 127.0.0.1:22002
|
||||||
|
$i3 = 127.0.0.1:22003
|
||||||
|
EOT
|
||||||
|
|
||||||
|
mkdir files-$i
|
||||||
|
pushd files-$i >/dev/null
|
||||||
|
../genfiles -maxsize 780 -files 1500
|
||||||
|
../md5r > ../md5-$i
|
||||||
|
popd >/dev/null
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "Starting..."
|
||||||
|
for i in 1 2 3 ; do
|
||||||
|
syncthing -c conf-$i --no-gui -l :2200$i &
|
||||||
|
done
|
||||||
|
|
||||||
|
cat md5-* | sort > md5-tot
|
||||||
|
while true ; do
|
||||||
|
sleep 10
|
||||||
|
conv=0
|
||||||
|
for i in 1 2 3 ; do
|
||||||
|
pushd files-$i >/dev/null
|
||||||
|
../md5r | sort > ../md5-$i
|
||||||
|
popd >/dev/null
|
||||||
|
if ! cmp md5-$i md5-tot >/dev/null ; then
|
||||||
|
echo $i unconverged
|
||||||
|
else
|
||||||
|
conv=$((conv + 1))
|
||||||
|
echo $i converged
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ $conv == 3 ]] ; then
|
||||||
|
kill %1
|
||||||
|
kill %2
|
||||||
|
kill %3
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user