Skip to content

Commit 5658b32

Browse files
Use Mosquitto test broker instead of EMQX
Signed-off-by: Kate Goldenring <[email protected]>
1 parent 765a74e commit 5658b32

File tree

6 files changed

+14
-67
lines changed

6 files changed

+14
-67
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ target/
99

1010
.tmp
1111

12-
test/*
12+
test/*
13+
14+
.vscode/*

scripts/deploy-workloads.sh

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,14 @@ if ! command -v kubectl &> /dev/null; then
99
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl;
1010
fi
1111

12-
update_mqtt_workload_with_broker_cluster_ip() {
13-
local dir=$1
14-
echo "Waiting for emqx pod to be ready"
15-
kubectl wait --for=condition=ready --timeout=20s pod/emqx
16-
# The MQTT trigger cannot do DNS resolution, so we need to use the IP address of the MQTT broker
17-
# Replace "EMQX_CLUSTER_IP" with the actual ClusterIP of the EMQX service
18-
local cluster_ip=$(kubectl get svc emqx -o jsonpath='{.spec.clusterIP}')
19-
sed -i "s/EMQX_CLUSTER_IP/$cluster_ip/g" $dir/workloads.yaml
20-
echo "Updated workloads.yaml with ClusterIP: $cluster_ip"
21-
}
22-
23-
2412
# apply the workloads
2513
echo ">>> apply workloads"
2614
kubectl apply -f tests/workloads-common
2715

2816
if [ "$1" == "workloads-pushed-using-spin-registry-push" ]; then
29-
update_mqtt_workload_with_broker_cluster_ip "tests/workloads-pushed-using-spin-registry-push"
3017
echo "deploying spin apps pushed to registry using 'spin registry push' command"
3118
kubectl apply -f tests/workloads-pushed-using-spin-registry-push
3219
else
33-
update_mqtt_workload_with_broker_cluster_ip "tests/workloads-pushed-using-docker-build-push"
3420
echo "deploying spin apps pushed to registry using 'docker build && k3d image import' command"
3521
kubectl apply -f tests/workloads-pushed-using-docker-build-push
3622
fi

tests/src/integration_test.rs

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -135,16 +135,16 @@ mod test {
135135
anyhow::bail!("kubectl is not installed");
136136
}
137137

138-
// Port forward the emqx mqtt broker
139-
let forward_port = port_forward_emqx(mqtt_port).await?;
140-
141-
// Publish a message to the emqx broker
142-
let mut mqttoptions = rumqttc::MqttOptions::new("123", "127.0.0.1", forward_port);
138+
// Publish a message to the MQTT broker
139+
let mut mqttoptions = rumqttc::MqttOptions::new("123", "test.mosquitto.org", mqtt_port);
143140
mqttoptions.set_keep_alive(std::time::Duration::from_secs(1));
144141

145142
let (client, mut eventloop) = rumqttc::AsyncClient::new(mqttoptions, 10);
146143
client
147-
.subscribe("hello", rumqttc::QoS::AtMostOnce)
144+
.subscribe(
145+
"containerd-shim-spin/mqtt-test-17h24d",
146+
rumqttc::QoS::AtMostOnce,
147+
)
148148
.await
149149
.unwrap();
150150

@@ -153,7 +153,7 @@ mod test {
153153
for _i in 0..iterations {
154154
client
155155
.publish(
156-
"hello",
156+
"containerd-shim-spin/mqtt-test-17h24d",
157157
rumqttc::QoS::AtLeastOnce,
158158
false,
159159
message.as_bytes(),
@@ -227,20 +227,6 @@ mod test {
227227
Ok(port)
228228
}
229229

230-
async fn port_forward_emqx(emqx_port: u16) -> Result<u16> {
231-
let port = get_random_port()?;
232-
233-
println!(" >>> kubectl portforward emqx {}:{} ", port, emqx_port);
234-
235-
Command::new("kubectl")
236-
.arg("port-forward")
237-
.arg("emqx")
238-
.arg(format!("{}:{}", port, emqx_port))
239-
.spawn()?;
240-
tokio::time::sleep(tokio::time::Duration::from_secs(2)).await;
241-
Ok(port)
242-
}
243-
244230
async fn get_logs_by_label(label: &str) -> Result<String> {
245231
let output = Command::new("kubectl")
246232
.arg("logs")

tests/workloads-common/mqtt-broker.yaml

Lines changed: 0 additions & 25 deletions
This file was deleted.

tests/workloads-pushed-using-docker-build-push/workloads.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,11 +284,10 @@ spec:
284284
- containerPort: 80
285285
env:
286286
- name: SPIN_VARIABLE_MQTT_TOPIC
287-
value: hello
287+
value: containerd-shim-spin/mqtt-test-17h24d
288288
# The MQTT trigger cannot do DNS resolution, so we need to use the IP address of the MQTT broker
289-
# Substitute `EMQX_CLUSTER_IP` with the result of `kubectl get svc emqx -n default -o jsonpath='{.spec.clusterIP}'`
290289
- name: SPIN_VARIABLE_MQTT_BROKER_URI
291-
value: "mqtt://EMQX_CLUSTER_IP:1883"
290+
value: "mqtt://test.moquitto.org"
292291
---
293292
apiVersion: v1
294293
kind: Service

tests/workloads-pushed-using-spin-registry-push/workloads.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,11 +284,10 @@ spec:
284284
- containerPort: 80
285285
env:
286286
- name: SPIN_VARIABLE_MQTT_TOPIC
287-
value: hello
287+
value: containerd-shim-spin/mqtt-test-17h24d
288288
# The MQTT trigger cannot do DNS resolution, so we need to use the IP address of the MQTT broker
289-
# Substitute `EMQX_CLUSTER_IP` with the result of `kubectl get svc emqx -n default -o jsonpath='{.spec.clusterIP}'`
290289
- name: SPIN_VARIABLE_MQTT_BROKER_URI
291-
value: "mqtt://EMQX_CLUSTER_IP:1883"
290+
value: "mqtt://test.moquitto.org"
292291
---
293292
apiVersion: v1
294293
kind: Service

0 commit comments

Comments
 (0)