mirror of
https://github.com/tiennm99/serena.git
synced 2026-10-19 06:15:34 +00:00
Fix Windows CI: Replace Unix-only SIGALRM with cross-platform timeout
signal.SIGALRM is not available on Windows, causing test_completion to fail. Replace with threading.Thread approach (daemon=True) that works on all platforms.
This commit is contained in:
1 file changed
+22
-21
@@ -1,5 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
import tempfile
|
import tempfile
|
||||||
|
import threading
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from unittest.mock import Mock, patch
|
from unittest.mock import Mock, patch
|
||||||
|
|
||||||
@@ -163,29 +164,29 @@ class TestFSharpLanguageServer:
|
|||||||
"""Test code completion functionality."""
|
"""Test code completion functionality."""
|
||||||
file_path = os.path.join("Program.fs")
|
file_path = os.path.join("Program.fs")
|
||||||
|
|
||||||
# F# completion can be slow, so we'll test this with a timeout approach
|
# Use threading for cross-platform timeout (signal.SIGALRM is Unix-only)
|
||||||
# In real usage, completions work but may take time for large projects
|
result = [None]
|
||||||
try:
|
exception = [None]
|
||||||
import signal
|
|
||||||
|
|
||||||
def timeout_handler(signum, frame):
|
|
||||||
raise TimeoutError("Completion request timed out")
|
|
||||||
|
|
||||||
signal.signal(signal.SIGALRM, timeout_handler)
|
|
||||||
signal.alarm(5) # 5 second timeout
|
|
||||||
|
|
||||||
|
def run_completion():
|
||||||
try:
|
try:
|
||||||
completions = language_server.request_completions(file_path, 15, 10)
|
result[0] = language_server.request_completions(file_path, 15, 10)
|
||||||
signal.alarm(0) # Cancel alarm
|
except Exception as e:
|
||||||
assert isinstance(completions, list), "Completions should be a list"
|
exception[0] = e
|
||||||
except TimeoutError:
|
|
||||||
signal.alarm(0) # Cancel alarm
|
thread = threading.Thread(target=run_completion, daemon=True)
|
||||||
# Completion timed out, but this is acceptable for F# in some cases
|
thread.start()
|
||||||
# The important thing is that the language server doesn't crash
|
thread.join(timeout=5) # 5 second timeout
|
||||||
assert True, "Completion timed out but language server is stable"
|
|
||||||
except Exception as e:
|
if thread.is_alive():
|
||||||
# If we can't set up the timeout, just skip this test
|
# Completion timed out, but this is acceptable for F# in some cases
|
||||||
assert True, f"Completion test skipped due to: {e}"
|
# The important thing is that the language server doesn't crash
|
||||||
|
return
|
||||||
|
|
||||||
|
if exception[0]:
|
||||||
|
raise exception[0]
|
||||||
|
|
||||||
|
assert isinstance(result[0], list), "Completions should be a list"
|
||||||
|
|
||||||
@pytest.mark.parametrize("language_server", [Language.FSHARP], indirect=True)
|
@pytest.mark.parametrize("language_server", [Language.FSHARP], indirect=True)
|
||||||
def test_diagnostics(self, language_server: SolidLanguageServer) -> None:
|
def test_diagnostics(self, language_server: SolidLanguageServer) -> None:
|
||||||
|
|||||||
Reference in new issue
Block a user