Skip to content

Add default server restart to each test run #309

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 5 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ and a number of fields:
* `long_run` - mark tests as long, enabled only with `--long` option (delimited
with the space, e.g. `long_run=t1.test.lua t2.test.lua`)
* `config` - test configuration file name
* `pretest_clean` - see [pretest_clean](#pretest_clean)

Field `core` must be one of:

Expand Down Expand Up @@ -338,39 +337,13 @@ test_run:cmd('setopt delimiter ""');
join(test_run, 30)
```

### pretest_clean
### pretest_clean()

Add the following line to `suite.ini` to enable this option for a test suite:
Nothing will be done before a Python test and for `core = unittest`
test suites.

```
pretest_clean = True
```

The behaviour of this option varies across test suite types (`core = tarantool /
app / unittest`).

For a `core = tarantool` test suite enabling of this option will lead to
execution of a special clean function before each Lua test. The
`pretest_clean.lua` file is copied into a test directory (`var/ddd-suite-name`)
and `require('pretest_clean').clean()` is invoked before each test.

This function performs the following steps:

* drop all non-system spaces;
* delete all users except 'guest' and 'admin';
* delete all roles except 'public', 'replicaiton' and 'super';
* delete all `box.space._func` records except `box.schema.user.info`;
* delete all `box.space._cluster` records except one for a current instance;
* remove all global variables except ones that tarantool had at start (it uses a
predefined list, see the source);
* unload all packages except built-in ones (see the source for the list).

Set _G.protected_globals to list of names to protect custom globals.

Nothing will be done before a Python test.

For a `core = app` test suite enabling of this option will lead to removing
tarantool WAL and snapshot files before each test.
For a `core = [app|tarantool]` test suites this function removes tarantool WAL
and snapshot files before each test.

The following files will be removed:

Expand All @@ -380,8 +353,6 @@ The following files will be removed:
* `*.inprogress`
* `[0-9]*/`

For a `core = unittest` test suite this option does not change any behaviour.

### Used By

- [Tarantool](https://github.com/tarantool/tarantool) - in-memory database and application server
Expand Down
29 changes: 2 additions & 27 deletions lib/tarantool_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,25 +122,6 @@ def write_result_file_version_line(self):
sys.stdout.write(self.RESULT_FILE_VERSION_TEMPLATE.format(
self.result_file_version) + '\n')

def execute_pretest_clean(self, ts):
""" Clean globals, loaded packages, spaces, users, roles
and so on before each test if the option is set.

Return True as success (or if this feature is disabled
in suite.ini) and False in case of an error.
"""
if not self.suite_ini['pretest_clean']:
return True

command = "require('pretest_clean').clean()"
result = self.send_command(command, ts, 'lua')
result = result.replace('\r\n', '\n')
if result != '---\n...\n':
sys.stdout.write(result)
return False

return True

def execute_pragma_sql_default_engine(self, ts):
""" Set default engine for an SQL test if it is provided
in a configuration.
Expand Down Expand Up @@ -239,8 +220,6 @@ def flush(self, ts, command_log, command_exe):

def exec_loop(self, ts):
self.write_result_file_version_line()
if not self.execute_pretest_clean(ts):
return
if not self.execute_pragma_sql_default_engine(ts):
return

Expand Down Expand Up @@ -789,10 +768,6 @@ def copy_files(self):
shutil.copy(tntctl_file, self.vardir)
shutil.copy(os.path.join(self.TEST_RUN_DIR, 'test_run.lua'),
self.vardir)
# Need to use get here because of nondefault servers doesn't have ini.
if self.ini.get('pretest_clean', False):
shutil.copy(os.path.join(self.TEST_RUN_DIR, 'pretest_clean.lua'),
self.vardir)

if self.snapshot_path:
# Copy snapshot to the workdir.
Expand All @@ -819,8 +794,8 @@ def prepare_args(self, args=[]):
return cli_args

def pretest_clean(self):
# Don't delete snap and logs for 'default' tarantool server
# because it works during worker lifetime.
# Tarantool servers restarts before each test on the worker.
# Snap and logs are removed within it.
pass

def cleanup(self, *args, **kwargs):
Expand Down
4 changes: 2 additions & 2 deletions lib/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ def execute(self, server):
# Note: don't forget to set 'server.current_test = self' in
# inherited classes. Crash reporting relying on that.
server.current_test = self
if self.suite_ini['pretest_clean']:
server.pretest_clean()
# All the test runs must be isolated between each other on each worker.
server.pretest_clean()

def run(self, server):
""" Execute the test assuming it's a python program. If the test
Expand Down
1 change: 0 additions & 1 deletion lib/test_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ def __init__(self, suite_path, args):
# use old format dictionary
self.fragile['tests'] = self.ini['fragile']

self.parse_bool_opt('pretest_clean', False)
self.parse_bool_opt('use_unix_sockets', False)
self.parse_bool_opt('use_unix_sockets_iproto', False)
self.parse_bool_opt('is_parallel', False)
Expand Down
4 changes: 2 additions & 2 deletions lib/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,13 +350,13 @@ def run_loop(self, task_queue, result_queue):
retries_left = self.suite.fragile_retries()
# let's run till short_status became 'pass'
while short_status != 'pass' and retries_left >= 0:
self.restart_server()
# print message only after some fails occurred
if short_status == 'fail':
self.restart_server()
color_stdout(
'Test "%s", conf: "%s"\n'
'\tfrom "fragile" list failed with results'
' file checksum: "%s", rerunning with server restart ...\n'
' file checksum: "%s", rerunning ...\n'
% (task_id[0], task_id[1], result_checksum), schema='error')
# run task and save the result to short_status
short_status, result_checksum, duration = self.run_task(task_id)
Expand Down
Loading