Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: integration test_termination #704

Merged
merged 1 commit into from
Dec 6, 2023
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
16 changes: 15 additions & 1 deletion tests/integration/basetest.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,17 +153,31 @@ def assert_shutdown(self, exitcode=0):
assert self.get_container_exitcode() == exitcode
self.assert_string_in_recent_logs("Mendix Runtime is shutting down")
self.assert_string_in_recent_logs("Mendix Runtime is now shut down")

# sometimes the java process is already killed but for some reason, it's in <defunct> state
if self.is_process_defunct("java"):
print("\n For some reason, java process is in <defunct> state.")
self.run_on_container("killall -9 java") # force kill the process to continue
exitcode = 1

if exitcode == 0:
# sys.exit(1) only occurs before the await termination loop
self.assert_string_in_recent_logs("Runtime process has been terminated")
self.assert_string_in_recent_logs("Terminating process group")
self.assert_string_in_recent_logs("Terminating process group")

def query_mxadmin(self, *args, **kwargs):
return self._runner.mxadmin(*args, **kwargs)

def run_on_container(self, *args, **kwargs):
return self._runner.run_on_container(*args, **kwargs)

def is_process_defunct(self, process):
try:
defunct_process = self.run_on_container("ps aux | grep {} | grep defunct".format(process))
return defunct_process is not None
except RuntimeError:
return False


class BaseTestWithPostgreSQL(BaseTest):
def _init_cflocal_runner(self, *args, **kwargs):
Expand Down
11 changes: 9 additions & 2 deletions tests/integration/test_termination.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,23 @@ def test_termination_broken_application(self):
self.assert_shutdown(1)

# Tests if killing Java terminates the container
# METRICS_INTERVAL:60 to make sure not to flood logs and, we get the desired string
def test_termination_java_crash_triggers_unhealthy(self):
self.stage_container(
"sample-6.2.0.mda",
env_vars={
"METRICS_INTERVAL": "10",
"METRICS_INTERVAL": "60",
},
)
self.start_container()
self.assert_app_running()
self.run_on_container("killall java")
assert self.await_container_health("unhealthy", 60)
self.assert_string_in_recent_logs("Runtime process has been terminated")

if self.is_process_defunct("java"):
print("\n For some reason, java process is in <defunct> state.")
self.run_on_container("killall -9 java") # force kill the process to continue
else:
self.assert_string_in_recent_logs("Runtime process has been terminated")

assert self.get_container_exitcode() == 0 # A manual kill command is all fine
Loading