@@ -29,12 +29,69 @@ RET=0
29
29
30
30
TEST_LOG=" ./response_cache_test.log"
31
31
UNIT_TEST=./response_cache_test
32
+ export CUDA_VISIBLE_DEVICES=0
33
+
34
+ # Only localhost supported in this test for now, but in future could make
35
+ # use of a persistent remote redis server, or similarly use --replicaof arg.
36
+ export TRITON_REDIS_HOST=" localhost"
37
+ export TRITON_REDIS_PORT=" 6379"
32
38
33
39
rm -fr * .log
34
40
35
- # UNIT TEST
41
+ function install_redis() {
42
+ # # Install redis if not already installed
43
+ if ! command -v redis-server > /dev/null 2>&1 ; then
44
+ apt update -y && apt install -y redis
45
+ fi
46
+ }
47
+
48
+ function start_redis() {
49
+ # Run redis server in background
50
+ redis-server --daemonize yes --port " ${TRITON_REDIS_PORT} "
51
+
52
+ # Check redis server is running
53
+ REDIS_PING_RESPONSE=$( redis-cli -h ${TRITON_REDIS_HOST} -p ${TRITON_REDIS_PORT} ping)
54
+ if [ " ${REDIS_PING_RESPONSE} " == " PONG" ]; then
55
+ echo " Redis successfully started in background"
56
+ else
57
+ echo -e " \n***\n*** Failed: Redis server did not start successfully\n***"
58
+ RET=1
59
+ fi
60
+ }
61
+
62
+ function stop_redis() {
63
+ echo " Stopping Redis server..."
64
+ redis-cli -h " ${TRITON_REDIS_HOST} " -p " ${TRITON_REDIS_PORT} " shutdown || true
65
+ echo " Redis server shutdown"
66
+ }
67
+
68
+ function set_redis_auth() {
69
+ # NOTE: Per-user auth [Access Control List (ACL)] is only supported in
70
+ # Redis >= 6.0 and is more comprehensive in what can be configured.
71
+ # For simplicity and wider range of Redis version support, use
72
+ # server-wide password via "requirepass" for now.
73
+ redis-cli -h " ${TRITON_REDIS_HOST} " -p " ${TRITON_REDIS_PORT} " config set requirepass " ${REDIS_PW} "
74
+ export REDISCLI_AUTH=" ${REDIS_PW} "
75
+ }
76
+
77
+ function unset_redis_auth() {
78
+ # Authenticate implicitly via REDISCLI_AUTH env var, then unset password/var
79
+ redis-cli -h " ${TRITON_REDIS_HOST} " -p " ${TRITON_REDIS_PORT} " config set requirepass " "
80
+ unset REDISCLI_AUTH
81
+ }
82
+
83
+ # UNIT TESTS
36
84
set +e
37
- export CUDA_VISIBLE_DEVICES=0
85
+
86
+ # # Unit tests currently run for both Local and Redis cache implementaitons
87
+ # # by default. However, we could break out the unit tests for each
88
+ # # into separate runs gtest filters if needed in the future:
89
+ # # - `${UNIT_TEST} --gtest_filter=*Local*`
90
+ # # - `${UNIT_TEST} --gtest_filter=*Redis*`
91
+ install_redis
92
+ # Stop any existing redis server first for good measure
93
+ stop_redis
94
+ start_redis
38
95
LD_LIBRARY_PATH=/opt/tritonserver/lib:$LD_LIBRARY_PATH $UNIT_TEST >> $TEST_LOG 2>&1
39
96
if [ $? -ne 0 ]; then
40
97
cat $TEST_LOG
@@ -48,10 +105,33 @@ function check_server_success_and_kill {
48
105
if [ " ${SERVER_PID} " == " 0" ]; then
49
106
echo -e " \n***\n*** Failed to start ${SERVER} \n***"
50
107
cat ${SERVER_LOG}
51
- exit 1
108
+ RET=1
109
+ else
110
+ kill ${SERVER_PID}
111
+ wait ${SERVER_PID}
112
+ fi
113
+ }
114
+
115
+ function check_server_expected_failure {
116
+ EXPECTED_MESSAGE=" ${1} "
117
+ if [ " ${SERVER_PID} " != " 0" ]; then
118
+ echo -e " \n***\n*** Failed: ${SERVER} started successfully when it was expected to fail\n***"
119
+ cat ${SERVER_LOG}
120
+ RET=1
121
+
122
+ kill ${SERVER_PID}
123
+ wait ${SERVER_PID}
124
+ else
125
+ # Check that server fails with the correct error message
126
+ set +e
127
+ grep -i " ${EXPECTED_MESSAGE} " ${SERVER_LOG}
128
+ if [ $? -ne 0 ]; then
129
+ echo -e " \n***\n*** Failed: Expected [${EXPECTED_MESSAGE} ] error message in output\n***"
130
+ cat $SERVER_LOG
131
+ RET=1
132
+ fi
133
+ set -e
52
134
fi
53
- kill $SERVER_PID
54
- wait $SERVER_PID
55
135
}
56
136
57
137
MODEL_DIR=" ${PWD} /models"
@@ -102,46 +182,66 @@ check_server_success_and_kill
102
182
# Test that specifying multiple cache types is not supported and should fail
103
183
SERVER_ARGS=" --model-repository=${MODEL_DIR} --cache-config=local,size=8192 --cache-config=redis,key=value ${EXTRA_ARGS} "
104
184
run_server
105
- if [ " $SERVER_PID " != " 0" ]; then
106
- echo -e " \n***\n*** Failed: $SERVER started successfully when it was expected to fail\n***"
107
- cat $SERVER_LOG
108
- RET=1
109
-
110
- kill $SERVER_PID
111
- wait $SERVER_PID
112
- else
113
- # Check that server fails with the correct error message
114
- set +e
115
- grep -i " multiple cache configurations" ${SERVER_LOG}
116
- if [ $? -ne 0 ]; then
117
- echo -e " \n***\n*** Failed: Expected multiple cache configuration error message in output\n***"
118
- cat $SERVER_LOG
119
- RET=1
120
- fi
121
- set -e
122
- fi
185
+ check_server_expected_failure " multiple cache configurations"
123
186
124
187
# Test that specifying both config styles is incompatible and should fail
125
188
SERVER_ARGS=" --model-repository=${MODEL_DIR} --response-cache-byte-size=12345 --cache-config=local,size=67890 ${EXTRA_ARGS} "
126
189
run_server
127
- if [ " $SERVER_PID " != " 0" ]; then
128
- echo -e " \n***\n*** Failed: $SERVER started successfully when it was expected to fail\n***"
129
- cat $SERVER_LOG
130
- RET=1
190
+ check_server_expected_failure " incompatible flags"
131
191
132
- kill $SERVER_PID
133
- wait $SERVER_PID
134
- else
135
- # Check that server fails with the correct error message
136
- set +e
137
- grep -i " incompatible flags" ${SERVER_LOG}
138
- if [ $? -ne 0 ]; then
139
- echo -e " \n***\n*** Failed: Expected incompatible cache config flags error message in output\n***"
140
- cat $SERVER_LOG
141
- RET=1
142
- fi
143
- set -e
144
- fi
192
+ # # Redis Cache CLI tests
193
+ REDIS_ENDPOINT=" --cache-config redis,host=${TRITON_REDIS_HOST} --cache-config redis,port=${TRITON_REDIS_PORT} "
194
+
195
+ # Test simple redis cache config succeeds
196
+ SERVER_ARGS=" --model-repository=${MODEL_DIR} ${REDIS_ENDPOINT} ${EXTRA_ARGS} "
197
+ run_server
198
+ check_server_success_and_kill
199
+
200
+ # Test triton fails to initialize if it can't connect to redis cache
201
+ SERVER_ARGS=" --model-repository=${MODEL_DIR} --cache-config=redis,host=localhost --cache-config=redis,port=nonexistent ${EXTRA_ARGS} "
202
+ run_server
203
+ check_server_expected_failure " Failed to connect to Redis: Connection refused"
204
+
205
+ # Test triton fails to initialize if it can't resolve host for redis cache
206
+ SERVER_ARGS=" --model-repository=${MODEL_DIR} --cache-config=redis,host=nonexistent --cache-config=redis,port=nonexistent ${EXTRA_ARGS} "
207
+ run_server
208
+ # Either of these errors can be returned for bad hostname, so check for either.
209
+ MSG1=" Temporary failure in name resolution"
210
+ MSG2=" Name or service not known"
211
+ check_server_expected_failure " ${MSG1} \|${MSG2} "
212
+
213
+ # Test triton fails to initialize if minimum required args (host & port) not all provided
214
+ SERVER_ARGS=" --model-repository=${MODEL_DIR} --cache-config=redis,port=${TRITON_REDIS_HOST} ${EXTRA_ARGS} "
215
+ run_server
216
+ check_server_expected_failure " Must at a minimum specify"
217
+
218
+ # # Redis Authentication tests
219
+
220
+ # Automatically provide auth via REDISCLI_AUTH env var when set: https://redis.io/docs/ui/cli/
221
+ REDIS_PW=" redis123!"
222
+ set_redis_auth
223
+
224
+ # Test simple redis authentication succeeds with correct credentials
225
+ REDIS_CACHE_AUTH=" --cache-config redis,password=${REDIS_PW} "
226
+ SERVER_ARGS=" --model-repository=${MODEL_DIR} ${REDIS_ENDPOINT} ${REDIS_CACHE_AUTH} ${EXTRA_ARGS} "
227
+ run_server
228
+ check_server_success_and_kill
229
+
230
+ # Test simple redis authentication fails with wrong credentials
231
+ REDIS_CACHE_AUTH=" --cache-config redis,password=wrong"
232
+ SERVER_ARGS=" --model-repository=${MODEL_DIR} ${REDIS_ENDPOINT} ${REDIS_CACHE_AUTH} ${EXTRA_ARGS} "
233
+ run_server
234
+ check_server_expected_failure " WRONGPASS"
235
+
236
+
237
+ # Test simple redis authentication fails with no credentials
238
+ SERVER_ARGS=" --model-repository=${MODEL_DIR} ${REDIS_ENDPOINT} ${EXTRA_ARGS} "
239
+ run_server
240
+ check_server_expected_failure " NOAUTH Authentication required"
241
+
242
+ # Clean up redis server before exiting test
243
+ unset_redis_auth
244
+ stop_redis
145
245
146
246
if [ $RET -eq 0 ]; then
147
247
echo -e " \n***\n*** Test Passed\n***"
0 commit comments