Skip to content

Commit

Permalink
Add test for shutdown while loading model (#6837)
Browse files Browse the repository at this point in the history
* Add test for shutdown while loading

* Fix intermittent failure on test_model_config_overwrite
  • Loading branch information
kthui authored Jan 31, 2024
1 parent dfe9dde commit f345bbb
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
13 changes: 13 additions & 0 deletions qa/L0_lifecycle/lifecycle_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3317,6 +3317,7 @@ def test_model_config_overwite(self):

# Touch the local config.pbtxt and reload the file to ensure the local config
# is preferred because it has a more recent mtime.
time.sleep(0.1) # make sure timestamps are different
Path(os.path.join("models", model_name, "config.pbtxt")).touch()

# Reload the model
Expand Down Expand Up @@ -3347,6 +3348,18 @@ def test_shutdown_while_background_unloading(self):
# The server will shutdown after this sub-test exits. The server must shutdown
# without any hang or runtime error.

def test_shutdown_while_loading(self):
triton_client = self._get_client()
self.assertTrue(triton_client.is_server_live())
self.assertTrue(triton_client.is_server_ready())
# Load the model which will load for at least 10 seconds.
model_name = "identity_fp32"
with concurrent.futures.ThreadPoolExecutor() as pool:
pool.submit(triton_client.load_model, model_name)
self.assertFalse(triton_client.is_model_ready(model_name))
# The server will shutdown after this sub-test exits. The server must shutdown
# without any hang or runtime error.


if __name__ == "__main__":
unittest.main()
40 changes: 40 additions & 0 deletions qa/L0_lifecycle/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2062,6 +2062,46 @@ if [ $NUMBER_OF_MODELS_UNLOADED -ne 2 ]; then
RET=1
fi

LOG_IDX=$((LOG_IDX+1))

# LifeCycleTest.test_shutdown_while_loading
rm -rf models
mkdir models
cp -r ../python_models/identity_fp32 models/ && (cd models/identity_fp32 && \
mkdir 1 && mv model.py 1 && \
echo " def initialize(self, args):" >> 1/model.py && \
echo " import time" >> 1/model.py && \
echo " time.sleep(10)" >> 1/model.py)

SERVER_ARGS="--model-repository=`pwd`/models --model-control-mode=explicit --log-verbose=2"
SERVER_LOG="./inference_server_$LOG_IDX.log"
run_server
if [ "$SERVER_PID" == "0" ]; then
echo -e "\n***\n*** Failed to start $SERVER\n***"
cat $SERVER_LOG
exit 1
fi

set +e
python $LC_TEST LifeCycleTest.test_shutdown_while_loading >>$CLIENT_LOG 2>&1
if [ $? -ne 0 ]; then
cat $CLIENT_LOG
echo -e "\n***\n*** Test Failed\n***"
RET=1
fi
set -e

kill $SERVER_PID
wait $SERVER_PID

ACTUAL_LOAD_UNLOAD_ORDER="`grep -o -e 'AsyncUnload()' -e 'OnLoadFinal()' $SERVER_LOG`"
EXPECTED_LOAD_UNLOAD_ORDER="`echo -e 'OnLoadFinal()\nAsyncUnload()'`"
if [ "$ACTUAL_LOAD_UNLOAD_ORDER" != "$EXPECTED_LOAD_UNLOAD_ORDER" ]; then
cat $SERVER_LOG
echo -e "\n***\n*** Failed assert load finish before unload\n***"
RET=1
fi

if [ $RET -eq 0 ]; then
echo -e "\n***\n*** Test Passed\n***"
else
Expand Down

0 comments on commit f345bbb

Please sign in to comment.