Skip to content

Commit

Permalink
Merge pull request #704 from mendix/fix_test_termination
Browse files Browse the repository at this point in the history
fix: integration test_termination
  • Loading branch information
sailhenz authored Dec 6, 2023
2 parents d4a941e + bdf9683 commit b3b14f6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
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

0 comments on commit b3b14f6

Please sign in to comment.