From 4c2b6655cf3fe1d627027716a51bb227b4c8fd6a Mon Sep 17 00:00:00 2001 From: JinYan Su <751080330@qq.com> Date: Tue, 8 Apr 2025 17:41:03 +0800 Subject: [PATCH] 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 --- .github/workflows/ci.yml | 5 ++ mooncake-wheel/mooncake/cli.py | 28 ++++++++++ mooncake-wheel/setup.py | 5 ++ mooncake-wheel/tests/master.py | 8 --- mooncake-wheel/tests/test_cli.py | 87 ++++++++++++++++++++++++++++++++ scripts/run_tests.sh | 14 ++++- scripts/test_installation.sh | 6 +++ 7 files changed, 143 insertions(+), 10 deletions(-) create mode 100644 mooncake-wheel/mooncake/cli.py delete mode 100644 mooncake-wheel/tests/master.py create mode 100644 mooncake-wheel/tests/test_cli.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bd46d6e1..8543bdb9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/mooncake-wheel/mooncake/cli.py b/mooncake-wheel/mooncake/cli.py new file mode 100644 index 00000000..e252d5a3 --- /dev/null +++ b/mooncake-wheel/mooncake/cli.py @@ -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()) diff --git a/mooncake-wheel/setup.py b/mooncake-wheel/setup.py index 82da823f..3a68d180 100644 --- a/mooncake-wheel/setup.py +++ b/mooncake-wheel/setup.py @@ -55,4 +55,9 @@ setup( "License :: OSI Approved :: Apache Software License", ], python_requires=python_version, + entry_points={ + 'console_scripts': [ + 'mooncake_master=mooncake.cli:main', + ], + }, ) diff --git a/mooncake-wheel/tests/master.py b/mooncake-wheel/tests/master.py deleted file mode 100644 index 11758070..00000000 --- a/mooncake-wheel/tests/master.py +++ /dev/null @@ -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]) diff --git a/mooncake-wheel/tests/test_cli.py b/mooncake-wheel/tests/test_cli.py new file mode 100644 index 00000000..dd5cb55d --- /dev/null +++ b/mooncake-wheel/tests/test_cli.py @@ -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) diff --git a/scripts/run_tests.sh b/scripts/run_tests.sh index 27e27136..754acc01 100755 --- a/scripts/run_tests.sh +++ b/scripts/run_tests.sh @@ -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 ../.. diff --git a/scripts/test_installation.sh b/scripts/test_installation.sh index d850757e..dea37449 100755 --- a/scripts/test_installation.sh +++ b/scripts/test_installation.sh @@ -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!"