mysql: fix replication tests (#17174)

Eliminate race condition in replication test
Remove replication configuration from standalone test
Improve mysql command syntax consistency

authored by ben smith and committed by Rok Garbas c38e6a2a e8343fbb

+9 -10
+2 -1
nixos/modules/services/databases/mysql.nix
··· 240 240 # Set up the replication master 241 241 242 242 ( echo "use mysql;" 243 + echo "CREATE USER '${cfg.replication.masterUser}'@'${cfg.replication.slaveHost}' IDENTIFIED WITH mysql_native_password;" 244 + echo "SET PASSWORD FOR '${cfg.replication.masterUser}'@'${cfg.replication.slaveHost}' = PASSWORD('${cfg.replication.masterPassword}');" 243 245 echo "GRANT REPLICATION SLAVE ON *.* TO '${cfg.replication.masterUser}'@'${cfg.replication.slaveHost}';" 244 - echo "update user set Password=password('${cfg.replication.masterPassword}') where User='${cfg.replication.masterUser}';" 245 246 ) | ${mysql}/bin/mysql -u root -N 246 247 ''} 247 248
+7 -8
nixos/tests/mysql-replication.nix
··· 19 19 services.mysql.enable = true; 20 20 services.mysql.package = pkgs.mysql; 21 21 services.mysql.replication.role = "master"; 22 + services.mysql.replication.slaveHost = "%"; 23 + services.mysql.replication.masterUser = replicateUser; 24 + services.mysql.replication.masterPassword = replicatePassword; 22 25 services.mysql.initialDatabases = [ { name = "testdb"; schema = ./testdb.sql; } ]; 23 - services.mysql.initialScript = pkgs.writeText "initmysql" 24 - '' 25 - create user '${replicateUser}'@'%' identified by '${replicatePassword}'; 26 - grant replication slave on *.* to '${replicateUser}'@'%'; 27 - ''; 28 26 networking.firewall.allowedTCPPorts = [ 3306 ]; 29 27 }; 30 28 ··· 56 54 }; 57 55 58 56 testScript = '' 59 - startAll; 60 - 57 + $master->start; 61 58 $master->waitForUnit("mysql"); 62 - $master->waitForUnit("mysql"); 59 + $slave1->start; 60 + $slave2->start; 61 + $slave1->waitForUnit("mysql"); 63 62 $slave2->waitForUnit("mysql"); 64 63 $slave2->sleep(100); # Hopefully this is long enough!! 65 64 $slave2->succeed("echo 'use testdb; select * from tests' | mysql -u root -N | grep 4");
-1
nixos/tests/mysql.nix
··· 10 10 11 11 { 12 12 services.mysql.enable = true; 13 - services.mysql.replication.role = "master"; 14 13 services.mysql.initialDatabases = [ { name = "testdb"; schema = ./testdb.sql; } ]; 15 14 services.mysql.package = pkgs.mysql; 16 15 };