mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2025-12-31 20:36:24 +00:00
feat: Add py-libp2p to rust-libp2p interoperability tests
This commit is contained in:
44
tests/interop/rust_libp2p/scripts/run_py_to_rust_test.ps1
Normal file
44
tests/interop/rust_libp2p/scripts/run_py_to_rust_test.ps1
Normal file
@ -0,0 +1,44 @@
|
||||
# scripts/run_py_to_rust_test.ps1
|
||||
# Test script for py-libp2p client connecting to rust-libp2p server
|
||||
|
||||
param(
|
||||
[int]$PingCount = 5,
|
||||
[int]$TimeoutSeconds = 30
|
||||
)
|
||||
|
||||
Write-Host "=== py-libp2p to rust-libp2p Interop Test ===" -ForegroundColor Cyan
|
||||
Write-Host "Starting rust-libp2p server..." -ForegroundColor Yellow
|
||||
|
||||
# Start rust server in background
|
||||
$rustProcess = Start-Process -FilePath "cargo" -ArgumentList "run" -WorkingDirectory "rust_node" -PassThru -WindowStyle Hidden
|
||||
|
||||
# Wait a moment for server to start
|
||||
Start-Sleep -Seconds 3
|
||||
|
||||
try {
|
||||
# Get the rust server's listening address from its output
|
||||
# For now, we'll assume it's listening on a predictable port
|
||||
# In a real scenario, you'd parse the server output to get the actual address
|
||||
|
||||
Write-Host "Waiting for rust server to start..." -ForegroundColor Yellow
|
||||
Start-Sleep -Seconds 5
|
||||
|
||||
# Try to find the server's peer ID and port from netstat or process output
|
||||
# For this test, we'll need to manually check the rust server output
|
||||
Write-Host "Please check the rust server output for its Peer ID and port" -ForegroundColor Red
|
||||
Write-Host "Then run the Python client manually with:" -ForegroundColor Yellow
|
||||
Write-Host "python py_node/ping.py client /ip4/127.0.0.1/tcp/<PORT>/p2p/<PEER_ID> --count $PingCount" -ForegroundColor Green
|
||||
|
||||
# Keep the server running
|
||||
Write-Host "Press any key to stop the test..." -ForegroundColor Cyan
|
||||
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
|
||||
|
||||
} finally {
|
||||
# Clean up
|
||||
Write-Host "Stopping rust server..." -ForegroundColor Yellow
|
||||
if ($rustProcess -and !$rustProcess.HasExited) {
|
||||
$rustProcess.Kill()
|
||||
$rustProcess.WaitForExit(5000)
|
||||
}
|
||||
Write-Host "Test completed." -ForegroundColor Green
|
||||
}
|
||||
78
tests/interop/rust_libp2p/scripts/run_rust_to_py_test.ps1
Normal file
78
tests/interop/rust_libp2p/scripts/run_rust_to_py_test.ps1
Normal file
@ -0,0 +1,78 @@
|
||||
# scripts/run_rust_to_py_test.ps1
|
||||
# Test script for rust-libp2p client connecting to py-libp2p server
|
||||
|
||||
param(
|
||||
[int]$Port = 8000,
|
||||
[int]$PingCount = 5,
|
||||
[int]$TimeoutSeconds = 30
|
||||
)
|
||||
|
||||
Write-Host "=== rust-libp2p to py-libp2p Interop Test ===" -ForegroundColor Cyan
|
||||
Write-Host "Starting py-libp2p server on port $Port..." -ForegroundColor Yellow
|
||||
|
||||
# Start Python server in background
|
||||
$pyProcess = Start-Process -FilePath "python" -ArgumentList "py_node/ping.py", "server", "--port", $Port -PassThru -RedirectStandardOutput "py_server_output.txt" -RedirectStandardError "py_server_error.txt"
|
||||
|
||||
# Wait for server to start
|
||||
Start-Sleep -Seconds 5
|
||||
|
||||
try {
|
||||
# Read the server output to get peer ID
|
||||
$maxWaitTime = 10
|
||||
$waited = 0
|
||||
$peerID = $null
|
||||
|
||||
while ($waited -lt $maxWaitTime -and !$peerID) {
|
||||
if (Test-Path "py_server_output.txt") {
|
||||
$output = Get-Content "py_server_output.txt" -Raw
|
||||
if ($output -match "Peer ID: ([\w\d]+)") {
|
||||
$peerID = $matches[1]
|
||||
break
|
||||
}
|
||||
}
|
||||
Start-Sleep -Seconds 1
|
||||
$waited++
|
||||
}
|
||||
|
||||
if (!$peerID) {
|
||||
Write-Host "Could not extract Peer ID from Python server output" -ForegroundColor Red
|
||||
Write-Host "Server output:" -ForegroundColor Yellow
|
||||
if (Test-Path "py_server_output.txt") {
|
||||
Get-Content "py_server_output.txt"
|
||||
}
|
||||
if (Test-Path "py_server_error.txt") {
|
||||
Write-Host "Server errors:" -ForegroundColor Red
|
||||
Get-Content "py_server_error.txt"
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
$multiaddr = "/ip4/127.0.0.1/tcp/$Port/p2p/$peerID"
|
||||
Write-Host "Python server started with Peer ID: $peerID" -ForegroundColor Green
|
||||
Write-Host "Full address: $multiaddr" -ForegroundColor Green
|
||||
|
||||
Write-Host "Starting rust client..." -ForegroundColor Yellow
|
||||
|
||||
# Run rust client
|
||||
$rustResult = Start-Process -FilePath "cargo" -ArgumentList "run", "--", $multiaddr -WorkingDirectory "rust_node" -Wait -PassThru -NoNewWindow
|
||||
|
||||
if ($rustResult.ExitCode -eq 0) {
|
||||
Write-Host "Rust client completed successfully!" -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host "Rust client failed with exit code: $($rustResult.ExitCode)" -ForegroundColor Red
|
||||
}
|
||||
|
||||
} finally {
|
||||
# Clean up
|
||||
Write-Host "Stopping Python server..." -ForegroundColor Yellow
|
||||
if ($pyProcess -and !$pyProcess.HasExited) {
|
||||
$pyProcess.Kill()
|
||||
$pyProcess.WaitForExit(5000)
|
||||
}
|
||||
|
||||
# Clean up output files
|
||||
if (Test-Path "py_server_output.txt") { Remove-Item "py_server_output.txt" }
|
||||
if (Test-Path "py_server_error.txt") { Remove-Item "py_server_error.txt" }
|
||||
|
||||
Write-Host "Test completed." -ForegroundColor Green
|
||||
}
|
||||
Reference in New Issue
Block a user