mirror of
https://github.com/haiwen/seafile-server.git
synced 2025-09-18 08:15:14 +00:00
Get gc id before index blocks (#718)
* Get gc id before index blocks * Add test gc online * Add test gc online * Adjust time of run gc --------- Co-authored-by: 杨赫然 <heran.yang@seafile.com>
This commit is contained in:
@@ -5,6 +5,8 @@ import time
|
||||
from subprocess import run
|
||||
from tests.config import USER, USER2
|
||||
from seaserv import seafile_api as api
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from requests_toolbelt import MultipartEncoder
|
||||
|
||||
file_name = 'file.txt'
|
||||
first_name = 'first.txt'
|
||||
@@ -30,6 +32,18 @@ def create_test_file():
|
||||
fp.write(third_content)
|
||||
fp.close()
|
||||
|
||||
large_file_name = 'large.txt'
|
||||
large_file_size = 2*1024*1024*1024
|
||||
large_file_path = os.getcwd() + '/' + large_file_name
|
||||
|
||||
def create_large_file():
|
||||
fp = open(large_file_path, 'wb')
|
||||
fp.write(os.urandom(large_file_size))
|
||||
fp.close()
|
||||
|
||||
def del_large_file():
|
||||
os.remove(large_file_path)
|
||||
|
||||
def del_local_files():
|
||||
os.remove(first_path)
|
||||
os.remove(second_path)
|
||||
@@ -131,3 +145,52 @@ def test_gc_partial_history(repo, rm_fs):
|
||||
run_gc(repo.id, '', '--check')
|
||||
|
||||
del_local_files()
|
||||
|
||||
def upload_file(url, m):
|
||||
start = 0
|
||||
end = large_file_size - 1
|
||||
total = large_file_size
|
||||
response = requests.post(url,
|
||||
data = m, headers = {'Content-Type': m.content_type,
|
||||
'Content-Range': f"bytes {start}-{end}/{total}",
|
||||
'Content-Disposition': 'attachment; filename="large.txt"'})
|
||||
return response.status_code, response.text
|
||||
|
||||
|
||||
@pytest.mark.parametrize('rm_fs', ['', '--rm-fs'])
|
||||
def test_gc_on_upload(repo, rm_fs):
|
||||
create_large_file()
|
||||
api.set_repo_valid_since (repo.id, 0)
|
||||
|
||||
obj_id = '{"parent_dir":"/"}'
|
||||
token = api.get_fileserver_access_token(repo.id, obj_id, 'upload', USER, False)
|
||||
upload_url_base = 'http://127.0.0.1:8082/upload-aj/'+ token
|
||||
m = MultipartEncoder(
|
||||
fields={
|
||||
'parent_dir': '/',
|
||||
'file': (large_file_name, open(large_file_path, 'rb'), 'application/octet-stream')
|
||||
})
|
||||
|
||||
|
||||
status_code = 200
|
||||
executor = ThreadPoolExecutor()
|
||||
future = executor.submit(upload_file, upload_url_base, m)
|
||||
|
||||
while True:
|
||||
offset = api.get_upload_tmp_file_offset(repo.id, "/" + large_file_name)
|
||||
if offset == large_file_size:
|
||||
break
|
||||
time.sleep (0.5)
|
||||
time.sleep (1)
|
||||
run_gc(repo.id, rm_fs, '')
|
||||
|
||||
while not future.done():
|
||||
time.sleep(0.5)
|
||||
|
||||
status_code = future.result()[0]
|
||||
assert status_code == 500
|
||||
|
||||
api.set_repo_valid_since (repo.id, 0)
|
||||
run_gc(repo.id, '', '--check')
|
||||
|
||||
del_large_file ()
|
||||
|
Reference in New Issue
Block a user