Skip to content
This repository has been archived by the owner on Jan 3, 2023. It is now read-only.

Commit

Permalink
Add sync test case (#1839)
Browse files Browse the repository at this point in the history
  • Loading branch information
PHILO-HE authored Jun 29, 2018
1 parent 999c971 commit 737ca94
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 23 deletions.
2 changes: 1 addition & 1 deletion docs/rest-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Example:
```
Example:
```
GET http://<host>:<port>/smart/api/v1/rules/{ruleId}/detail
GET http://<host>:<port>/smart/api/v1/rules/{ruleId}/info
Code:200
Content-Type:application/json
```
Expand Down
92 changes: 70 additions & 22 deletions supports/integration-test/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,37 @@
from util import *


class TestSync(unittest.TestCase):
@timeout_decorator.timeout(seconds=200)
def verify(rid, num_cmds_gen):
while True:
time.sleep(1)
rule = get_rule(rid)
if rule['numCmdsGen'] >= num_cmds_gen:
break


@timeout_decorator.timeout(seconds=60)
class TestSync(unittest.TestCase):
def test_sync_rule(self):
file_paths = []
cids = []
# create a directory with random name
source_dir = TEST_DIR + random_string() + "/"
sync_dir = TEST_DIR + random_string() + "/"
# create random files in the above directory
for i in range(MAX_NUMBER):
file_path, cid = create_random_file_parallel(FILE_SIZE, source_dir)
file_path, cid = create_random_file_parallel(FILE_SIZE, sync_dir)
file_paths.append(file_path)
cids.append(cid)
wait_for_cmdlets(cids)

# wait for DB sync
time.sleep(5)
rule_str = "file : every 1s | path matches " + \
"\"" + source_dir + "*\" | sync -dest " + DEST_DIR
"\"" + sync_dir + "*\" | sync -dest " + DEST_DIR
rid = submit_rule(rule_str)
start_rule(rid)
# Status check
while True:
time.sleep(1)
rule = get_rule(rid)
if rule['numCmdsGen'] >= MAX_NUMBER:
break
num_cmds_gen = MAX_NUMBER
verify(rid, num_cmds_gen)
cids = get_cids_of_rule(rid)
failed = wait_for_cmdlets(cids)
self.assertTrue(len(failed) == 0)
Expand All @@ -40,28 +44,72 @@ def test_sync_rule(self):
time.sleep(5)
cids = []
num_delete = random.randrange(len(file_paths))
num_cmds_gen = num_cmds_gen + num_delete
for i in range(num_delete):
cids.append(submit_cmdlet("delete -file " + file_paths[i]))
wait_for_cmdlets(cids)
while True:
time.sleep(1)
rule = get_rule(rid)
if rule['numCmdsGen'] >= MAX_NUMBER + num_delete:
break
verify(rid, num_cmds_gen)

# test create src file
cids = []
num_create = 10
num_cmds_gen = num_cmds_gen + num_create
for i in range(num_create):
file_path, cid = create_random_file_parallel(FILE_SIZE, source_dir)
file_path, cid = create_random_file_parallel(FILE_SIZE, sync_dir)
cids.append(cid)
wait_for_cmdlets(cids)
verify(rid, num_cmds_gen)
failed = wait_for_cmdlets(get_cids_of_rule(rid))
self.assertTrue(len(failed) == 0)

# test subdir case
cids = []
subdir = sync_dir + random_string() + "/"
num_subdir_files = 10
num_cmds_gen = num_cmds_gen + num_subdir_files
for i in range(num_subdir_files):
file_path, cid = create_random_file_parallel(FILE_SIZE, subdir)
file_paths.append(file_path)
cids.append(cid)
wait_for_cmdlets(cids)
verify(rid, num_cmds_gen)
failed = wait_for_cmdlets(get_cids_of_rule(rid))
self.assertTrue(len(failed) == 0)
# delete subdir
cid = submit_cmdlet("delete -file " + subdir)
wait_for_cmdlet(cid)
num_cmds_gen = num_cmds_gen + 1
verify(rid, num_cmds_gen)
failed = wait_for_cmdlets(get_cids_of_rule(rid))
self.assertTrue(len(failed) == 0)

# test rename case
cids = []
num_rename = 10
src_rename = []
num_cmds_gen = num_cmds_gen + num_rename
for i in range(num_rename):
file_path, cid = create_random_file_parallel(FILE_SIZE, sync_dir)
src_rename.append(file_path)
cids.append(cid)
wait_for_cmdlets(cids)
while True:
time.sleep(1)
rule = get_rule(rid)
if rule['numCmdsGen'] >= MAX_NUMBER + num_delete + num_create:
break
# TODO: test delete file while syncing
# sync original files
verify(rid, num_cmds_gen)
failed = wait_for_cmdlets(get_cids_of_rule(rid))
self.assertTrue(len(failed) == 0)
cids = []
for i in range(num_rename):
cids.append(submit_cmdlet("rename -file " + src_rename[i] + " -dest " + sync_dir + random_string()))
wait_for_cmdlets(cids)
num_cmds_gen = num_cmds_gen + num_rename
# sync renamed file
verify(rid, num_cmds_gen)
failed = wait_for_cmdlets(get_cids_of_rule(rid))
self.assertTrue(len(failed) == 0)

# TODO: test rename from outside dir into sync dir
# TODO: rename from sync dir to outside dir
# TODO: rename the syncing file

time.sleep(5)
stop_rule(rid)
Expand Down

0 comments on commit 737ca94

Please sign in to comment.