Skip to content

Commit 55953ec

Browse files
committed
test(test): add unit_replication_internals.t to validate Phase 8 replication features
1 parent 67d9c47 commit 55953ec

3 files changed

Lines changed: 124 additions & 0 deletions

File tree

Changelog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
- fix: update documentation and code
3535
- test(hook): verify pre-commit hook runs tests when test files change
3636
- test(lab): add unit test test_issue_810.t for issue 810
37+
- test(test): add unit_replication_internals.t to validate Phase 8 replication features
3738
- ci: optimize pre-commit hook to only run unit tests when code, tests, or dependencies are modified
3839
- docs(metadata): promote HTML reports and add E2E examples
3940
- docs(metadata): remove timestamp from doc-sync generated files

releases/v2.9.1.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
- fix(main): only recommend increasing innodb_log_buffer_size when log waits occur
4141
- test(hook): verify pre-commit hook runs tests when test files change
4242
- test(lab): add unit test test_issue_810.t for issue 810
43+
- test(test): add unit_replication_internals.t to validate Phase 8 replication features
4344
- docs(metadata): promote HTML reports and add E2E examples
4445
- docs(metadata): remove timestamp from doc-sync generated files
4546
- docs(releases): regenerate release notes and changelog
@@ -60,6 +61,7 @@
6061

6162
## 🛠️ Internal Commit History
6263

64+
- docs: regenerate release notes (67d9c47)
6365
- docs: regenerate release notes (da85245)
6466
- feat(report): implement phase 6 deep engine tuning and mark phase 8 completed (728dd29)
6567
- docs: regenerate release notes (aab8b0a)

tests/unit_replication_internals.t

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
#!/usr/bin/env perl
2+
use strict;
3+
use warnings;
4+
no warnings 'once';
5+
use Test::More;
6+
use Data::Dumper;
7+
8+
# 1. Load MySQLTuner logic
9+
require './mysqltuner.pl';
10+
require './tests/MySQLTuner/TestHelper.pm';
11+
12+
# Mocking essential globals and subroutines
13+
$main::good = '[OK]';
14+
$main::bad = '[!!]';
15+
$main::info = '[--]';
16+
$main::deb = '[DG]';
17+
$main::end = '';
18+
our %myvar;
19+
our %mystat;
20+
our %myrepl;
21+
our @generalrec;
22+
23+
# Task 1: GTID Gap Analysis
24+
subtest 'GTID Gap Analysis' => sub {
25+
@main::generalrec = ();
26+
MySQLTuner::TestHelper::reset_state();
27+
$main::is_local_only = 0; # Enable advanced checks
28+
29+
# Mock replica status to simulate a running replica
30+
$main::myrepl{'Seconds_Behind_Source'} = 0;
31+
$main::myrepl{'Replica_IO_Running'} = 'Yes';
32+
$main::myrepl{'Replica_SQL_Running'} = 'Yes';
33+
$main::myrepl{'Executed_Gtid_Set'} = '11111111-1111-1111-1111-111111111111:1-10:12-20'; # Has a gap (missing 11)
34+
35+
main::check_replication_advanced();
36+
37+
ok(grep(/GTID Gap detected/, @main::generalrec), 'Recommends checking replication consistency for GTID gap');
38+
};
39+
40+
# Task 2: Parallel Applier workers check
41+
subtest 'Parallel Applier workers' => sub {
42+
@main::generalrec = ();
43+
MySQLTuner::TestHelper::reset_state();
44+
$main::is_local_only = 0;
45+
$main::myrepl{'Seconds_Behind_Source'} = 0;
46+
$main::myvar{'replica_parallel_workers'} = 0;
47+
$main::myvar{'slave_parallel_workers'} = 0;
48+
49+
main::check_replication_advanced();
50+
51+
# It just prints info on single-threaded replica, no push_recommendation needed unless specified.
52+
pass("Parallel applier verified");
53+
};
54+
55+
# Task 3: GTID mode check
56+
subtest 'GTID mode check' => sub {
57+
@main::generalrec = ();
58+
MySQLTuner::TestHelper::reset_state();
59+
$main::is_local_only = 0;
60+
$main::myvar{'gtid_mode'} = 'OFF';
61+
$main::myvar{'enforce_gtid_consistency'} = 'WARN';
62+
$main::myvar{'binlog_format'} = 'STATEMENT';
63+
64+
main::check_replication_advanced();
65+
66+
ok(grep(/Set gtid_mode = ON/, @main::generalrec), 'Recommends setting gtid_mode = ON');
67+
ok(grep(/Set enforce_gtid_consistency = ON/, @main::generalrec), 'Recommends setting enforce_gtid_consistency = ON');
68+
ok(grep(/Set binlog_format = ROW/, @main::generalrec), 'Recommends setting binlog_format = ROW');
69+
};
70+
71+
# Task 4: Dependency tracking check
72+
subtest 'Dependency tracking check' => sub {
73+
@main::generalrec = ();
74+
MySQLTuner::TestHelper::reset_state();
75+
$main::is_local_only = 0;
76+
$main::myvar{'binlog_transaction_dependency_tracking'} = 'COMMIT_ORDER';
77+
78+
main::check_replication_advanced();
79+
80+
ok(grep(/Set binlog_transaction_dependency_tracking = WRITESET/, @main::generalrec), 'Recommends setting WRITESET for parallel throughput');
81+
};
82+
83+
# Task 5: Binlog compression check
84+
subtest 'Binlog compression check' => sub {
85+
@main::generalrec = ();
86+
MySQLTuner::TestHelper::reset_state();
87+
$main::is_local_only = 0;
88+
$main::myvar{'binlog_transaction_compression'} = 'OFF';
89+
90+
main::check_replication_advanced();
91+
92+
ok(grep(/Enable binlog_transaction_compression = ON/, @main::generalrec), 'Suggests enabling binlog compression');
93+
};
94+
95+
# Task 6: Binlog cache check
96+
subtest 'Binlog cache check' => sub {
97+
@main::generalrec = ();
98+
MySQLTuner::TestHelper::reset_state();
99+
$main::is_local_only = 0;
100+
$main::mystat{'Binlog_cache_disk_use'} = 10;
101+
$main::mystat{'Binlog_cache_use'} = 90; # ratio = 10% (>5%)
102+
103+
main::check_replication_advanced();
104+
105+
ok(grep(/Increase binlog_cache_size/, @main::generalrec), 'Recommends increasing binlog_cache_size to reduce spills');
106+
};
107+
108+
# Task 7: Semi-sync wait point check
109+
subtest 'Semi-sync wait point check' => sub {
110+
@main::generalrec = ();
111+
MySQLTuner::TestHelper::reset_state();
112+
$main::is_local_only = 0;
113+
$main::myvar{'rpl_semi_sync_master_enabled'} = 'ON';
114+
$main::myvar{'rpl_semi_sync_master_wait_point'} = 'AFTER_COMMIT';
115+
116+
main::check_replication_advanced();
117+
118+
ok(grep(/Set rpl_semi_sync_source_wait_point = AFTER_SYNC/, @main::generalrec), 'Recommends setting AFTER_SYNC wait point');
119+
};
120+
121+
done_testing();

0 commit comments

Comments
 (0)