Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion concore.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private static void writeKillScript() {
script += " exit /b 0\r\n";
script += ")\r\n";
script += "for /f \"usebackq tokens=*\" %%p in (\"%~dp0" + regName + "\") do (\r\n";
script += " wmic process where \"ProcessId=%%p\" get CommandLine /value 2>nul | find /i \"concore\" >nul\r\n";
script += " powershell -NoProfile -Command \"(Get-CimInstance Win32_Process -Filter 'ProcessId=%%p').CommandLine\" 2>nul | findstr /i \"concore\" >nul\r\n";
script += " if not errorlevel 1 (\r\n";
script += " echo Killing concore process %%p\r\n";
script += " taskkill /F /PID %%p >nul 2>&1\r\n";
Expand Down
2 changes: 1 addition & 1 deletion concore.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def _write_kill_script():
script += " exit /b 0\r\n"
script += ")\r\n"
script += 'for /f "usebackq tokens=*" %%p in ("%~dp0' + reg_name + '") do (\r\n'
script += ' wmic process where "ProcessId=%%p" get CommandLine /value 2>nul | find /i "concore" >nul\r\n'
script += ' powershell -NoProfile -Command "(Get-CimInstance Win32_Process -Filter \'ProcessId=%%p\').CommandLine" 2>nul | findstr /i "concore" >nul\r\n'
script += " if not errorlevel 1 (\r\n"
script += " echo Killing concore process %%p\r\n"
script += " taskkill /F /PID %%p >nul 2>&1\r\n"
Expand Down
29 changes: 28 additions & 1 deletion tests/test_concore.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,10 +716,37 @@ def test_write_kill_script_generates_bat_file(self):
with open(_KILL_SCRIPT_FILE) as f:
content = f.read()
assert os.path.basename(_PID_REGISTRY_FILE) in content
assert "wmic" in content
assert "wmic" not in content
assert "Get-CimInstance" in content
assert "taskkill" in content
assert "concore" in content.lower()

@pytest.mark.skipif(sys.platform != "win32", reason="Windows only")
def test_kill_script_kills_concore_process(self):
import subprocess
from concore import _write_kill_script, _KILL_SCRIPT_FILE, _PID_REGISTRY_FILE

proc = subprocess.Popen(
[sys.executable, "-c", "import time; time.sleep(60)", "concore_node"]
)
try:
with open(_PID_REGISTRY_FILE, "w") as f:
f.write(str(proc.pid) + "\n")
_write_kill_script()
result = subprocess.run(
["cmd", "/c", _KILL_SCRIPT_FILE],
capture_output=True,
text=True,
timeout=60,
)
assert "Killing concore process " + str(proc.pid) in result.stdout
proc.wait(timeout=10)
assert not os.path.exists(_PID_REGISTRY_FILE)
assert not os.path.exists(_KILL_SCRIPT_FILE)
finally:
if proc.poll() is None:
proc.kill()

def test_multi_node_registration(self):
from concore import _register_pid, _PID_REGISTRY_FILE

Expand Down
Loading