• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..09-Nov-2021-

READMEH A D09-Nov-20216.9 KiB13399

test_session_detach.ccH A D09-Nov-202123.1 KiB791610

test_session_in_thd.ccH A D09-Nov-20216.8 KiB224147

test_session_info.ccH A D09-Nov-202137.4 KiB1,097842

test_sql_2_sessions.ccH A D09-Nov-202125.4 KiB886685

test_sql_9_sessions.ccH A D09-Nov-202118.9 KiB559458

test_sql_all_col_types.ccH A D09-Nov-202131.1 KiB1,046816

test_sql_cmds_1.ccH A D09-Nov-202124.3 KiB861624

test_sql_commit.ccH A D09-Nov-202126.3 KiB929718

test_sql_complex.ccH A D09-Nov-202131.2 KiB1,020794

test_sql_errors.ccH A D09-Nov-202127 KiB943716

test_sql_lock.ccH A D09-Nov-202134.1 KiB1,003770

test_sql_processlist.ccH A D09-Nov-202125.1 KiB830638

test_sql_replication.ccH A D09-Nov-202126.4 KiB933721

test_sql_shutdown.ccH A D09-Nov-202122.3 KiB791604

test_sql_sqlmode.ccH A D09-Nov-202129.5 KiB1,007762

test_sql_stored_procedures_functions.ccH A D09-Nov-202127.8 KiB961744

test_sql_views_triggers.ccH A D09-Nov-202127.6 KiB961744

test_x_sessions_deinit.ccH A D09-Nov-20218 KiB277179

test_x_sessions_init.ccH A D09-Nov-20219.5 KiB324223

README

1/* Copyright (c) 2015, 2021, Oracle and/or its affiliates.
2
3   This program is free software; you can redistribute it and/or modify
4   it under the terms of the GNU General Public License, version 2.0,
5   as published by the Free Software Foundation.
6
7   This program is also distributed with certain software (including
8   but not limited to OpenSSL) that is licensed under separate terms,
9   as designated in a particular file or component or in included license
10   documentation.  The authors of MySQL hereby grant you an additional
11   permission to link the program and your derivative works with the
12   separately licensed software that they have included with MySQL.
13
14   This program is distributed in the hope that it will be useful,
15   but WITHOUT ANY WARRANTY; without even the implied warranty of
16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   GNU General Public License, version 2.0, for more details.
18
19   You should have received a copy of the GNU General Public License
20   along with this program; if not, write to the Free Software
21   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
22
23Testing plugin services
24-----------------------
25
26Plugin services are usually APIs provided by the mysqld server. Theses APIs can be tested with
27unit test frameworks like "googletest" by developers. In QA it is preferable to test plugin
28services closer to reality with the help of plugins due to following reasons:
29
30  - Integrating plugin, plugin services, clients and SQL layer for testing interaction between all.
31  - Having examples for users close to reality (as described in user manual).
32  - Using our (qa) test tools.
33
34Implementing a test plugin
35--------------------------
36
37Depending on the specification of a plugin service, the test plugin must have a special plugin type
38or even tested with all plugin types.
39
40For the frame work to implement test plugins, the plugin type "daemon" has be chosen. It will be
41loaded (started) with the sql statement "INSTALL PLUGIN" and unloaded (stopped) by calling
42"UNINSTALL PLUGIN". There is no other communication between server and daemon unless it will be
43explicitly implemented, e.g. with the help of an API or service. INSTALL and UNINSTALL will be
44executed by a mtr test. The mtr test may of course contain other sql statements to test the
45interaction between plugin (service) and SQL layer.
46
47The plugin shall write its test results into one or more files. These files can then be written
48into the result file of the mtr test with the normal mtr commands like "cat_file".
49
50With the help of the log_message service the test plugin can easily write messages into
51"mysqld.1.err". These messages can be made visible in the result file or checked as follows:
52Load this log into a table with 2 columns (date, info). The column "date" is ignored as not
53deterministic. The column "info" will be selected by removing "\r" to be compatible to windows
54(The err log file on windows contains CR,LF as newline). Select the messages so they will be
55visible in the mtr result file.
56
57A perl snippet can be used for that purpose, too.
58
59In a plugin status and system (sql) variables can be specified. With status variables the
60state of the test execution can be reported to the mtr test calling the test plugin. That might
61be useful to e.g. give a ready message for a test case or the whole plugin. Especially when
62using threads in a test plugin such status variables are useful to synchronize execution of
63plugin and mtr test as both are running in parallel. System variables can be used to e.g. control
64test execution. But, that is very rudimentary as can be used to configure the plugin as its start.
65
66Test plugins
67------------
68
69There exist test plugins of type "daemon", which can be taken as examples or frameworks and
70calling mtr tests:
71
72  - "plugin/test_services" for the test plugin written in C++,
73  - "mysql-test/suite/test_services" for the corresponding mtr tests.
74
75Test plugins:
76
77  -  "test_services.cc"
78
79     showing how to implement a test plugin for simple plugin services like
80     "my_snprintf" and "my_plugin_log_message". For each of the services there is a function
81     implemented containing the test cases. Instead of using the standard I/O of C++ it is much
82     more comfortable to used "my_open", "my_write", etc. as it covers all platforms. The output
83     of "my_snprintf" can be found in "var/mysqld.1/data/test_services.log".
84     "my_plugin_log_message" writes into "mysqld.1.err". The (selected) contents of these files
85     can be seen in the result file of "test_services.test". "test_services.test" didn't create
86     a thread. The effect is that the test (mysqld) is waiting until the plugin completes its work.
87     A waiting condition to synchronize execution of plugin and mtr test is not necessary.
88
89  -  "test_service_threaded.cc"
90
91     runs the same tests as "test_services.cc", but in a thread. This needs synchronization
92     of plugin and mtr test as both are running in parallel. The synchronization will be done
93     by waiting for the plugin (exactly the thread in the plugin) to be finished. If the
94     thread is needing a very long time then the mtr test may run in a timeout.
95
96  - "test_framework.cc"
97
98     is a rudimentary implementation of a daemon plugin, which can be take to create a new one.
99     Of course copying and modifying/extending one of the other plugins to create a new
100     test plugin can be recommended depending on the need of threads.
101
102Using threads has the advantage of limiting test execution with a timeout. That may be interesting
103for long running plugins, testing complex APIs. Plugins needing a short run time may run without threads.
104
105    To create the plugins and run the test do the following:
106        - modify "CmakeLists.txt" if you want to add a new test plugin,
107        - rebuild ALL or only make test_services by running make in the test_services directory,
108        - in mysql-test: "./mtr --suite=test_services test_services" or
109          "./mtr --suite=test_services test_services_threaded"
110
111    If a test case in plugin "test_services" shall be switched off run the test as follows:
112
113        ./mtr --mysqld=--loose-test-services-with-log-message=0 t/test_services.test
114
115That shows a simple way of control test execution with system variables.
116
117Steps to create a new test plugin
118---------------------------------
119
120The following is an example of steps to create a test plugin for a plugin service relying on
121the daemon type:
122
123  - Create test_<plugin name>.cc file under mysql/plugin/test_plugins deciding if threading
124    is needed or not.
125      - Put the test cases for plugin service to be tested in the init function (preferred) and
126        the clean up in the deinit function.
127      - Add new plugin to plugin.def to make it available to mtr.
128  - Create one or more MTR tests.
129      - MTR test loads plugin and execute the test cases.
130      - After uninstall of the plugin put the test results into the result file of the mtr test.
131      - Create a reference result file.
132
133