Skip to content

Commit ae86afa

Browse files
fix: switch to using EMQX MQTT broker for e2e tests
Signed-off-by: Kate Goldenring <[email protected]>
1 parent b60027b commit ae86afa

File tree

5 files changed

+59
-4
lines changed

5 files changed

+59
-4
lines changed

scripts/deploy-workloads.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,29 @@ 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+
1223
# apply the workloads
1324
echo ">>> apply workloads"
1425
kubectl apply -f tests/workloads-common
1526
# wait for all the pods to be ready
1627
kubectl wait --for=condition=ready --timeout=120s pod --all
1728

1829
if [ "$1" == "workloads-pushed-using-spin-registry-push" ]; then
30+
update_mqtt_workload_with_broker_cluster_ip "tests/workloads-pushed-using-spin-registry-push"
1931
echo "deploying spin apps pushed to registry using 'spin registry push' command"
2032
kubectl apply -f tests/workloads-pushed-using-spin-registry-push
2133
else
34+
update_mqtt_workload_with_broker_cluster_ip "tests/workloads-pushed-using-docker-build-push"
2235
echo "deploying spin apps pushed to registry using 'docker build && k3d image import' command"
2336
kubectl apply -f tests/workloads-pushed-using-docker-build-push
2437
fi

tests/src/integration_test.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,11 @@ mod test {
174174
anyhow::bail!("kubectl is not installed");
175175
}
176176

177-
// Publish a message to the MQTT broker
178-
let mut mqttoptions = rumqttc::MqttOptions::new("123", "test.mosquitto.org", mqtt_port);
177+
// Port forward the emqx mqtt broker
178+
let forward_port = port_forward_emqx(mqtt_port).await?;
179+
180+
// Publish a message to the emqx broker
181+
let mut mqttoptions = rumqttc::MqttOptions::new("123", "127.0.0.1", forward_port);
179182
mqttoptions.set_keep_alive(std::time::Duration::from_secs(1));
180183

181184
let (client, mut eventloop) = rumqttc::AsyncClient::new(mqttoptions, 10);
@@ -216,6 +219,20 @@ mod test {
216219
Ok(())
217220
}
218221

222+
async fn port_forward_emqx(emqx_port: u16) -> Result<u16> {
223+
let port = get_random_port()?;
224+
225+
println!(" >>> kubectl portforward emqx {}:{} ", port, emqx_port);
226+
227+
Command::new("kubectl")
228+
.arg("port-forward")
229+
.arg("emqx")
230+
.arg(format!("{}:{}", port, emqx_port))
231+
.spawn()?;
232+
tokio::time::sleep(tokio::time::Duration::from_secs(2)).await;
233+
Ok(port)
234+
}
235+
219236
#[tokio::test]
220237
async fn spin_static_assets_test() -> Result<()> {
221238
let host_port = 8082;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
name: emqx
5+
labels:
6+
app: emqx
7+
spec:
8+
containers:
9+
- name: emqx
10+
image: emqx/emqx
11+
ports:
12+
- containerPort: 1883
13+
---
14+
apiVersion: v1
15+
kind: Service
16+
metadata:
17+
name: emqx
18+
spec:
19+
selector:
20+
app: emqx
21+
ports:
22+
- protocol: TCP
23+
port: 1883
24+
targetPort: 1883
25+
type: ClusterIP

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ spec:
287287
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
289289
- name: SPIN_VARIABLE_MQTT_BROKER_URI
290-
value: "mqtt://test.mosquitto.org"
290+
value: "mqtt://EMQX_CLUSTER_IP:1883"
291291
---
292292
apiVersion: v1
293293
kind: Service

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ spec:
287287
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
289289
- name: SPIN_VARIABLE_MQTT_BROKER_URI
290-
value: "mqtt://test.mosquitto.org"
290+
value: "mqtt://EMQX_CLUSTER_IP:1883"
291291
---
292292
apiVersion: v1
293293
kind: Service

0 commit comments

Comments
 (0)