Skip to content

Commit

Permalink
Use Mosquitto test broker instead of EMQX
Browse files Browse the repository at this point in the history
Signed-off-by: Kate Goldenring <[email protected]>
  • Loading branch information
kate-goldenring committed Nov 1, 2024
1 parent 765a74e commit afa8e8d
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 67 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ target/

.tmp

test/*
test/*

.vscode/*
14 changes: 0 additions & 14 deletions scripts/deploy-workloads.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,14 @@ if ! command -v kubectl &> /dev/null; then
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl;
fi

update_mqtt_workload_with_broker_cluster_ip() {
local dir=$1
echo "Waiting for emqx pod to be ready"
kubectl wait --for=condition=ready --timeout=20s pod/emqx
# The MQTT trigger cannot do DNS resolution, so we need to use the IP address of the MQTT broker
# Replace "EMQX_CLUSTER_IP" with the actual ClusterIP of the EMQX service
local cluster_ip=$(kubectl get svc emqx -o jsonpath='{.spec.clusterIP}')
sed -i "s/EMQX_CLUSTER_IP/$cluster_ip/g" $dir/workloads.yaml
echo "Updated workloads.yaml with ClusterIP: $cluster_ip"
}


# apply the workloads
echo ">>> apply workloads"
kubectl apply -f tests/workloads-common

if [ "$1" == "workloads-pushed-using-spin-registry-push" ]; then
update_mqtt_workload_with_broker_cluster_ip "tests/workloads-pushed-using-spin-registry-push"
echo "deploying spin apps pushed to registry using 'spin registry push' command"
kubectl apply -f tests/workloads-pushed-using-spin-registry-push
else
update_mqtt_workload_with_broker_cluster_ip "tests/workloads-pushed-using-docker-build-push"
echo "deploying spin apps pushed to registry using 'docker build && k3d image import' command"
kubectl apply -f tests/workloads-pushed-using-docker-build-push
fi
Expand Down
28 changes: 7 additions & 21 deletions tests/src/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,16 @@ mod test {
anyhow::bail!("kubectl is not installed");
}

// Port forward the emqx mqtt broker
let forward_port = port_forward_emqx(mqtt_port).await?;

// Publish a message to the emqx broker
let mut mqttoptions = rumqttc::MqttOptions::new("123", "127.0.0.1", forward_port);
// Publish a message to the MQTT broker
let mut mqttoptions = rumqttc::MqttOptions::new("123", "test.mosquitto.org", mqtt_port);
mqttoptions.set_keep_alive(std::time::Duration::from_secs(1));

let (client, mut eventloop) = rumqttc::AsyncClient::new(mqttoptions, 10);
client
.subscribe("hello", rumqttc::QoS::AtMostOnce)
.subscribe(
"containerd-shim-spin/mqtt-test-17h24d",
rumqttc::QoS::AtMostOnce,
)
.await
.unwrap();

Expand All @@ -153,7 +153,7 @@ mod test {
for _i in 0..iterations {
client
.publish(
"hello",
"containerd-shim-spin/mqtt-test-17h24d",
rumqttc::QoS::AtLeastOnce,
false,
message.as_bytes(),
Expand Down Expand Up @@ -227,20 +227,6 @@ mod test {
Ok(port)
}

async fn port_forward_emqx(emqx_port: u16) -> Result<u16> {
let port = get_random_port()?;

println!(" >>> kubectl portforward emqx {}:{} ", port, emqx_port);

Command::new("kubectl")
.arg("port-forward")
.arg("emqx")
.arg(format!("{}:{}", port, emqx_port))
.spawn()?;
tokio::time::sleep(tokio::time::Duration::from_secs(2)).await;
Ok(port)
}

async fn get_logs_by_label(label: &str) -> Result<String> {
let output = Command::new("kubectl")
.arg("logs")
Expand Down
25 changes: 0 additions & 25 deletions tests/workloads-common/mqtt-broker.yaml

This file was deleted.

5 changes: 2 additions & 3 deletions tests/workloads-pushed-using-docker-build-push/workloads.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,10 @@ spec:
- containerPort: 80
env:
- name: SPIN_VARIABLE_MQTT_TOPIC
value: hello
value: containerd-shim-spin/mqtt-test-17h24d
# The MQTT trigger cannot do DNS resolution, so we need to use the IP address of the MQTT broker
# Substitute `EMQX_CLUSTER_IP` with the result of `kubectl get svc emqx -n default -o jsonpath='{.spec.clusterIP}'`
- name: SPIN_VARIABLE_MQTT_BROKER_URI
value: "mqtt://EMQX_CLUSTER_IP:1883"
value: "mqtt://test.mosquitto.org"
---
apiVersion: v1
kind: Service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,10 @@ spec:
- containerPort: 80
env:
- name: SPIN_VARIABLE_MQTT_TOPIC
value: hello
value: containerd-shim-spin/mqtt-test-17h24d
# The MQTT trigger cannot do DNS resolution, so we need to use the IP address of the MQTT broker
# Substitute `EMQX_CLUSTER_IP` with the result of `kubectl get svc emqx -n default -o jsonpath='{.spec.clusterIP}'`
- name: SPIN_VARIABLE_MQTT_BROKER_URI
value: "mqtt://EMQX_CLUSTER_IP:1883"
value: "mqtt://test.mosquitto.org"
---
apiVersion: v1
kind: Service
Expand Down

0 comments on commit afa8e8d

Please sign in to comment.