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

mosquitto.sh runs native mosquitto #148

Merged

Conversation

jpgrayson
Copy link
Contributor

I am posting this as a possible solution to the problem of how to run tests natively with a mosquitto service.

This changes scripts/mosquitto.sh to run a native mosquitto process instead of running mosquitto as a containerized service. This specifically allows mosquitto to create/bind a unix socket path that is available to natively running tests.

This is the best way forward I am seeing to enable tests running natively on MacOS to support unix sockets. But I also appreciate that it's a very different paradigm.

The container based approach works on Linux; i.e. a container can share a unix socket to a Linux host. So mosquitto.sh could be written to use containers on Linux and only use a native mosquitto process on MacOS. Let me know if that alternative seems right.

@adam-fowler
Copy link
Collaborator

Is it not possible to have mosquitto bind a path internal to the docker container?

@jpgrayson
Copy link
Contributor Author

Mosquitto can bind a unix socket path internal to the docker container, but tests running in the host MacOS environment need access to that socket path.

Using a volume mount is the nominal way to share parts of the host and container filesystems, but a unix socket is not a regular file and cannot be shared between a Linux container and a MacOS host.

A unix socket can be shared between a container and a linux host.

AFAICT, the only way to enable tests running natively on MacOS to connect to mosquitto via a unix socket will involve running a native mosquitto process on the MacOS host.

This change modifies mosquitto.sh for this purpose.

As noted, we could structure this script to continue using the containerized mosquitto approach on Linux hosts where that will work with unix sockets.

@adam-fowler
Copy link
Collaborator

This script was originally written on the understanding mosquitto was running inside Docker and might be running in the background. We can probably remove that and just support running in the foreground now.

@jpgrayson
Copy link
Contributor Author

I can make the script just run in the foreground. That would be simpler and would avoid monkeying with a pid file.

I'd kind of like to have the option on Linux of running either non-containerized mosquitto or in a container. Perhaps by testing for a mosquitto executable and falling back to running a container.

I'll update the PR with these changes. Let me know what you think. And thanks again for taking a look at these changes.

@adam-fowler
Copy link
Collaborator

@jpgrayson this all sounds good.

@codecov-commenter
Copy link

codecov-commenter commented Nov 22, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (6c41888) 78.92% compared to head (45a7bd9) 78.92%.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #148   +/-   ##
=======================================
  Coverage   78.92%   78.92%           
=======================================
  Files          22       22           
  Lines        2500     2500           
=======================================
  Hits         1973     1973           
  Misses        527      527           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

scripts/mosquitto.sh Outdated Show resolved Hide resolved
The goal of mosquitto.sh is to get a mosquitto service up and running so
that tests can built and run in the native OS environment.

A mosquitto container running on a MacOS host cannot share a unix socket
from the Linux container to the MacOS host.

Running a native mosquitto instance from mosquitto.sh solves this
problem. The native mosquitto process can create/listen a
host-compatible unix socket.

The script is modified to run a locally installed mosquitto by default,
if available, and fallback to running mosquitto in a container.

For both the locally installed and containerized paths, the script now
just runs in the foreground; no more start/stop/status subcommands.
@adam-fowler adam-fowler merged commit 22c9b87 into swift-server-community:main Nov 27, 2023
8 checks passed
@jpgrayson jpgrayson deleted the native-mosquitto-script branch November 28, 2023 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants