Skip to content

Commit

Permalink
Fix CI for linux runner (#6)
Browse files Browse the repository at this point in the history
* combine actions workflows into one

* temp disable long tests

* hopefully fix actions trigger for pytest

* temp disable windows as an actions target os

* disable all but one tests

* update stop logic

* pylint

* definitely kill server in tests

* re-enable some more tests

* kick bot before exit to remove errors in log

* reenable all tests

* fix formatting
  • Loading branch information
Ableytner authored Oct 7, 2024
1 parent 2f75cfc commit 571df64
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/define-pylint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- self-hosted
strategy:
matrix:
os: [Linux, Windows]
os: [Linux]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ inputs.python-version }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/define-pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- self-hosted
strategy:
matrix:
os: [Linux, Windows]
os: [Linux]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ inputs.python-version }}
Expand Down
13 changes: 0 additions & 13 deletions .github/workflows/run-pylint.yml

This file was deleted.

17 changes: 0 additions & 17 deletions .github/workflows/run-pytest.yml

This file was deleted.

31 changes: 31 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Run Tests

on:
push:
branches: [main]
pull_request:
workflow_dispatch:

jobs:
pylint:
strategy:
matrix:
python-version: ["3.8", "3.12"]
uses: ./.github/workflows/define-pylint.yml
with:
python-version: ${{ matrix.python-version }}
secrets: inherit

pytest:
strategy:
matrix:
python-version: ["3.8", "3.12"]
needs: pylint
if: |
(github.event_name == 'push' && github.ref_name == 'main') ||
(github.event_name == 'pull_request' && github.base_ref == 'main') ||
(github.event_name == 'workflow_dispatch')
uses: ./.github/workflows/define-pytest.yml
with:
python-version: ${{ matrix.python-version }}
secrets: inherit
28 changes: 20 additions & 8 deletions mcserverwrapper/src/server/base_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def start(self, blocking=True):
self._wait_for_startup()

def stop(self):
"""Stop the running server gracefully, and kills it if it doesn't stop within 20 seconds"""
"""Stop the running server gracefully"""

# server hasn't yet started, so it doesn't need to be stopped
if self._child is None:
Expand All @@ -61,13 +61,18 @@ def stop(self):
self.execute_command("/stop")

def kill(self):
"""Kill the server process, but DATA MAY BE LOST"""
"""Kill the server process, but UNSAVED DATA WILL BE LOST AND SAVES POSSIBLY CORRUPTED"""

logger.log("Killing server process")
if sys.platform == "win32":
self._child.kill(signal.CTRL_C_EVENT)
os.system(f"taskkill /pid {self._child.pid} /f")
else:
self._child.kill(signal.SIGTERM)
# pylint: disable-next=no-member
self._child.kill(signal.SIGKILL)

if self.get_child_status(30) is None:
logger.log("Server did not stop")
logger.log("We're running out of options, maybe try manually killing the server?")

def execute_command(self, command: str) -> None:
"""Send a given command to the server"""
Expand Down Expand Up @@ -150,12 +155,19 @@ def _wait_for_startup(self):
response = info_getter.ping_address_with_return("127.0.0.1", self._port)
sleep(1)

def _stopping(self):
def _ensure_stop(self):
logger.log("Stopping server")
status = self.get_child_status(20)
status = self.get_child_status(30)
if status is None:
logger.log("Server did not stop within 20 seconds")
self.kill()
logger.log("Server did not stop within 30 seconds")
if sys.platform == "win32":
self._child.kill(signal.CTRL_C_EVENT)
else:
self._child.kill(signal.SIGTERM)

status = self.get_child_status(60)
if status is None:
logger.log("Server did not stop within 90 seconds")

def _format_output(self, raw_text: bytes) -> str:
# remove line breaks
Expand Down
2 changes: 1 addition & 1 deletion mcserverwrapper/src/server/forge_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def execute_command(self, command: str):
super().execute_command(command)

if command == "/stop":
self._stopping()
self._ensure_stop()

@classmethod
def _check_jar(cls, jar_file: str) -> McVersion | None:
Expand Down
2 changes: 1 addition & 1 deletion mcserverwrapper/src/server/paper_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def execute_command(self, command: str):
super().execute_command(command)

if command == "stop":
self._stopping()
self._ensure_stop()

@staticmethod
def _check_jar(jar_file: str) -> McVersion | None:
Expand Down
2 changes: 1 addition & 1 deletion mcserverwrapper/src/server/vanilla_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def execute_command(self, command: str):
super().execute_command(command)

if command == "/stop":
self._stopping()
self._ensure_stop()

@classmethod
def _check_jar(cls, jar_file: str) -> McVersion | None:
Expand Down
3 changes: 2 additions & 1 deletion mcserverwrapper/test/helpers/forge_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ def run_forge_test(jarfile, offline_mode=False):
while "Hello World" not in line:
line = wrapper.output_queue.get(timeout=10)

wrapper.stop()
wrapper.send_command("/kick Developer", wait_time=1)
wrapper.server.kill()

assert not wrapper.server_running()
# assert that the server process really stopped
Expand Down
3 changes: 2 additions & 1 deletion mcserverwrapper/test/helpers/vanilla_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ def run_vanilla_test(jarfile, offline_mode=False):
while "I spawned" not in line:
line = wrapper.output_queue.get(timeout=5)

wrapper.stop()
wrapper.send_command("/kick Developer", wait_time=1)
wrapper.server.kill()

assert not wrapper.server_running()
# assert that the server process really stopped
Expand Down
9 changes: 6 additions & 3 deletions mcserverwrapper/test/integration_tests/test_vanilla.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import pytest

from mcserverwrapper import Wrapper
from mcserverwrapper.src import error
from ..helpers.common_helper import assert_port_is_free, download_file, connect_mineflayer, setup_workspace
from ..helpers.vanilla_helper import run_vanilla_test, run_vanilla_test_url
from ..testable_thread import TestableThread
Expand Down Expand Up @@ -111,18 +112,20 @@ def test_mineflayer(newest_server_jar):
while "I spawned" not in line:
line = wrapper.output_queue.get(timeout=5)

wrapper.stop()
wrapper.send_command("/kick Developer", wait_time=1)
wrapper.server.kill()

# assert that the server process really stopped
assert wrapper.server.get_child_status(0.1) is not None

def _test_invalid_start_params(newest_server_jar):
def test_invalid_start_params(newest_server_jar):
"""Test a server with an invalid startup command"""

start_cmd = f"java -Xmx2G -jar {newest_server_jar}nogui"

wrapper = Wrapper(os.path.join(os.getcwd(), "testdir", newest_server_jar),
server_start_command=start_cmd,
print_output=False)
with pytest.raises(KeyboardInterrupt):

with pytest.raises(error.ServerExitedError):
wrapper.startup()

0 comments on commit 571df64

Please sign in to comment.