進度測試
This commit is contained in:
		
							
								
								
									
										57
									
								
								test.sh
									
									
									
									
									
								
							
							
						
						
									
										57
									
								
								test.sh
									
									
									
									
									
								
							@@ -18,9 +18,9 @@ function message() {
 | 
			
		||||
    info=$2
 | 
			
		||||
    if [[ ${response: -3} -eq 200 ]]; then
 | 
			
		||||
        if [[ $# -eq 3 ]] && [[ $3 == true ]]; then
 | 
			
		||||
            echo "[測試成功] $info: $response"
 | 
			
		||||
            echo "[測試通過] $info: $response"
 | 
			
		||||
        else
 | 
			
		||||
            echo "[測試成功] $info"
 | 
			
		||||
            echo "[測試通過] $info"
 | 
			
		||||
        fi
 | 
			
		||||
    else
 | 
			
		||||
        pkill -f go_test && rm -f data/sqlite3.db && echo "[$info]測試失敗: $response" && exit 1
 | 
			
		||||
@@ -67,9 +67,14 @@ response=$(curl -X PATCH -H "Content-Type: application/json" -d '{"images":["htt
 | 
			
		||||
message "$response" "修改數據集"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# 訓練模型 (POST /api/models)
 | 
			
		||||
# 服務器列表
 | 
			
		||||
response=$(curl -X GET -b "session_id=$session_id" -s -w "%{http_code}" http://localhost:8080/api/servers)
 | 
			
		||||
message "$response" "服務器列表" true
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# 創建模型訓練任務 (POST /api/models)
 | 
			
		||||
response=$(curl -X POST -H "Content-Type: application/json" -d '{"name":"test","type":"dreambooth","trigger_words":"miao~","base_model":"sd1.5","epochs":20,"description":"test","dataset_id":'$dataset_id'}' -b "session_id=$session_id" -s -w "%{http_code}" http://localhost:8080/api/models)
 | 
			
		||||
message "$response" "訓練模型"
 | 
			
		||||
message "$response" "創建模型訓練任務" true
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# 取模型id的值, 值爲 int
 | 
			
		||||
@@ -77,36 +82,22 @@ model_id=$(echo "${response%???}" | grep -o '"id": [0-9]*' | awk '{print $2}')
 | 
			
		||||
#echo "model_id: $model_id"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# 模型列表 (GET /api/models)
 | 
			
		||||
response=$(curl -X GET -H "Content-Type: application/json" -b "session_id=$session_id" -s -w "%{http_code}" http://localhost:8080/api/models)
 | 
			
		||||
message "$response" "模型列表" true
 | 
			
		||||
# 循環獲取模型訓練進度, 直到訓練完成
 | 
			
		||||
while true; do
 | 
			
		||||
    # 獲取模型訓練進度 (GET /api/models/:id)
 | 
			
		||||
    response=$(curl -X GET -b "session_id=$session_id" -s -w "%{http_code}" http://localhost:8080/api/models/$model_id)
 | 
			
		||||
    progress=$(echo "${response%???}" | grep -o '"progress": [0-9]*' | awk '{print $2}')
 | 
			
		||||
    status=$(echo "${response%???}" | grep -o '"status": "[^"]*' | cut -d '"' -f 4)
 | 
			
		||||
    message "$response" "獲取模型訓練進度 $progress% $status"
 | 
			
		||||
    # 如果進度爲 100, 訓練完成, 跳出循環
 | 
			
		||||
    [[ $progress -eq 100 ]] && { echo "訓練完成"; break; }
 | 
			
		||||
    # 休眠 5 秒
 | 
			
		||||
    sleep 5
 | 
			
		||||
done
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
## 獲取模型訓練進度 (GET /api/models/:id)
 | 
			
		||||
#response=$(curl -X GET -b "session_id=$session_id" -s -w "%{http_code}" http://localhost:8080/api/models/$model_id)
 | 
			
		||||
#[[ ${response: -3} -eq 200 ]] && { echo "獲取模型訓練進度成功: ${response%???}"; } || exit_service "獲取模型訓練進度失敗: ${response%???}"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
## 循環獲取模型訓練進度, 直到訓練完成
 | 
			
		||||
#while true; do
 | 
			
		||||
#    # 獲取模型訓練進度 (GET /api/models/:id)
 | 
			
		||||
#    response=$(curl -X GET -b "session_id=$session_id" -s -w "%{http_code}" http://localhost:8080/api/models/$model_id)
 | 
			
		||||
#    [[ ${response: -3} -eq 200 ]] && { echo "獲取模型訓練進度成功: ${response%???}"; } || exit_service "獲取模型訓練進度失敗: ${response%???}"
 | 
			
		||||
#
 | 
			
		||||
#    # 取出進度字段的值, 值爲 int
 | 
			
		||||
#    progress=$(echo "${response%???}" | grep -o '"progress": [0-9]*' | awk '{print $2}')
 | 
			
		||||
#    echo "progress: $progress"
 | 
			
		||||
#
 | 
			
		||||
#    # 如果進度爲 100, 訓練完成, 跳出循環
 | 
			
		||||
#    [[ $progress -eq 100 ]] && { echo "訓練完成"; break; }
 | 
			
		||||
#
 | 
			
		||||
#    # 休眠 5 秒
 | 
			
		||||
#    sleep 5
 | 
			
		||||
#done
 | 
			
		||||
 | 
			
		||||
# 服務器列表
 | 
			
		||||
response=$(curl -X GET -b "session_id=$session_id" -s -w "%{http_code}" http://localhost:8080/api/servers)
 | 
			
		||||
message "$response" "服務器列表" true
 | 
			
		||||
## 模型列表 (GET /api/models)
 | 
			
		||||
#response=$(curl -X GET -H "Content-Type: application/json" -b "session_id=$session_id" -s -w "%{http_code}" http://localhost:8080/api/models)
 | 
			
		||||
#message "$response" "模型列表"
 | 
			
		||||
 | 
			
		||||
sleep 10
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user