Testing App
Test Three-Tier Stack
In this section of the lab, we will test the following:
- Test the complete application flow from HAProxy through
Node.jsapp to Postgres database - Verify connectivity, data persistence, and load balancing functionality.
Verify VM Connectivity
Confirm all three VMs are running and network accessible from your workstation:
-
Get IP addresses from Prism UI (Compute > VMs) or SSH into each
-
SSH test from HAProxy VM to app and DB:
# On haproxy-vm-01 ssh ubuntu@app-vm-01.local "curl -I http://localhost:3000" ssh ubuntu@db-vm-01.local "sudo netstat -tlnp | grep 5432"All VMs must resolve via DHCP hostnames or update /etc/hosts on each VM.
Test HAProxy Load Balancer
-
Access the application through HAProxy frontend:
Check HAProxy stats: curl http://haproxy-vm-01.local/haproxy?stats (enable in config).
Verify App-to-Database Connectivity
-
On app-vm-01, confirm Node.js connects to Postgres:
App should show successful DB queries in logs during curl tests.
Validate Data Persistence
-
Create and verify data flows through all layers:
-
List todos (should show new item)
-
Verify in Postgres directly
Database query should match API response JSON.
Load Balancing Test (Optional Scale)
-
Deploy second app VM (app-vm-02-userXX) via UI or API, add to HAProxy backend:
-
On the HAProxy VM, modify the
/etc/haproxy/haproxy.cfgfile to include the second front-end app VM. -
Reload haproxy with new settings
-
Test multiple requests:
Check HAProxy stats for even distribution of traffic.
Monitoring and Troubleshooting
Open VSCode > Terminal on your jumphost
Check logs and ensure functionality:
ssh ubuntu@haproxy-vm-01-user01 'sudo journalctl -u haproxy -f' # HAProxy logs
ssh ubuntu@app-vm-01-user01 'pm2 logs' # App logs
ssh ubuntu@db-vm-01-user01 'sudo tail -f /var/log/postgresql/*.log' # Postgres logs
Common issues:
| Issue | Symptoms | Fix |
|---|---|---|
| 502 Bad Gateway | HAProxy can't reach app | Verify app:3000, firewall, hostname resolution confluence.atlassian |
| DB Connection Failed | App logs show Postgres errors | Check postgres service, password, todos DB exists github |
| No HAProxy response | Port 80 blocked | sudo ufw allow 80 or disable firewall |
Performance Validation
Monitor resource usage in Prism UI (Compute > VMs > Analyze):
-
App VM: CPU < 50%, Memory < 3GB during load tests
-
DB VM: Disk IOPS low, connections = active users
-
HAProxy: Minimal CPU/RAM usage
Success criteria: 100% API uptime, data persistence, HAProxy health checks green.