2 system ? builtins.currentSystem,
4 pkgs ? import ../../.. { inherit system config; },
9 inherit (import ./common.nix { inherit pkgs lib; }) mkTestName mariadbPackages;
11 replicateUser = "replicate";
12 replicatePassword = "secret";
14 makeTest = import ./../make-test-python.nix;
16 makeReplicationTest = {
18 name ? mkTestName package,
20 name = "${name}-replication";
22 maintainers = lib.teams.helsinki-systems.members;
30 replication.role = "master";
31 replication.slaveHost = "%";
32 replication.masterUser = replicateUser;
33 replication.masterPassword = replicatePassword;
34 initialDatabases = [ { name = "testdb"; schema = ./testdb.sql; } ];
36 networking.firewall.allowedTCPPorts = [ 3306 ];
39 secondary1 = { nodes, ... }: {
43 replication.role = "slave";
44 replication.serverId = 2;
45 replication.masterHost = nodes.primary.networking.hostName;
46 replication.masterUser = replicateUser;
47 replication.masterPassword = replicatePassword;
51 secondary2 = { nodes, ... }: {
55 replication.role = "slave";
56 replication.serverId = 3;
57 replication.masterHost = nodes.primary.networking.hostName;
58 replication.masterUser = replicateUser;
59 replication.masterPassword = replicatePassword;
66 primary.wait_for_unit("mysql")
67 primary.wait_for_open_port(3306)
68 # Wait for testdb to be fully populated (5 rows).
69 primary.wait_until_succeeds(
70 "sudo -u mysql mysql -u mysql -D testdb -N -B -e 'select count(id) from tests' | grep -q 5"
75 secondary1.wait_for_unit("mysql")
76 secondary1.wait_for_open_port(3306)
77 secondary2.wait_for_unit("mysql")
78 secondary2.wait_for_open_port(3306)
80 # wait for replications to finish
81 secondary1.wait_until_succeeds(
82 "sudo -u mysql mysql -u mysql -D testdb -N -B -e 'select count(id) from tests' | grep -q 5"
84 secondary2.wait_until_succeeds(
85 "sudo -u mysql mysql -u mysql -D testdb -N -B -e 'select count(id) from tests' | grep -q 5"
88 secondary2.succeed("systemctl stop mysql")
90 "echo 'insert into testdb.tests values (123, 456);' | sudo -u mysql mysql -u mysql -N"
92 secondary2.succeed("systemctl start mysql")
93 secondary2.wait_for_unit("mysql")
94 secondary2.wait_for_open_port(3306)
95 secondary2.wait_until_succeeds(
96 "echo 'select * from testdb.tests where Id = 123;' | sudo -u mysql mysql -u mysql -N | grep 456"
101 lib.mapAttrs (_: package: makeReplicationTest { inherit package; }) mariadbPackages