import os import time import random from locust import HttpUser, task, between, constant, tag base_dir = '/home/lk/MyProject/BMW_F3OCR/数据集/文件分类/营业执照' file_path_list = [os.path.join(base_dir, file_name) for file_name in os.listdir(base_dir)] class QuickstartUser(HttpUser): # wait_time = between(1, 5) @tag('sync') @task def sync_test(self): self.client.get("/sync") @tag('async') @task def async_test(self): self.client.get("/async") @tag('sync_classification') @task def sync_classification(self): img_path = random.choice(file_path_list) files=[('image', ('', open(img_path,'rb'), ''))] self.client.post("/sync_classification", files=files) @tag('async_classification') @task def async_classification(self): img_path = random.choice(file_path_list) files=[('image', ('', open(img_path,'rb'), ''))] self.client.post("/async_classification", files=files)