How to setup a small test environment?

Sometimes is will be good, to have a small test instance. Only one repro with only a handfull of files.

How to setup this?

e.g.: It is possible to run more than one instance on the same machine and sync “via” localhost?

Run one instance, chnage the ports and start another instance and change the ports?!?

Maybe use “-home” to use different .config directories?

There’s a script, which is fairly involved, that does this, in https://github.com/calmh/syncthing/blob/master/integration/test.sh. The basics is to just start multiple instances with separate listening ports and hard code the node address/port since local discovery doesn’t work within the same host.

Hm, didn’t see how it helps.

I’m working on something like this:

Startup file 01:

#!/bin/bash

BASE_DIR=$(pwd)/instance01/
SYNCTHING_BIN=/home/syncthing/bin/syncthing

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

and startup file 02:

#!/bin/bash

BASE_DIR=$(pwd)/instance02/
SYNCTHING_BIN=/home/syncthing/bin/syncthing

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

)

Only the BASE_DIR is changed.

Start first skript and change ports. Start second script and change ports. Will result in something like this:

The configs looks like this:

config from instance01:

<configuration version="2">
    <repository id="default" directory="/home/jens/syncthing_test/instance01/Sync" ro="false" ignorePerms="false">
        <node id="DB4B7IURXQSOXYPIRGHANDTUAJFRWIG7U5SMV3UYALVSLLPCPHNA"></node>
        <node id="HN7FVKI4NQNYFPXY2MBDJUCOKOVD3KSTIRVPM25MWP2UISYNP6WA"></node>
        <versioning type="simple">
            <param key="keep" val="5"></param>
        </versioning>
    </repository>
    <node id="DB4B7IURXQSOXYPIRGHANDTUAJFRWIG7U5SMV3UYALVSLLPCPHNA" name="instance01">
        <address>127.0.0.1:22001</address>
    </node>
    <node id="HN7FVKI4NQNYFPXY2MBDJUCOKOVD3KSTIRVPM25MWP2UISYNP6WA" name="instance02">
        <address>127.0.0.1:22002</address>
    </node>
    <gui enabled="true" tls="false">
        <address>127.0.0.1:8001</address>
    </gui>
    <options>
        <listenAddress>127.0.0.1:22001</listenAddress>
        <globalAnnounceServer>announce.syncthing.net:22025</globalAnnounceServer>
        <globalAnnounceEnabled>false</globalAnnounceEnabled>
        <localAnnounceEnabled>false</localAnnounceEnabled>
        <localAnnouncePort>21026</localAnnouncePort>
        <parallelRequests>16</parallelRequests>
        <maxSendKbps>0</maxSendKbps>
        <rescanIntervalS>3</rescanIntervalS>
        <reconnectionIntervalS>60</reconnectionIntervalS>
        <maxChangeKbps>10000</maxChangeKbps>
        <startBrowser>true</startBrowser>
        <upnpEnabled>false</upnpEnabled>
    </options>
</configuration>

config from instance02:

<configuration version="2">
    <repository id="default" directory="/home/jens/syncthing_test/instance02/Sync" ro="false" ignorePerms="false">
        <node id="HN7FVKI4NQNYFPXY2MBDJUCOKOVD3KSTIRVPM25MWP2UISYNP6WA"></node>
        <node id="DB4B7IURXQSOXYPIRGHANDTUAJFRWIG7U5SMV3UYALVSLLPCPHNA"></node>
        <versioning type="simple">
            <param key="keep" val="5"></param>
        </versioning>
    </repository>
    <node id="DB4B7IURXQSOXYPIRGHANDTUAJFRWIG7U5SMV3UYALVSLLPCPHNA" name="instance01">
        <address>127.0.0.1:22001</address>
    </node>
    <node id="HN7FVKI4NQNYFPXY2MBDJUCOKOVD3KSTIRVPM25MWP2UISYNP6WA" name="instance02">
        <address>127.0.0.1:22002</address>
    </node>
    <gui enabled="true" tls="false">
        <address>127.0.0.1:8002</address>
    </gui>
    <options>
        <listenAddress>127.0.0.1:22002</listenAddress>
        <globalAnnounceServer>announce.syncthing.net:22025</globalAnnounceServer>
        <globalAnnounceEnabled>false</globalAnnounceEnabled>
        <localAnnounceEnabled>false</localAnnounceEnabled>
        <localAnnouncePort>21027</localAnnouncePort>
        <parallelRequests>16</parallelRequests>
        <maxSendKbps>0</maxSendKbps>
        <rescanIntervalS>3</rescanIntervalS>
        <reconnectionIntervalS>60</reconnectionIntervalS>
        <maxChangeKbps>10000</maxChangeKbps>
        <startBrowser>true</startBrowser>
        <upnpEnabled>false</upnpEnabled>
    </options>
</configuration>

I update configs…

It works fine!

The error from https://github.com/calmh/syncthing/issues/284 didn’t happen.

set a other HOME= under linux for testing, is IMHO a good solution.

I would like to do the same under windows. I looked into https://github.com/calmh/syncthing/blob/master/cmd/syncthing/main.go and see some environment variables that are used under windows. So i created a batch start file for this:

@title syncthing test

set HOMEDRIVE=D:
set HOMEPATH=\synthing_test
set USERPROFILE=%HOMEDRIVE%%HOMEPATH%
set APPDATA=%USERPROFILE%\Roaming
set LOCALAPPDATA=%USERPROFILE%\Local

syncthing.exe
@pause

What i didn’t find out, how the computer name are get trou. I tried this:

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

Doesn’t work. But ok, i start it one time and change the config.

So now i can setup a “test” network on linux and windows, independently from productive usage :wink:

I have created https://github.com/jedie/syncthing/wiki/Test-Syncthing for this.

EDIT: New topic here -> How to create Syncthing test environments