This manual is intended to give developers a comprehensive guidance to test TDengine efficiently. It is divided into three main sections: introduction, prerequisites and testing guide.
Note
- The commands and scripts below are verified on Linux (Ubuntu 18.04/20.04/22.04).
- The commands and steps described below are to run the tests on a single host.
- Install Python3
apt install python3
apt install python3-pip
- Install Python dependencies
pip3 install pandas psutil fabric2 requests faker simplejson \
toml pexpect tzlocal distro decorator loguru hyperloglog
- Install Python connector for TDengine
pip3 install taospy taos-ws-py
- Building
Before testing, please make sure the building operation with option -DBUILD_TOOLS=true -DBUILD_TEST=true -DBUILD_CONTRIB=true
has been done, otherwise execute commands below:
cd debug
cmake .. -DBUILD_TOOLS=true -DBUILD_TEST=true -DBUILD_CONTRIB=true
make && make install
In tests
directory, there are different types of tests for TDengine. Below is a brief introduction about how to run them and how to add new cases.
Unit tests are the smallest testable units, which are used to test functions, methods or classes in TDengine code.
cd debug/build/bin
./osTimeTests
cd tests/unit-test/
bash test.sh -e 0
Detailed steps to add new unit test case
The Google test framwork is used for unit testing to specific function module, please refer to steps below to add a new test case:
In the test directory corresponding to the target function module, create test files in CPP format and write corresponding test cases.
Modify the CMakeLists.txt file in this directory to ensure that the new test files are properly included in the compilation process. See the source/os/test/CMakeLists.txt
file for configuration examples.
In the root directory of the project, create a compilation directory (e.g., debug), switch to the directory and run CMake commands (e.g., cmake .. -DBUILD_TEST=1
) to generate a compilation file,
and then run a compilation command (e.g. make) to complete the compilation of the test code.
Find the executable file in the compiled directory(e.g. TDengine/debug/build/bin/
) and run it.
Use the add_test command to add new compiled test cases into CI test collection, ensure that the new added test cases can be run for every build.
System tests are end-to-end test cases written in Python from a system point of view. Some of them are designed to test features only in enterprise ediiton, so when running on community edition, they may fail. We'll fix this issue by separating the cases into different gruops in the future.
Take test file system-test/2-query/avg.py
for example:
cd tests/system-test
python3 ./test.py -f 2-query/avg.py
cd tests
./run_all_ci_cases.sh -t python # all python cases
Detailed steps to add new system test case
The Python test framework is developed by TDengine team, and test.py is the test case execution and monitoring of the entry program, Use python3 ./test.py -h
to view more features.
Please refer to steps below for how to add a new test case:
Create a file in tests/system-test
containing each functional directory and refer to the use case template tests/system-test/0-others/test_case_template.py
to add a new test case.
Ensure the test case execution is successful.
cd tests/system-test && python3 ./test.py -f 0-others/test_case_template.py
Edit tests/parallel_test/cases.task
and add the testcase path and executions in the specified format. The third column indicates whether to use Address Sanitizer mode for testing.
#caseID,rerunTimes,Run with Sanitizer,casePath,caseCommand
,,n,system-test, python3 ./test.py -f 0-others/test_case_template.py
In the early stage of TDengine development, test cases are run by an internal test framework called TSIM, which is developed in C++.
To run the legacy test cases, please execute the following commands:
cd tests/script
./test.sh -f tsim/db/basic1.sim
cd tests
./run_all_ci_cases.sh -t legacy # all legacy cases
Note
TSIM test framwork is deprecated by system test now, it is encouraged to add new test cases in system test, please refer to System Test for details.
Smoke test is a group of test cases selected from system test, which is also known as sanity test to ensure the critical functionalities of TDengine.
cd /root/TDengine/packaging/smokeTest
./test_smoking_selfhost.sh
New cases can be added by updating the value of commands
variable in test_smoking_selfhost.sh
.
A simple tool to execute various functions of the system in a randomized way, hoping to expose potential problems without a pre-defined test scenario.
cd tests/pytest
python3 auto_crash_gen.py
- Add a function, such as
TaskCreateNewFunction
inpytest/crash_gen/crash_gen_main.py
. - Integrate
TaskCreateNewFunction
into thebalance_pickTaskType
function incrash_gen_main.py
.
CI testing (Continuous Integration testing), is an important practice in software development that aims to automate frequent integration of code into a shared codebase, build and test it to ensure code quality and stability.
TDengine CI testing will run all the test cases from the following three types of tests: unit test, system test and legacy test.
If this is the first time to run all the CI test cases, it is recommended to add the test branch, please run it with following commands:
cd tests
./run_all_ci_cases.sh -b main # on main branch
Please refer to the Unit Test、System Test and Legacy Test sections for detailed steps to add new test cases, when new cases are added in aboved tests, they will be run automatically by CI test.