feat(mooncakestore): add mooncake_master CLI entry point and tests (#218)

* feat(cli): add mooncake_master CLI entry point and tests

* test: add CLI entry point tests to run_tests script
This commit is contained in:
JinYan Su 2025-04-08 17:41:03 +08:00 committed by GitHub
parent ed2f4d410a
commit 4c2b6655cf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 143 additions and 10 deletions

View File

@ -49,6 +49,11 @@ jobs:
cd mooncake-store/tests
MC_METADATA_SERVER=http://127.0.0.1:8090/metadata python3 test_distributed_object_store.py
shell: bash
- name: Stop mooncake master
run: pkill -f mooncake_master || true
shell: bash
- name: Build Python wheel
run: ./scripts/build_wheel.sh
shell: bash

View File

@ -0,0 +1,28 @@
#!/usr/bin/env python3
"""
Minimal CLI module for mooncake_master.
"""
import os
import sys
import subprocess
def main():
"""
Main entry point for the mooncake_master command.
Simply runs the mooncake_master binary with all arguments passed through.
"""
# Get the path to the mooncake_master binary
package_dir = os.path.dirname(os.path.abspath(__file__))
bin_path = os.path.join(package_dir, "mooncake_master")
# Make sure the binary is executable
os.chmod(bin_path, 0o755)
# Run the binary with all arguments passed through
return subprocess.call([bin_path] + sys.argv[1:])
if __name__ == "__main__":
sys.exit(main())

View File

@ -55,4 +55,9 @@ setup(
"License :: OSI Approved :: Apache Software License",
],
python_requires=python_version,
entry_points={
'console_scripts': [
'mooncake_master=mooncake.cli:main',
],
},
)

View File

@ -1,8 +0,0 @@
import os
from importlib.resources import files
from mooncake import *
import subprocess
bin_path = files("mooncake") / "mooncake_master"
print("bin path:", bin_path)
os.chmod(bin_path, 0o755)
result = subprocess.run([bin_path])

View File

@ -0,0 +1,87 @@
#!/usr/bin/env python3
"""
Test script to verify that the mooncake_master entry point works correctly.
"""
import os
import sys
import subprocess
import time
def test_entry_point_installed():
"""Test that the entry point is installed and can be executed."""
try:
# Check if mooncake_master is in PATH
result = subprocess.run(
["which", "mooncake_master"],
capture_output=True,
text=True
)
if result.returncode != 0:
print("❌ mooncake_master entry point not found in PATH")
return False
print(f"✅ mooncake_master entry point found at: {result.stdout.strip()}")
return True
except Exception as e:
print(f"❌ Error checking for entry point: {e}")
return False
def test_run_master():
"""Test running the master service through the entry point."""
try:
# Run mooncake_master with a non-default port to avoid conflicts
process = subprocess.Popen(
["mooncake_master", "--port=50052", "--max_threads=2","--enable_gc=false"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
# Give it a moment to start
time.sleep(2)
# Check if process is running
if process.poll() is None:
print("✅ mooncake_master process started successfully")
# Terminate the process
process.terminate()
process.wait(timeout=5)
print("✅ mooncake_master process terminated successfully")
return True
else:
stdout, stderr = process.communicate()
print(f"❌ mooncake_master process failed to start")
print(f"stdout: {stdout.decode()}")
print(f"stderr: {stderr.decode()}")
return False
except Exception as e:
print(f"❌ Error running mooncake_master: {e}")
return False
if __name__ == "__main__":
print("Testing mooncake_master entry point...")
# Run tests
entry_point_installed = test_entry_point_installed()
if entry_point_installed:
run_master_success = test_run_master()
else:
run_master_success = False
# Print summary
print("\nTest Summary:")
print(f"Entry point installed: {'' if entry_point_installed else ''}")
print(f"Run master successful: {'' if run_master_success else ''}")
# Exit with appropriate status code
if entry_point_installed and run_master_success:
print("\nAll tests passed! 🎉")
sys.exit(0)
else:
print("\nSome tests failed. 😢")
sys.exit(1)

View File

@ -16,12 +16,22 @@ MC_METADATA_SERVER=http://127.0.0.1:8090/metadata python transfer_engine_initiat
kill $TARGET_PID || true
echo "Running master tests..."
pkill -f mooncake_master || true
python master.py &
which mooncake_master 2>/dev/null | grep -q '/usr/local/bin/mooncake_master' && \
{ echo "ERROR: mooncake_master found in /usr/local/bin, not installed by python"; exit 1; } || \
echo "mooncake_master not found in /usr/local/bin, installed by python"
echo "mooncake_master found, running tests..."
mooncake_master &
MASTER_PID=$!
sleep 1
MC_METADATA_SERVER=http://127.0.0.1:8090/metadata python test_distributed_object_store.py
kill $MASTER_PID || true
echo "Running CLI entry point tests..."
python test_cli.py
echo "All tests completed successfully!"
cd ../..

View File

@ -28,6 +28,12 @@ echo "Running import structure test..."
cp -r mooncake-wheel/tests test_env/
cd test_env
python tests/test_import_structure.py
echo "Verifying mooncake_master entry point..."
# Check if the mooncake_master entry point is installed and executable
which mooncake_master || { echo "ERROR: mooncake_master entry point not found!"; exit 1; }
echo "Success: mooncake_master entry point found"
cd ..
echo "Installation test completed successfully!"