Some checks are pending
Rhai Tests / Run Rhai Tests (push) Waiting to run
- Add `zinit_client` package to the workspace, enabling its use in the SAL monorepo. This allows for better organization and dependency management. - Update `MONOREPO_CONVERSION_PLAN.md` to reflect the addition of `zinit_client` and its status. This ensures the conversion plan stays up-to-date. - Move `src/zinit_client/` directory to `zinit_client/` for better organization. This improves the overall structure of the project. - Update references to `zinit_client` to use the new path. This ensures the codebase correctly links to the `zinit_client` package.
201 lines
5.9 KiB
Plaintext
201 lines
5.9 KiB
Plaintext
// Signal management and kill functionality test script
|
|
// This script tests sending signals to services
|
|
|
|
// Configuration
|
|
let socket_paths = [
|
|
"/var/run/zinit.sock",
|
|
"/tmp/zinit.sock",
|
|
"/run/zinit.sock",
|
|
"./zinit.sock"
|
|
];
|
|
|
|
// Find available socket
|
|
let socket_path = "";
|
|
for path in socket_paths {
|
|
try {
|
|
let test_services = zinit_list(path);
|
|
socket_path = path;
|
|
print(`✓ Found working Zinit socket at: ${path}`);
|
|
break;
|
|
} catch(e) {
|
|
// Continue to next path
|
|
}
|
|
}
|
|
|
|
if socket_path == "" {
|
|
print("⚠ No working Zinit socket found. Skipping tests.");
|
|
return;
|
|
}
|
|
|
|
print("=== Signal Management Test ===");
|
|
|
|
let service_name = "rhai-signal-test";
|
|
let exec_command = "sleep 30"; // Long-running command for signal testing
|
|
let oneshot = false; // Not oneshot so it keeps running
|
|
|
|
// Clean up any existing service first
|
|
print("\n0. Cleaning up any existing test service...");
|
|
try {
|
|
zinit_stop(socket_path, service_name);
|
|
zinit_forget(socket_path, service_name);
|
|
zinit_delete_service(socket_path, service_name);
|
|
print("✓ Cleanup completed");
|
|
} catch(e) {
|
|
print(" (Cleanup errors are expected if service doesn't exist)");
|
|
}
|
|
|
|
// Test 1: Create long-running service for signal testing
|
|
print("\n1. Creating long-running service for signal testing...");
|
|
try {
|
|
let create_result = zinit_create_service(socket_path, service_name, exec_command, oneshot);
|
|
print(`✓ Long-running service created: ${create_result}`);
|
|
} catch(e) {
|
|
print(`✗ Service creation failed: ${e}`);
|
|
print("⚠ Signal tests will be skipped");
|
|
return;
|
|
}
|
|
|
|
// Test 2: Start the service
|
|
print("\n2. Starting the service...");
|
|
try {
|
|
let monitor_result = zinit_monitor(socket_path, service_name);
|
|
let start_result = zinit_start(socket_path, service_name);
|
|
print(`✓ Service started: ${start_result}`);
|
|
|
|
// Check if it's running
|
|
try {
|
|
let status = zinit_status(socket_path, service_name);
|
|
print(` Service state: ${status.state}`);
|
|
print(` Service PID: ${status.pid}`);
|
|
} catch(e) {
|
|
print(` Status check failed: ${e}`);
|
|
}
|
|
|
|
} catch(e) {
|
|
print(`⚠ Service start failed: ${e}`);
|
|
// Clean up and exit
|
|
try {
|
|
zinit_delete_service(socket_path, service_name);
|
|
} catch(cleanup_e) {
|
|
// Ignore cleanup errors
|
|
}
|
|
return;
|
|
}
|
|
|
|
// Test 3: Send TERM signal
|
|
print("\n3. Testing TERM signal...");
|
|
try {
|
|
let kill_result = zinit_kill(socket_path, service_name, "TERM");
|
|
print(`✓ TERM signal sent: ${kill_result}`);
|
|
|
|
// Check status after signal
|
|
try {
|
|
let status = zinit_status(socket_path, service_name);
|
|
print(` Service state after TERM: ${status.state}`);
|
|
print(` Service PID after TERM: ${status.pid}`);
|
|
} catch(e) {
|
|
print(` Status check after TERM failed: ${e}`);
|
|
}
|
|
|
|
} catch(e) {
|
|
print(`⚠ TERM signal failed: ${e}`);
|
|
}
|
|
|
|
// Test 4: Restart service for more signal testing
|
|
print("\n4. Restarting service for additional signal tests...");
|
|
try {
|
|
let restart_result = zinit_restart(socket_path, service_name);
|
|
print(`✓ Service restarted: ${restart_result}`);
|
|
|
|
// Check if it's running again
|
|
try {
|
|
let status = zinit_status(socket_path, service_name);
|
|
print(` Service state after restart: ${status.state}`);
|
|
print(` Service PID after restart: ${status.pid}`);
|
|
} catch(e) {
|
|
print(` Status check after restart failed: ${e}`);
|
|
}
|
|
|
|
} catch(e) {
|
|
print(`⚠ Service restart failed: ${e}`);
|
|
}
|
|
|
|
// Test 5: Send HUP signal
|
|
print("\n5. Testing HUP signal...");
|
|
try {
|
|
let kill_result = zinit_kill(socket_path, service_name, "HUP");
|
|
print(`✓ HUP signal sent: ${kill_result}`);
|
|
|
|
// Check status after signal
|
|
try {
|
|
let status = zinit_status(socket_path, service_name);
|
|
print(` Service state after HUP: ${status.state}`);
|
|
print(` Service PID after HUP: ${status.pid}`);
|
|
} catch(e) {
|
|
print(` Status check after HUP failed: ${e}`);
|
|
}
|
|
|
|
} catch(e) {
|
|
print(`⚠ HUP signal failed: ${e}`);
|
|
}
|
|
|
|
// Test 6: Send USR1 signal
|
|
print("\n6. Testing USR1 signal...");
|
|
try {
|
|
let kill_result = zinit_kill(socket_path, service_name, "USR1");
|
|
print(`✓ USR1 signal sent: ${kill_result}`);
|
|
|
|
// Check status after signal
|
|
try {
|
|
let status = zinit_status(socket_path, service_name);
|
|
print(` Service state after USR1: ${status.state}`);
|
|
print(` Service PID after USR1: ${status.pid}`);
|
|
} catch(e) {
|
|
print(` Status check after USR1 failed: ${e}`);
|
|
}
|
|
|
|
} catch(e) {
|
|
print(`⚠ USR1 signal failed: ${e}`);
|
|
}
|
|
|
|
// Test 7: Send KILL signal (forceful termination)
|
|
print("\n7. Testing KILL signal (forceful termination)...");
|
|
try {
|
|
let kill_result = zinit_kill(socket_path, service_name, "KILL");
|
|
print(`✓ KILL signal sent: ${kill_result}`);
|
|
|
|
// Check status after signal
|
|
try {
|
|
let status = zinit_status(socket_path, service_name);
|
|
print(` Service state after KILL: ${status.state}`);
|
|
print(` Service PID after KILL: ${status.pid}`);
|
|
} catch(e) {
|
|
print(` Status check after KILL failed: ${e}`);
|
|
}
|
|
|
|
} catch(e) {
|
|
print(`⚠ KILL signal failed: ${e}`);
|
|
}
|
|
|
|
// Test 8: Test invalid signal
|
|
print("\n8. Testing invalid signal handling...");
|
|
try {
|
|
let kill_result = zinit_kill(socket_path, service_name, "INVALID");
|
|
print(`⚠ Invalid signal unexpectedly succeeded: ${kill_result}`);
|
|
} catch(e) {
|
|
print(`✓ Invalid signal correctly rejected: ${e}`);
|
|
}
|
|
|
|
// Cleanup
|
|
print("\n9. Cleaning up test service...");
|
|
try {
|
|
zinit_stop(socket_path, service_name);
|
|
zinit_forget(socket_path, service_name);
|
|
let delete_result = zinit_delete_service(socket_path, service_name);
|
|
print(`✓ Test service cleaned up: ${delete_result}`);
|
|
} catch(e) {
|
|
print(`⚠ Cleanup failed: ${e}`);
|
|
}
|
|
|
|
print("\n=== Signal Management Test Complete ===");
|