Skip to content

Commit

Permalink
refactor sync relevant python tests (#301)
Browse files Browse the repository at this point in the history
  • Loading branch information
boqiu authored Dec 19, 2024
1 parent 8790fe1 commit 6412039
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 125 deletions.
1 change: 1 addition & 0 deletions tests/config/node_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from web3 import Web3

ZGS_CONFIG = {
"network_enr_address": "127.0.0.1",
"log_config_file": "log_config",
"confirmation_block_count": 1,
"discv5_disable_ip_limit": True,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@
from test_framework.test_framework import TestFramework
from utility.utils import wait_until

class AutoRandomSyncV2Test(TestFramework):
class AutoSyncHistoricalTest(TestFramework):
def setup_params(self):
self.num_nodes = 4

# Enable random auto sync v2
# Enable auto sync
for i in range(self.num_nodes):
self.zgs_node_configs[i] = {
"sync": {
"auto_sync_enabled": True,
"max_sequential_workers": 0,
"max_random_workers": 3,
"auto_sync_enabled": True
}
}

Expand Down Expand Up @@ -41,4 +39,4 @@ def run_test(self):
wait_until(lambda: self.nodes[self.num_nodes - 1].zgs_get_file_info(data_root_2)["finalized"])

if __name__ == "__main__":
AutoRandomSyncV2Test().main()
AutoSyncHistoricalTest().main()
32 changes: 0 additions & 32 deletions tests/sync_auto_random_test.py

This file was deleted.

32 changes: 0 additions & 32 deletions tests/sync_auto_sequential_test_ignore.py

This file was deleted.

4 changes: 1 addition & 3 deletions tests/sync_auto_test_ignore.py → tests/sync_auto_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ def setup_params(self):
for i in range(self.num_nodes):
self.zgs_node_configs[i] = {
"sync": {
"auto_sync_enabled": True,
"max_sequential_workers": 3,
"max_random_workers": 3,
"auto_sync_enabled": True
}
}

Expand Down
62 changes: 10 additions & 52 deletions tests/sync_test.py → tests/sync_chunks_test.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
#!/usr/bin/env python3

import random
import time

from test_framework.test_framework import TestFramework
from utility.submission import data_to_segments
from utility.utils import (
assert_equal,
wait_until,
)
from utility.utils import assert_equal, wait_until

class SyncChunksTest(TestFramework):
"""
By default, auto_sync_enabled and sync_file_on_announcement_enabled are both false,
and chunks sync should be triggered by rpc.
"""

class SyncTest(TestFramework):
def setup_params(self):
self.num_nodes = 2

Expand All @@ -21,49 +22,6 @@ def setup_params(self):
}

def run_test(self):
# By default, auto_sync_enabled and sync_file_on_announcement_enabled are both false,
# and file or chunks sync should be triggered by rpc.
self.__test_sync_file_by_rpc()
self.__test_sync_chunks_by_rpc()

def __test_sync_file_by_rpc(self):
self.log.info("Begin to test file sync by rpc")

client1 = self.nodes[0]
client2 = self.nodes[1]

# stop client2, preventing it from receiving AnnounceFile
client2.shutdown()

data_root = self.__upload_file__(0, 256 * 1024)

# restart client2
client2.start()
client2.wait_for_rpc_connection()

# File should not be auto sync on node 2 and there is no cached file locations
wait_until(lambda: client2.zgs_get_file_info(data_root) is not None)
time.sleep(3)
assert_equal(client2.zgs_get_file_info(data_root)["finalized"], False)
# file sync use ASK_FILE & ANSWER FILE protocol, and do not cache file announcement anymore.
# assert(client2.admin_get_file_location(0) is None)

# Trigger file sync by rpc
assert(client2.admin_start_sync_file(0) is None)
wait_until(lambda: client2.sync_status_is_completed_or_unknown(0))
wait_until(lambda: client2.zgs_get_file_info(data_root)["finalized"])
# file sync use ASK_FILE & ANSWER FILE protocol, and do not cache file announcement anymore.
# assert(client2.admin_get_file_location(0) is not None)

# Validate data
assert_equal(
client2.zgs_download_segment(data_root, 0, 1024),
client1.zgs_download_segment(data_root, 0, 1024),
)

def __test_sync_chunks_by_rpc(self):
self.log.info("Begin to test chunks sync by rpc")

client1 = self.nodes[0]
client2 = self.nodes[1]

Expand Down Expand Up @@ -98,12 +56,12 @@ def __test_sync_chunks_by_rpc(self):
self.nodes[0].wait_for_rpc_connection()

# Trigger chunks sync by rpc
assert(client2.admin_start_sync_chunks(1, 1024, 2048) is None)
wait_until(lambda: client2.sync_status_is_completed_or_unknown(1))
assert(client2.admin_start_sync_chunks(0, 1024, 2048) is None)
wait_until(lambda: client2.sync_status_is_completed_or_unknown(0))
wait_until(lambda: client2.zgs_download_segment_decoded(data_root, 1024, 2048) is not None)

# Validate data
assert_equal(client2.zgs_download_segment_decoded(data_root, 1024, 2048), chunk_data[1024*256:2048*256])

if __name__ == "__main__":
SyncTest().main()
SyncChunksTest().main()
51 changes: 51 additions & 0 deletions tests/sync_file_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env python3

import time

from test_framework.test_framework import TestFramework
from utility.utils import assert_equal, wait_until

class SyncFileTest(TestFramework):
"""
By default, auto_sync_enabled and sync_file_on_announcement_enabled are both false,
and file sync should be triggered by rpc.
"""

def setup_params(self):
self.num_nodes = 2

def run_test(self):
client1 = self.nodes[0]
client2 = self.nodes[1]

# stop client2, preventing it from receiving AnnounceFile
client2.shutdown()

data_root = self.__upload_file__(0, 256 * 1024)

# restart client2
client2.start()
client2.wait_for_rpc_connection()

# File should not be auto sync on node 2 and there is no cached file locations
wait_until(lambda: client2.zgs_get_file_info(data_root) is not None)
time.sleep(3)
assert_equal(client2.zgs_get_file_info(data_root)["finalized"], False)
# file sync use ASK_FILE & ANSWER FILE protocol, and do not cache file announcement anymore.
# assert(client2.admin_get_file_location(0) is None)

# Trigger file sync by rpc
assert(client2.admin_start_sync_file(0) is None)
wait_until(lambda: client2.sync_status_is_completed_or_unknown(0))
wait_until(lambda: client2.zgs_get_file_info(data_root)["finalized"])
# file sync use ASK_FILE & ANSWER FILE protocol, and do not cache file announcement anymore.
# assert(client2.admin_get_file_location(0) is not None)

# Validate data
assert_equal(
client2.zgs_download_segment(data_root, 0, 1024),
client1.zgs_download_segment(data_root, 0, 1024),
)

if __name__ == "__main__":
SyncFileTest().main()

0 comments on commit 6412039

Please sign in to comment.