How to create Syncthing test environments

Here some tips to create syncthing test environments.

Multiple Test Instances

You can start multiple instances on the same machine. Every instance must used separate listening ports, e.g.: 22001, 22002 etc. Add all nodes with address/port e.g.: 127.0.0.1:2200x (local discovery doesn’t work within the same host).

To do this:

  • Set a different home directory for every instance
  • Start one instance and change settings, then start next instance etc.

Linux

Here a simple script to startup multiple instance with different home directories:

#!/bin/bash

# Change the path to syncthing binary here:
SYNCTHING_BIN=/home/syncthing/bin/syncthing

read -n1 -p "Start number? [1,2,3...]" NUMBER
echo

BASE_DIR=~/syncthing_test/instance${NUMBER}/
mkdir -p $BASE_DIR

(
    set -x
    HOME=${BASE_DIR}
    ${SYNCTHING_BIN} -home=${BASE_DIR}\syncthing_configs
)

Start the script and enter 1, setup the instance. Start in a other terminal, enter 2, etc.

You will get the following filesystem structure:

  • ~/syncthing_test/
    • instance1/
      • syncthing_configs/config.xml
    • instance2/
      • syncthing_configs/config.xml

e.g:

Windows

Here a batch file that starts two instances at once:

@echo off
prompt -$G
cd /d "%~dp0"

set syncthing_exe=D:\path\to\syncthing.exe

title syncthing test%1

if "%1"=="" (
    echo on
    @echo.
    @echo Start instance 01
    start cmd.exe /K "%~0" 01

    @echo.
    @echo Start instance 02
    start cmd.exe /K "%~0" 02

    @echo off
    echo.
    echo This window can be closed.
    pause
    goto:eof
)

REM Start one instance
echo on
set HOMEDRIVE=D:
set HOMEPATH=\synthing_test\instance%1
set USERPROFILE=%HOMEDRIVE%%HOMEPATH%
set APPDATA=%USERPROFILE%\Roaming
set LOCALAPPDATA=%USERPROFILE%\Local

set COMPUTERNAME=%USERDOMAIN%_test%1
set USERDOMAIN_ROAMINGPROFILE=%USERDOMAIN%_test%1
set USERDOMAIN=%USERDOMAIN%_test%1

%syncthing_exe%
@pause

You must set syncthing_exe and you can change HOMEDRIVE and the start folder of HOMEPATH for your needs.

To cleanup the default Sync repository, adapt this batch:

@echo off
prompt -$G

title %0

set BASE=D:\synthing_test\instance

echo on

rmdir /q /s %BASE%01\Sync
del %BASE%01\Local\Syncthing\*.gz

@echo.

rmdir /q /s %BASE%02\Sync
del %BASE%02\Local\Syncthing\*.gz
@pause

Links

Creating a directory with many files:

mkdir manyfiles
cd manyfiles
for i in $(seq 1 999); do for j in $(seq 1 99); do touch $i-$j; done; done
ls | wc -

You can check if the file list is the same on both sides by creating a list, e.g. ls > list1 on the one side, ls > list2 on the other; at the end diff list1 list2.

Creating a directory with big files:

mkdir bigfiles
cd bigfiles
for i in $(seq 1 10); do dd if=/dev/urandom of=test-$i bs=1M count=1000; done
ls -l

You may wish to check the md5sum of files before and after sync to be certain here: md5sum * > list1 on Alice; md5sum * > list2 on Bob; diff list1 list2.

There’s a bunch of utilities and test scripts in https://github.com/calmh/syncthing/tree/master/integration as well.