]> git.scottworley.com Git - syncthing-autoregister/commitdiff
Fix race: Re-register on file change
authorScott Worley <scottworley@scottworley.com>
Tue, 28 Jul 2020 00:48:19 +0000 (17:48 -0700)
committerScott Worley <scottworley@scottworley.com>
Tue, 28 Jul 2020 00:48:19 +0000 (17:48 -0700)
modules/syncthing-autoregister.nix
tests/automatic-enrollment.nix

index da9df86d1f41e59293af54d9fb525069204ae0ca..ad710f66e6ba450c4fb71e0ec419052f65c45a5e 100644 (file)
@@ -45,6 +45,20 @@ in {
         ExecStart = register-script;
       };
     };
         ExecStart = register-script;
       };
     };
+    systemd.services.syncthing-reregister = {
+      after = [ "syncthing-autoregister.service" ];
+      script = ''
+        ${pkgs.coreutils}/bin/sleep 1
+        ${pkgs.systemd}/bin/systemctl restart syncthing-autoregister
+      '';
+      serviceConfig = {
+        Type = "oneshot";
+      };
+    };
+    systemd.paths.syncthing-reregister = {
+      pathConfig.PathChanged = cfg.path;
+      wantedBy = [ "multi-user.target" ];
+    };
   };
 }
 
   };
 }
 
index 951a4153e000be6bb453522fab7f4bcde415d1f4..617f672e4da38f157986db9d2f7b2d1ef3be764b 100644 (file)
@@ -57,7 +57,7 @@ import <nixpkgs/nixos/tests/make-test-python.nix> ({ pkgs, lib, ... }:
 
 
       def verifyDeviceIDSet(machine, expectedDevice):
 
 
       def verifyDeviceIDSet(machine, expectedDevice):
-          machine.succeed(
+          machine.wait_until_succeeds(
               '(( "$(nix eval --raw -f "<nixos/nixos>" config.services.syncthing.declarative.devices.%s.id | wc -c)" == 63 ))'
               % expectedDevice
           )
               '(( "$(nix eval --raw -f "<nixos/nixos>" config.services.syncthing.declarative.devices.%s.id | wc -c)" == 63 ))'
               % expectedDevice
           )
@@ -82,16 +82,16 @@ import <nixpkgs/nixos/tests/make-test-python.nix> ({ pkgs, lib, ... }:
           "${configurationWithDeviceIDs}"
       )
 
           "${configurationWithDeviceIDs}"
       )
 
+      start_all()
       a.wait_for_unit("syncthing-autoregister.service")
       setConfig(a, configurationWithDeviceIDs)
       verifyDeviceIDSet(a, "a")
       getDeviceFile(a)
 
       a.wait_for_unit("syncthing-autoregister.service")
       setConfig(a, configurationWithDeviceIDs)
       verifyDeviceIDSet(a, "a")
       getDeviceFile(a)
 
+      b.wait_for_unit("syncthing-autoregister.service")
       putDeviceFile(b)
       setConfig(b, configurationWithDeviceIDs)
       verifyDeviceIDSet(b, "a")
       putDeviceFile(b)
       setConfig(b, configurationWithDeviceIDs)
       verifyDeviceIDSet(b, "a")
-      b.wait_for_unit("syncthing-autoregister.service")
-      verifyDeviceIDSet(b, "a")
       verifyDeviceIDSet(b, "b")
     '';
   })
       verifyDeviceIDSet(b, "b")
     '';
   })