Skip to content

Commit

Permalink
Add test gc online
Browse files Browse the repository at this point in the history
  • Loading branch information
杨赫然 committed Nov 21, 2024
1 parent c14b84a commit 87b0ce5
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 4 deletions.
5 changes: 1 addition & 4 deletions ci/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,7 @@ def main():
args = parse_args()
if on_github_actions() and not args.test_only:
fetch_and_build()
if on_github_actions():
dbs = ('sqlite3', 'mysql')
else:
dbs = ('sqlite3',)
dbs = ('mysql',)
for db in dbs:
start_and_test_with_db(db)

Expand Down
60 changes: 60 additions & 0 deletions tests/test_gc/test_gc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
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'
Expand All @@ -30,6 +32,18 @@ def create_test_file():
fp.write(third_content)
fp.close()

large_file_name = 'large.txt'
large_file_size = 400*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)
Expand Down Expand Up @@ -131,3 +145,49 @@ def test_gc_partial_history(repo, rm_fs):
run_gc(repo.id, '', '--check')

del_local_files()

def upload_file(url, m):
response = requests.post(url,
data = m, headers = {'Content-Type': m.content_type,
'Content-Range': 'bytes 0-419430399/419430400',
'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 (0.5)
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 ()

0 comments on commit 87b0ce5

Please sign in to comment.