Skip to content

Commit

Permalink
Extract sync test utils into dedicated module
Browse files Browse the repository at this point in the history
  • Loading branch information
wojciechos committed Nov 1, 2024
1 parent 87da2e6 commit 1474279
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 37 deletions.
22 changes: 4 additions & 18 deletions e2e/tests/sync/juno_from_juno.star
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
participants = import_module("../../clients/participants.star")
sync_utils = import_module("./sync_test_utils.star")

# Test configuration
SYNC_TIMEOUT_SECONDS = 1200
SYNC_TIMEOUT_SECONDS = 1800
TARGET_BLOCK_NUMBER = 1000

def run(plan):
Expand All @@ -24,20 +25,5 @@ def run(plan):
"network": "sepolia",
})

tester_image = plan.add_service(
"sync-tester",
config=ServiceConfig(
image=ImageBuildSpec(
image_name="sync-test",
build_context_dir="./../../tester",
),
)
)

# Run the tester
plan.print("Starting the sync tester...")
plan.exec(tester_image.name, ExecRecipe(
["node", "index.mjs", "http://" + peer_node.ip_address + ":6061", str(SYNC_TIMEOUT_SECONDS), str(TARGET_BLOCK_NUMBER)]
))

plan.print("Juno to Juno sync test completed")
sync_utils.run_sync_test(plan, feeder_node, peer_node, SYNC_TIMEOUT_SECONDS, TARGET_BLOCK_NUMBER)
plan.print("Juno to Juno sync test completed")
24 changes: 5 additions & 19 deletions e2e/tests/sync/juno_from_pathfinder.star
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
participants = import_module("../../clients/participants.star")
sync_utils = import_module("./sync_test_utils.star")

# Test configuration
SYNC_TIMEOUT_SECONDS = 1200
SYNC_TIMEOUT_SECONDS = 1800
TARGET_BLOCK_NUMBER = 1000

def run(plan):
# Run the Pathfinder feeder node
# Run the Pathfinder as feeder node
feeder_node = participants.run_participant(plan, "pathfinder-feeder", {
"type": "pathfinder",
"is_feeder": True,
Expand All @@ -22,20 +23,5 @@ def run(plan):
"network": "sepolia",
})

tester_image = plan.add_service(
"sync-tester",
config=ServiceConfig(
image=ImageBuildSpec(
image_name="sync-test",
build_context_dir="./../../tester",
),
)
)

# Run the tester
plan.print("Starting the sync tester...")
plan.exec(tester_image.name, ExecRecipe(
["node", "index.mjs", "http://" + peer_node.ip_address + ":6061", str(SYNC_TIMEOUT_SECONDS), str(TARGET_BLOCK_NUMBER)]
))

plan.print("Juno from Pathfinder sync test completed")
sync_utils.run_sync_test(plan, feeder_node, peer_node, SYNC_TIMEOUT_SECONDS, TARGET_BLOCK_NUMBER)
plan.print("Juno from Pathfinder sync test completed")
43 changes: 43 additions & 0 deletions e2e/tests/sync/sync_test_utils.star
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
def execute_sync_test(plan, peer_node, sync_timeout_seconds, target_block_number):
"""
Executes the sync test against a peer node:
1. Creates a tester service
2. Runs the sync test
3. Returns the test results
"""
# Create and run tester service
tester_service = plan.add_service(
"sync-tester",
config=ServiceConfig(
image=ImageBuildSpec(
image_name="sync-test",
build_context_dir="./../../tester",
),
)
)

plan.print("Starting the sync tester...")
plan.exec(tester_service.name, ExecRecipe(
["node", "index.mjs", "http://" + peer_node.ip_address + ":6061", str(sync_timeout_seconds), str(target_block_number)]
))

def cleanup_services(plan):
"""
Cleans up all services after the test is complete
"""
services = plan.get_services(description="Fetching running services")
for service in services:
plan.print("Found service: " + service.name + " at " + service.ip_address)
plan.remove_service(
name=service.name,
description="Removing service " + service.name
)

def run_sync_test(plan, feeder_node, peer_node, sync_timeout_seconds, target_block_number):
"""
Orchestrates the complete sync test process:
1. Executes the sync test
2. Cleans up all services
"""
execute_sync_test(plan, peer_node, sync_timeout_seconds, target_block_number)
cleanup_services(plan)

0 comments on commit 1474279

Please sign in to comment.