forked from HenryNdubuaku/tango
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·96 lines (77 loc) · 2.17 KB
/
Copy pathtest.sh
File metadata and controls
executable file
·96 lines (77 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/bin/bash
# filepath: ./deploy_test.sh
# This script builds the module, compiles protos, terminates any process using port 50051,
# runs the server and clients, and stops all processes after a fixed duration.
# New flags:
# --production If present, the test will use the deployed IP.
# --project <ID> Set the project ID. Defaults to "tango-v1-452518" if not provided.
set -e
export GOOGLE_APPLICATION_CREDENTIALS=gcp-credentials.json
export PATH="$PATH:$(go env GOPATH)/bin"
DEFAULT_PROJECT_ID="tango-v1-452518"
PROJECT_ID="$DEFAULT_PROJECT_ID"
PRODUCTION_FLAG=0
SLEEP_DURATION=10
while [[ $# -gt 0 ]]; do
case "$1" in
--production)
PRODUCTION_FLAG=1
shift
;;
--project)
PROJECT_ID="$2"
shift 2
;;
*)
shift
;;
esac
done
DEPLOYED_IP=$(gcloud compute addresses describe tango-static-ip \
--project=${PROJECT_ID} \
--region=us-central1 \
--format="value(address)")
if [ $PRODUCTION_FLAG -eq 1 ]; then
TANGO_ADDRESS="${DEPLOYED_IP}:50051"
else
TANGO_ADDRESS="localhost:50051"
fi
echo "Using Tango address: ${TANGO_ADDRESS}"
echo "Using Project ID: ${PROJECT_ID}"
go mod tidy
protoc -I. \
--go_out=src/protobuff --go_opt=paths=source_relative \
--go-grpc_out=src/protobuff --go-grpc_opt=paths=source_relative \
protobuff.proto
protoc -I. --cpp_out=cpp protobuff.proto
cleanup() {
echo "Stopping all processes..."
kill $SERVER_PID $DEVICE_PID $JOB_PID 2>/dev/null || true
exit
}
trap cleanup EXIT INT TERM
OLD_PID=$(lsof -t -i:50051 || true)
if [ -n "$OLD_PID" ]; then
echo "Port 50051 is in use. Terminating process(es): $OLD_PID"
kill -9 $OLD_PID
sleep 2
fi
if [ $PRODUCTION_FLAG -eq 0 ]; then
echo "Starting server..."
go run main.go &
SERVER_PID=$!
sleep 2
echo "Starting device simulator..."
go run test/device_client.go --tango-address ${TANGO_ADDRESS} &
DEVICE_PID=$!
sleep 2
fi
echo "Starting job submission client..."
go run test/job_client.go --tango-address ${TANGO_ADDRESS} &
JOB_PID=$!
echo "Server PID: $SERVER_PID"
echo "Device Simulator PID: $DEVICE_PID"
echo "Job Submission PID: $JOB_PID"
echo "Test will run for $SLEEP_DURATION seconds..."
sleep $SLEEP_DURATION
cleanup