This commit is contained in:
fengzero
2023-10-09 08:41:09 +00:00
parent 71f3b3cb24
commit bb52ef5d5f
12 changed files with 120 additions and 33 deletions
+2 -30
View File
@@ -121,7 +121,7 @@ jobs:
gcov_include: include plugins src
gcov_ignore: tests simulator
pyft:
pft:
runs-on: ubuntu-20.04
container: ghcr.io/neugates/build:x86_64-main
@@ -129,7 +129,6 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0
- name: compile
run: |
@@ -138,37 +137,11 @@ jobs:
cmake -DUSE_GCOV=1 .. -DCMAKE_TOOLCHAIN_FILE=../cmake/x86_64-linux-gnu.cmake
make -j4
- name: get neuron current branch
shell: bash
run: |
if [ '${{ github.event_name }}' == 'push' ]; then
branch=${{ github.ref_name }}
elif [ '${{ github.event_name }}' == 'pull_request' ]; then
branch=${{ github.event.pull_request.base.ref }}
elif [ '${{ github.event_name }}' == 'release' ]; then
branch=${{ github.event.release.target_commitish }}
fi
echo "BRANCH=$branch" >> $GITHUB_ENV
echo "neuron current branch is $branch"
- name: fetch neu-ft
uses: actions/checkout@v4
with:
repository: neugates/neu-ft
path: neu-ft
ref: ${{ env.BRANCH }}
- name: function test
run: |
pip install -U pytest
pip install requests
pytest -s neu-ft/neuron
- uses: actions/upload-artifact@v3
with:
name: pyft_result
path: |
neu-ft/neuron/report
pytest -s tests/ft
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
@@ -176,4 +149,3 @@ jobs:
gcov: true
gcov_include: include plugins src
gcov_ignore: tests simulator
-1
View File
@@ -164,7 +164,6 @@ void neu_manager_destroy(neu_manager_t *manager)
UT_array *addrs = neu_node_manager_get_addrs_all(manager->node_manager);
neu_event_del_timer(manager->events, manager->timer_lev);
neu_event_del_timer(manager->events, manager->timer_timestamp);
header->type = NEU_REQ_NODE_UNINIT;
+1 -2
View File
@@ -42,8 +42,7 @@ typedef struct neu_manager {
neu_event_timer_t *timer_timestamp;
neu_event_timer_t *timer_lev;
int64_t timestamp_lev_manager;
int64_t timestamp_lev_manager;
} neu_manager_t;
int neu_manager_add_plugin(neu_manager_t *manager, const char *library);
+3
View File
@@ -0,0 +1,3 @@
import sys
sys.path.append("tests/ft")
+32
View File
@@ -0,0 +1,32 @@
import os
import sys
import neuron.api as api
from neuron.common import *
class TestLogin:
@description(given="name and password", when="login", then="login success with token")
def test_login_success(self):
response = api.login()
assert 200 == response.status_code
@description(given="invalid user", when="login", then="login failed")
def test_login_invalid_user(self):
response = api.login('invalid_user')
assert 401 == response.status_code
@description(given="invalid password", when="login", then="login failed")
def test_login_invalid_password(self):
response = api.login(password='invalid_password')
assert 401 == response.status_code
@description(given="user, old and new password", when="change password", then="change success")
def test_change_password(self):
response = api.change_password(new_password='invalid_password')
assert 200 == response.status_code
assert 0 == response.json()['error']
response = api.login(password='invalid_password')
assert 200 == response.status_code
View File
+10
View File
@@ -0,0 +1,10 @@
import requests
import neuron.config as config
def login(user='admin', password='0000'):
return requests.post(url=config.BASE_URL + '/api/v2/login', json={"name": user, "pass": password})
def change_password(new_password, user='admin', old_password='0000', jwt=config.default_jwt):
return requests.post(url=config.BASE_URL + '/api/v2/password', headers={"Authorization": jwt}, json={"name": user, "old_pass": old_password, "new_pass": new_password})
+40
View File
@@ -0,0 +1,40 @@
import time
import sys
from functools import wraps
import pytest
import neuron.process as process
class description(object):
def __init__(self, given, when, then):
self.given = given
self.when = when
self.then = then
def __call__(self, func):
@wraps(func)
def wrapper(*args, **kwargs):
info = "Given " + self.given + ", when " + \
self.when + ", then " + self.then + "."
print('\033[1;33;40m')
print("\n" + info)
print('\033[0m', end=' Result: ')
return func(*args, **kwargs)
return wrapper
@pytest.fixture(autouse=True, scope='class')
def class_setup_and_teardown():
process.remove_persistence()
p = process.start_neuron()
yield
process.stop_neuron(p)
@pytest.fixture(autouse=True, scope='function')
def case_time():
start = time.time()
yield
print(' Time cost: {:.3f}s'.format(time.time() - start), end='')
+2
View File
@@ -0,0 +1,2 @@
BASE_URL = "http://127.0.0.1:7000"
default_jwt = "Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJuZXVyb24iLCJib2R5RW5jb2RlIjowLCJleHAiOjE3MTc4MzUyNjIsImlhdCI6MTY4NjI5OTI2MiwiaXNzIjoibmV1cm9uIn0.tJ8Z12S5lzzyqvJedFr11w0FmQ8l9inFHuzcuA_3uKoNBJSZlQAkcWyDAO2XELyuZFtHPrk8pJFgEqTzwphtBAybVXbeHBRWED5XuHvYqznzwk1J2UCOuw_ehmHnLszZHRAcMoeLWIRIx0KM7BXvZAyFA2J1axJntxfRrurNMn6MbfnGGtza6hJfuQ6pG-h4cHhrBOogf8nw3f8RLfd16vbWobhEp8KBUrwsfn2Iv4hMXvZMekv_PXboLO74f7oMkEL6pdM9g6G6rDBTjTU8FssfeyJcAP7Xb9mS2G7GNW5B8twtPVLtpOQH9VNbLa4OQxdMb0WN86i9vSDiCOoN6A"
+23
View File
@@ -0,0 +1,23 @@
import os
import time
import pytest
import subprocess
def remove_persistence(dir='build/'):
os.system("rm -rf " + dir + "/persistence/sqlite.db")
os.system("mkdir -p " + dir + "/persistence")
def start_neuron(dir='build/'):
process = subprocess.Popen(
['./neuron'], stderr=subprocess.PIPE, cwd=dir)
time.sleep(1)
assert process.poll() is None
return process
def stop_neuron(process):
result = process.terminate()
stderr = process.stderr.read().decode()
assert stderr == '', "Neuron process has errors: " + stderr
+3
View File
@@ -0,0 +1,3 @@
[pytest]
python_files = test_*.py
python_functions = test_*
+4
View File
@@ -0,0 +1,4 @@
from distutils.core import setup
setup(name='neuronft', version="0.0.1",
description='ft module', author='neuron', py_modules=['neuron', 'neuron.api', 'neuron.common', 'neuron.config', 'neuron.process'])