Skip to content

Commit 7022d5b

Browse files
committed
Unit tests for ranged GTID updates.
1 parent 23c153f commit 7022d5b

2 files changed

Lines changed: 120 additions & 5 deletions

File tree

test/tap/tests/Makefile

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,7 @@ CUSTOMARGS += -Wl,-Bdynamic -lcpp_dotenv -lcurl -lssl -lcrypto -lre2 -lpthread -
9393
.PHONY: all
9494
all: tests
9595

96-
debug: OPT := $(STDCPP) -O0 -DDEBUG -ggdb -Wl,--no-as-needed -Wl,-rpath,$(TAP_LDIR) $(WGCOV) $(WASAN) -DGITVERSION=\"$(GIT_VERSION)\"
97-
debug: tests
98-
99-
tests: CUSTOMARGS += $(OPT)
100-
tests: tests-cpp \
96+
tap-tests: tests-cpp \
10197
tests-php \
10298
tests-py \
10399
tests-sh \
@@ -125,6 +121,15 @@ tests: tests-cpp \
125121
fast_forward_switch_replication_deprecate_eof_libmysql-t \
126122
reg_test_mariadb_stmt_store_result_libmysql-t \
127123
reg_test_mariadb_stmt_store_result_async-t
124+
125+
unit-tests: \
126+
unit-proxysql_gtid-t
127+
128+
debug: OPT := $(STDCPP) -O0 -DDEBUG -ggdb -Wl,--no-as-needed -Wl,-rpath,$(TAP_LDIR) $(WGCOV) $(WASAN) -DGITVERSION=\"$(GIT_VERSION)\"
129+
debug: tests
130+
131+
tests: CUSTOMARGS += $(OPT)
132+
tests: tap-tests unit-tests
128133
tests:
129134
@echo "Removing empty .gcno files ..."
130135
find -L . -type f -name '*.gcno' -empty -ls -delete
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
#include <stdlib.h>
2+
3+
#include "tap.h"
4+
#include "unit_test.h"
5+
#include "proxysql_gtid.h"
6+
7+
using std::string;
8+
9+
int testGtidIntervalFromString_Count() {
10+
return 2;
11+
}
12+
void testGtidIntervalFromString() {
13+
ok(gtid_interval_t("123-456") == gtid_interval_t(123, 456), "GTID interval from range string");
14+
ok(gtid_interval_t("111") == gtid_interval_t(111, 111), "GTID interval from single GTID string");
15+
}
16+
17+
int testGtidIntervalContains_Count() {
18+
return 8;
19+
}
20+
void testGtidIntervalContains() {
21+
auto iv = gtid_interval_t(123, 456);
22+
23+
ok(iv.contains(123), "GTID interval contains start");
24+
ok(iv.contains(456), "GTID interval contains end");
25+
ok(iv.contains(300), "GTID interval contains middle");
26+
ok(!iv.contains(100), "GTID interval doesn't contain before start");
27+
ok(!iv.contains(500), "GTID interval doesn't contain past end");
28+
ok(!iv.contains(gtid_interval_t(100, 300)), "GTID interval doesn't contain range before start");
29+
ok(!iv.contains(gtid_interval_t(300, 500)), "GTID interval doesn't contain range past end");
30+
ok(iv.contains(gtid_interval_t(150, 310)), "GTID interval contains range");
31+
}
32+
33+
int testGtidIntervalAppend_Count() {
34+
return 7;
35+
}
36+
void testGtidIntervalAppend() {
37+
auto iv = gtid_interval_t(123, 456);
38+
39+
ok(!iv.append(gtid_interval_t(90, 100)), "cannot append before range start");
40+
ok(!iv.append(gtid_interval_t(100, 200)), "cannot append at start");
41+
ok(!iv.append(gtid_interval_t(500, 600)), "cannot append past end");
42+
ok(iv.append(gtid_interval_t(457, 490)), "append");
43+
ok(iv.to_string() == "123-490", "append result");
44+
45+
iv = gtid_interval_t(123, 456);
46+
ok(iv.append(gtid_interval_t(200, 600)), "append with overlap");
47+
ok(iv.to_string() == "123-600", "append with overlap result");
48+
}
49+
50+
int testGtidIntervalMerge_Count() {
51+
return 14;
52+
}
53+
void testGtidIntervalMerge() {
54+
auto iv = gtid_interval_t(123, 456);
55+
ok(!iv.merge(gtid_interval_t(90, 100)), "cannot merge before range start");
56+
ok(!iv.merge(gtid_interval_t(500, 600)), "cannot merge past range end");
57+
ok(iv.merge(gtid_interval_t(90, 200)), "merge at start");
58+
ok(iv == gtid_interval_t(90, 456), "merge at start result");
59+
60+
iv = gtid_interval_t(123, 456);
61+
ok(iv.merge(gtid_interval_t(300, 500)), "merge at end");
62+
ok(iv == gtid_interval_t(123, 500), "merge at end result");
63+
64+
iv = gtid_interval_t(123, 456);
65+
ok(iv.merge(gtid_interval_t(200, 300)), "merge at middle");
66+
ok(iv == gtid_interval_t(123, 456), "merge at middle result");
67+
68+
iv = gtid_interval_t(123, 456);
69+
ok(iv.merge(gtid_interval_t(100, 500)), "merge overlap");
70+
ok(iv == gtid_interval_t(100, 500), "merge overlap result");
71+
72+
iv = gtid_interval_t(123, 456);
73+
ok(iv.merge(gtid_interval_t(100, 122)), "merge append at start");
74+
ok(iv == gtid_interval_t(100, 456), "merge append at start result");
75+
76+
iv = gtid_interval_t(123, 456);
77+
ok(iv.merge(gtid_interval_t(457, 600)), "merge append at end");
78+
ok(iv == gtid_interval_t(123, 600), "merge append at end result");
79+
}
80+
81+
std::function<int(void)> testFunctionCounts[] = {
82+
testGtidIntervalFromString_Count,
83+
testGtidIntervalContains_Count,
84+
testGtidIntervalAppend_Count,
85+
testGtidIntervalMerge_Count,
86+
NULL,
87+
};
88+
std::function<void(void)> testFunctions[] = {
89+
testGtidIntervalFromString,
90+
testGtidIntervalContains,
91+
testGtidIntervalAppend,
92+
testGtidIntervalMerge,
93+
NULL,
94+
};
95+
96+
int main(int argc, char** argv) {
97+
// Set up unit tests...
98+
int n = 0;
99+
for (auto i = 0; testFunctionCounts[i] != NULL; i++) {
100+
n += testFunctionCounts[i]();
101+
}
102+
plan(n);
103+
104+
// ...and run them.
105+
for (auto i = 0; testFunctions[i] != NULL; i++) {
106+
testFunctions[i]();
107+
}
108+
109+
return exit_status();
110+
}

0 commit comments

Comments
 (0)