Skip to content

Commit

Permalink
Fixes failing tests for the alternates/building-on-matlab-docker-image.
Browse files Browse the repository at this point in the history
  • Loading branch information
epaganon authored and Prabhakar Kumar committed Sep 11, 2024
1 parent 55e1676 commit 3c9f91f
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 24 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/build-test-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,4 @@ jobs:
UPPERCASE_RELEASE=${LOWERCASE_RELEASE^}
docker tag ${{ env.IMAGE_BASE_NAME }}:${MATLAB_RELEASE} ${{ env.IMAGE_BASE_NAME }}:${LOWERCASE_RELEASE}
docker tag ${{ env.IMAGE_BASE_NAME }}:${MATLAB_RELEASE} ${{ env.IMAGE_BASE_NAME }}:${UPPERCASE_RELEASE}
docker push ${{ env.IMAGE_BASE_NAME }}:${LOWERCASE_RELEASE}
docker push ${{ env.IMAGE_BASE_NAME }}:${UPPERCASE_RELEASE}
docker push --all-tags ${{ env.IMAGE_BASE_NAME }}
3 changes: 1 addition & 2 deletions .github/workflows/non-interactive-build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,4 @@ jobs:
UPPERCASE_RELEASE=${LOWERCASE_RELEASE^}
docker tag ${{ env.IMAGE_BASE_NAME }}:${MATLAB_RELEASE} ${{ env.IMAGE_BASE_NAME }}:${LOWERCASE_RELEASE}
docker tag ${{ env.IMAGE_BASE_NAME }}:${MATLAB_RELEASE} ${{ env.IMAGE_BASE_NAME }}:${UPPERCASE_RELEASE}
docker push ${{ env.IMAGE_BASE_NAME }}:${LOWERCASE_RELEASE}
docker push ${{ env.IMAGE_BASE_NAME }}:${UPPERCASE_RELEASE}
docker push --all-tags ${{ env.IMAGE_BASE_NAME }}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from utils import helpers
import docker
import pexpect
import testinfra
import unittest

Expand Down Expand Up @@ -44,13 +45,15 @@ def test_no_entry_option(self):
expected_login_msg = (
"Please enter your MathWorks Account email address and press Enter:"
)
self.container = self.client.containers.run(
self.container = self.client.containers.create(
image=self.image_name,
detach=True,
stdin_open=True,
tty=True,
)
helpers.wait_for_msg_in_log(self.container, expected_login_msg)
self.assertIn(expected_login_msg, self.container.logs(tail=1).decode())
self.child = pexpect.spawn(f"docker start -i {self.container.id}")
self.child.expect(expected_login_msg)
output = self.child.after.decode().strip()
self.assertIn(expected_login_msg.lower(), output.lower())

def test_shell_option(self):
"""Test that if the '-shell' option is specified, then a '/bin/bash' process is started"""
Expand Down Expand Up @@ -142,20 +145,6 @@ def test_batch_option(self):

self.assertGreater(len(host.process.filter(user="matlab", comm="MATLAB")), 0)

def test_custom_option(self):
"""Test that if a custom option is specified, the custom command is run in bash."""
custom_option = "pwd"
expected_output = "/home/matlab"

self.container = self.client.containers.run(
image=self.image_name,
detach=True,
command=custom_option,
)
self.container.wait()

self.assertEqual(self.container.logs().decode().strip(), expected_output)


################################################################################

Expand Down
1 change: 1 addition & 0 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

docker
markdown-it-py
pexpect
pytest-testinfra
7 changes: 5 additions & 2 deletions tests/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,15 @@ def wait_for_msg_in_log(container, msg, timeout=30):
"""Wait until the expected log message is printed to stdout"""

def msg_is_logged():
return msg in container.logs().decode()
return msg.lower() in container.logs().decode().lower()

try:
wait_for(msg_is_logged, timeout)
except TimeoutError:
raise RuntimeError(f"The message {msg} was not printed to stdout.")
output = container.logs().decode()
raise RuntimeError(
f"The message\n\n\t'{msg}'\n\nwas not printed to stdout:\n\n{output}"
)


def wait_for_container_status(client, id, status, timeout=30):
Expand Down

0 comments on commit 3c9f91f

Please sign in to comment.