summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorAndrei Zeliankou <zelenkov@nginx.com>2021-11-04 13:05:53 +0000
committerAndrei Zeliankou <zelenkov@nginx.com>2021-11-04 13:05:53 +0000
commitbc95fcc324dc55d07547ccb85389465e5db70d68 (patch)
treec8813727e8df1514cdf295afec696042867dfaff /test
parent2359c4056c38bfb10569ec03da895c8e6e9dfbd2 (diff)
downloadunit-bc95fcc324dc55d07547ccb85389465e5db70d68.tar.gz
unit-bc95fcc324dc55d07547ccb85389465e5db70d68.tar.bz2
Tests: added migration test for "share".
Diffstat (limited to 'test')
-rw-r--r--test/conftest.py11
-rw-r--r--test/test_static.py45
2 files changed, 52 insertions, 4 deletions
diff --git a/test/conftest.py b/test/conftest.py
index 36061f8c..689c857a 100644
--- a/test/conftest.py
+++ b/test/conftest.py
@@ -356,7 +356,7 @@ def run(request):
_check_alerts(log=log)
-def unit_run():
+def unit_run(state_dir=None):
global unit_instance
if not option.restart and 'unitd' in unit_instance:
@@ -374,7 +374,9 @@ def unit_run():
if oct(stat.S_IMODE(os.stat(build_dir).st_mode)) != '0o777':
public_dir(build_dir)
- os.mkdir(temp_dir + '/state')
+ state = temp_dir + '/state' if state_dir is None else state_dir
+ if not os.path.isdir(state):
+ os.mkdir(state)
unitd_args = [
unitd,
@@ -382,7 +384,7 @@ def unit_run():
'--modules',
build_dir,
'--state',
- temp_dir + '/state',
+ state,
'--pid',
temp_dir + '/unit.pid',
'--log',
@@ -414,7 +416,8 @@ def unit_run():
with open(temp_dir + '/unit.pid', 'r') as f:
unit_instance['pid'] = f.read().rstrip()
- _clear_conf(unit_instance['temp_dir'] + '/control.unit.sock')
+ if state_dir is None:
+ _clear_conf(unit_instance['temp_dir'] + '/control.unit.sock')
_fds_info['main']['fds'] = _count_fds(unit_instance['pid'])
diff --git a/test/test_static.py b/test/test_static.py
index 94f790da..80f4c610 100644
--- a/test/test_static.py
+++ b/test/test_static.py
@@ -1,7 +1,9 @@
import os
+import shutil
import socket
import pytest
+from conftest import unit_run, unit_stop
from unit.applications.proto import TestApplicationProto
from unit.option import option
from unit.utils import waitforfiles
@@ -40,6 +42,49 @@ class TestStatic(TestApplicationProto):
}
)
+ def test_static_migration(self, skip_fds_check, temp_dir):
+ skip_fds_check(True, True, True)
+
+ def set_conf_version(path, version):
+ with open(path, 'w+') as f:
+ f.write(str(version))
+
+ with open(temp_dir + '/state/version', 'r') as f:
+ assert int(f.read().rstrip()) > 12500, 'current version'
+
+ assert 'success' in self.conf(
+ {"share": temp_dir + "/assets"}, 'routes/0/action'
+ ), 'configure migration 12500'
+
+ shutil.copytree(temp_dir + '/state', temp_dir + '/state_copy_12500')
+ set_conf_version(temp_dir + '/state_copy_12500/version', 12500)
+
+ assert 'success' in self.conf(
+ {"share": temp_dir + "/assets$uri"}, 'routes/0/action'
+ ), 'configure migration 12600'
+ shutil.copytree(temp_dir + '/state', temp_dir + '/state_copy_12600')
+ set_conf_version(temp_dir + '/state_copy_12600/version', 12600)
+
+ assert 'success' in self.conf(
+ {"share": temp_dir + "/assets"}, 'routes/0/action'
+ ), 'configure migration no version'
+ shutil.copytree(
+ temp_dir + '/state', temp_dir + '/state_copy_no_version'
+ )
+ os.remove(temp_dir + '/state_copy_no_version/version')
+
+ unit_stop()
+ unit_run(temp_dir + '/state_copy_12500')
+ assert self.get(url='/')['body'] == '0123456789', 'before 1.26.0'
+
+ unit_stop()
+ unit_run(temp_dir + '/state_copy_12600')
+ assert self.get(url='/')['body'] == '0123456789', 'after 1.26.0'
+
+ unit_stop()
+ unit_run(temp_dir + '/state_copy_no_version')
+ assert self.get(url='/')['body'] == '0123456789', 'before 1.26.0 2'
+
def test_static_index(self):
assert self.get(url='/index.html')['body'] == '0123456789', 'index'
assert self.get(url='/')['body'] == '0123456789', 'index 2'