| 1 |
= About = |
| 2 |
This directory proposes a unit tests suite for OAR's scheduler. |
| 3 |
It basically consists of a framework to help writing little scripts that will check the scheduler's decisions. |
| 4 |
|
| 5 |
Since OAR's API comes down to the Database, input and output data for the unit tests are SQL data. |
| 6 |
|
| 7 |
Input data are SQL file to be generated using mysqldump on a live OAR installation, or on a fake installation where resources aren't real (e.g. all resources targets are on the single test machine), then injected in the test database. |
| 8 |
|
| 9 |
Output data is actually the test database as it is let once the scheduler ran. |
| 10 |
Unit test results are to be computed using SQL statements on that database. |
| 11 |
|
| 12 |
Several ideas behind this test framework come from Perl unit test packages mechanism (Test::More). |
| 13 |
|
| 14 |
= Notes = |
| 15 |
As a matter of implementation, it was needed to be able to run the Database server with a faked time, so that input SQL files are not outdated once inserted later after their creation. This is achieved using the faketime program, and tranparent thanks to the framework functions. |
| 16 |
|
| 17 |
Only the MySQL database is supported for now. |
| 18 |
|
| 19 |
A dedicated MySQL server is run for tests, hence you must watch out which TCP port is available: by default the dedicated MySQL server run on the 3307 port in order to avoid an obvious conflict with the default MySQL server instance which might be run on system startup. |
| 20 |
|
| 21 |
= Files = |
| 22 |
Any test is a file which is prefixed by 3 digits, e.g. 001_advance_reservation_with_absent_resource.sh . |
| 23 |
|
| 24 |
A test file uses file with the same prefix in the "data" directory, e.g. 001_oar.conf . |
| 25 |
|
| 26 |
Tests use bash functions that are defined in the "scripts" directory. |
| 27 |
|
| 28 |
Upon a test script execution, the execution environement is created in the "build" directory. |
| 29 |
|
| 30 |
Finally the "src" symlink is pointing to OAR source directory where the installation Makefile is located, e.g. <oar svn checkout>/trunk . |
| 31 |
|
| 32 |
= Configuration = |
| 33 |
Running those tests requires: |
| 34 |
* MySQL server |
| 35 |
* MySQL client |
| 36 |
* faketime |
| 37 |
* perl, aso... |
| 38 |
The src symlink pointing to OAR source directory, e.g. <oar svn checkout>/trunk . |
| 39 |
|
| 40 |
= Running tests = |
| 41 |
Running a test is only the matter of running the 3 digit prefixed bash script. |
| 42 |
|
| 43 |
The test might output to stderr a lot of verbose information, but only tests results goes to stdout. |
| 44 |
A test is successful if it outputs only "OK: ..." lines. |
| 45 |
A test fails as soon as it outputs one "KO: ..." line. |
| 46 |
|
| 47 |
= Writing tests = |
| 48 |
The easiest way to write a test is to copy one of the existing one, and adapt it. |
| 49 |
|
| 50 |
The test script process begins with the test_cleanup call, everthing above should be left as it is. |
| 51 |
|
| 52 |
3 kinds of functions are provided: |
| 53 |
* base, which provides the framework base functions, related to the actual testing |
| 54 |
* mysql, which provides functions to handle the MySQL database process |
| 55 |
* oar, which provides functions to handle OAR mechanisms |
| 56 |
|
| 57 |
== base == |
| 58 |
* debug(message) |
| 59 |
Print (to stderr) debug info if debug is activated (DEBUG variable) |
| 60 |
|
| 61 |
* test_print_ok(message) |
| 62 |
Print the OK flag, along with a message |
| 63 |
|
| 64 |
* test_print_ko(message) |
| 65 |
Print the KO flag, along with a message |
| 66 |
|
| 67 |
* test_exit_status(message, command) { |
| 68 |
Print the OK or KO flag depending on the exit status of command, along with a message |
| 69 |
|
| 70 |
* test_preparer() |
| 71 |
Prepare the test environment |
| 72 |
|
| 73 |
* test_cleanup() |
| 74 |
Clean-up the test environment |
| 75 |
|
| 76 |
== MySQL == |
| 77 |
* mysql_check_oar_conf() |
| 78 |
Check that the oar.conf used if ok for the test |
| 79 |
|
| 80 |
* mysql_copy_config(file=my.cnf) |
| 81 |
Fetch mysql config file from the data directory, by adding the test prefix to file. |
| 82 |
file defaults to "my.cnf". |
| 83 |
|
| 84 |
* mysql_init() |
| 85 |
Initialize the dedicated MySQL server own data. |
| 86 |
|
| 87 |
* mysql_start(date=null) |
| 88 |
Start the dedicated MySQL server, possibily a the specified date, or now if no date is given. |
| 89 |
|
| 90 |
* mysql_stop() |
| 91 |
Stop the dedicated MySQL server. |
| 92 |
|
| 93 |
* mysql_create_oar_db() |
| 94 |
Create the oar DB, as given in oar.conf, and grant privilegies. |
| 95 |
|
| 96 |
* mysql_query(query) |
| 97 |
Run the SQL query that is provided as parameter. |
| 98 |
|
| 99 |
* mysql_query_from_file(file) |
| 100 |
Run the SQL query from file, looked up in the data directory after prepending the test prefix. |
| 101 |
|
| 102 |
== OAR == |
| 103 |
* oar_copy_config(file=oar.conf) |
| 104 |
Fetch OAR config file from the data directory, by adding the test prefix to file. |
| 105 |
file defaults to "oar.conf". |
| 106 |
|
| 107 |
* oar_source_conf() |
| 108 |
Source OAR parameters, making then available for the test functions. |
| 109 |
|
| 110 |
* oar_install() |
| 111 |
Perform OAR installation within the test enviroment. |
| 112 |
|
| 113 |
oar_run_scheduler() |
| 114 |
Run one pass of OAR meta scheduler, i.e. one pass of the queue's scheduler on each queue. |
| 115 |
|