Skip to content

test: add initial unit tests and code coverage support #283

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 6 commits into from
May 25, 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
14 changes: 14 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[run]
branch = True
concurrency =
gevent
multiprocessing

[report]
precision = 1
include =
./*
omit =
lib/tarantool-python/*
lib/msgpack-python/*
test/*
10 changes: 10 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,13 @@ jobs:
- name: run regression tests
run: |
make test
- name: code coverage
if: ${{ matrix.python-version == '3.8' && matrix.tarantool-version == '2.7' }}
run: |
pip install coveralls==3.*
make coverage
- name: upload coverage data to coveralls.io
if: ${{ matrix.python-version == '3.8' && matrix.tarantool-version == '2.7' }}
run: coveralls --service=github
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ htmlcov/
.coverage
.coverage.*
.cache
.hypothesis/
nosetests.xml
coverage.xml
*,cover
Expand Down
19 changes: 16 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
MAKEFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
PROJECT_DIR := $(patsubst %/,%,$(dir $(MAKEFILE_PATH)))
TEST_RUN_EXTRA_PARAMS?=
PYTHON?=python

Expand All @@ -13,8 +15,19 @@ luacheck:
luacheck --config .luacheckrc .

test_integration:
$(PYTHON) test/test-run.py --force $(TEST_RUN_EXTRA_PARAMS)
PYTHONPATH=$(PROJECT_DIR) $(PYTHON) test/test-run.py --force $(TEST_RUN_EXTRA_PARAMS)

test: test_integration
test_unittest:
$(PYTHON) -m unittest discover test/unittest/

.PHONY: lint flake8 luacheck test test_integration
test: test_unittest test_integration

coverage:
PYTHON="coverage run" make -f $(MAKEFILE_PATH) test
coverage combine $(PROJECT_DIR) $(PROJECT_DIR)/test
coverage report

clean:
coverage erase

.PHONY: lint flake8 luacheck test test_integration test_unittest
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Tarantool Functional testing framework

[![Coverage Status](https://coveralls.io/repos/github/tarantool/test-run/badge.svg)](https://coveralls.io/github/tarantool/test-run)

### Test Suite

Bunch of tests, that lay down in the subfolder (recursively) with `suite.ini`
Expand Down
4 changes: 2 additions & 2 deletions lib/tarantool_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -905,8 +905,8 @@ def start(self, silent=True, wait=True, wait_load=True, rais=True, args=[],
# Verify that the schema actually was not upgraded.
if self.disable_schema_upgrade:
expected_version = extract_schema_from_snapshot(self.snapshot_path)
actual_version = yaml.safe_load(self.admin.execute(
'box.space._schema:get{"version"}'))[0]
actual_version = tuple(yaml.safe_load(self.admin.execute(
'box.space._schema:get{"version"}'))[0][1:])
if expected_version != actual_version:
color_stdout('Schema version check fails: expected '
'{}, got {}\n'.format(expected_version,
Expand Down
12 changes: 9 additions & 3 deletions lib/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import errno
import os
import sys
import collections
Expand All @@ -24,6 +25,9 @@
PY3 = sys.version_info[0] == 3
PY2 = sys.version_info[0] == 2

if PY2:
FileNotFoundError = IOError

if PY3:
string_types = str,
integer_types = int,
Expand Down Expand Up @@ -283,11 +287,13 @@ def xlog_rows(xlog_path):

Assume tarantool and tarantoolctl is in PATH.
"""
if not os.path.exists(xlog_path):
raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), xlog_path)
cmd = ['tarantoolctl', 'cat', xlog_path, '--format=json', '--show-system']
with open(os.devnull, 'w') as devnull:
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=devnull)
for line in process.stdout.readlines():
yield json.loads(line)
yield json.loads(bytes_to_str(line))


def extract_schema_from_snapshot(snapshot_path):
Expand All @@ -303,15 +309,15 @@ def extract_schema_from_snapshot(snapshot_path):
"BODY": {"space_id": 272, "tuple": ["version", 2, 3, 1]}
}

:returns: [u'version', 2, 3, 1]
:returns: (2, 3, 1)
"""
BOX_SCHEMA_ID = 272
for row in xlog_rows(snapshot_path):
if row['HEADER']['type'] == 'INSERT' and \
row['BODY']['space_id'] == BOX_SCHEMA_ID:
res = row['BODY']['tuple']
if res[0] == 'version':
return res
return tuple(res[1:])
return None


Expand Down
2 changes: 2 additions & 0 deletions requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
coverage==5.*
flake8==3.7.9
hypothesis==4.*
Loading