当前位置:网站首页>基于Locust框架进行文件上传下载性能测试
基于Locust框架进行文件上传下载性能测试
2022-07-26 12:44:00 【码同学软件测试】
在很多业务场景中,需要针对文件上传和下载进行测试。当你要测试一个业务时,必须要先理解这个业务的本质。我们先来看下上传和下载的本质。
文件上传过程
1、在浏览器上选择本地文件,点击上传
2、浏览器读取本地文件,将文件内容放到HTTP请求的body中,然后在HTTP请求头中,标记请求数据类型:
Content-type:multipart/form-data,
以post形式提交至服务端。
3、服务端接受到请求数据后,在服务器上新建一个文件,将body中的数据写入到文件,一次文件上传处理完成。
文件下载过程
1、在浏览器上点击下载按钮,向服务端发起一个HTTP get类型请求
2、服务端接收到请求后,将对应文件内容读取出来,写入到HTTP响应中,并在响应头里标记Content- Disposition: attachment; filename=xxx
3、浏览器接受到响应后,根据标记识别出本次是下载请求,根据标记中的filename在本地创建一个同名文件,然后将响应中的数据写入到文件里,一次下载文件处理完成。
从上传和下载的描述中可以看出,所谓的文件上传和下载,其实都是将文件内容附加到HTTP请求里进行传输。
使用Locust测试文件上传下载
先来看下某项目上传和下载的接口文档

文件上传脚本编写

执行脚本,在本地浏览器中请求http://localhost:8089/,输入并发用户,和ip端口,点击开始执行

可以在Pycharm的控制台上打印出每次上传的返回结果

文件下载脚本编写

执行脚本,在locust UI界面上开始测试,可以在Pycharm中看到接口的返回值
在这里插入图片描述
注意事项
下载文件过程中,服务端只负责把文件内容返回给客户端,文件的创建和保存应该是客户端来做的。如果做服务端的接口测试,本地就不需要创建文件了。文件的内容是放在响应body中的,只需要判断响应body的大小和文件大小相同,即代表下载成功了。
边栏推荐
- 华为年内二度招聘“天才少年”;540万Twitter账号信息泄露,卖价3万美元;谷歌解雇了相信AI有意识的工程师|极客头条...
- Redisson distributed lock usage example (I)
- Sword finger offer 24. reverse the linked list
- Panorama of volcanic engine cloud growth plan: 30 + plans come out together, and military development advantage areas
- JDBC gets connections from the connection pool (Druid connection pool)
- The strongest tool class of entity mapping: mapstruct Zhenxiang
- 食品安全 | 随便果可以”随便“吃吗?
- Backtracking - question 51 Queen n -- a classic backtracking problem that must be overcome
- 代码报错解决问题经验之二:YOLOv5中的test报错
- Data query where
猜你喜欢

V00 - do whatever you want when you are old

What is the Internet of things? The most comprehensive explanation of common IOT protocols

回溯——46. 全排列

Today in history: IBM obtained the first patent; Verizon acquires Yahoo; Amazon releases fire phone

代码报错解决问题经验之二:YOLOv5中的test报错

HCIP-9.OSPF的各种拓展

维度灾难 维数灾难 暂记

Vs code set the method of ctrl+s saving and automatic formatting

Emerging security providers to learn about in 2022

Shutter background graying effect, how transparency, gray mask
随机推荐
数字化时代,是什么“黄金宝藏”在推动百年药企发展?
Remote IP debugger (Practical dry goods)
The.Net webapi uses groupname to group controllers to render the swagger UI
UE5 官方案例Lyra 全特性详解 7.资源管理
Version of NDK matched the requested version 21.0.6113669. versions available locally: 2
What is a callback function? Understanding of the word "back"
JDBC gets connections from the connection pool (Druid connection pool)
(int argc, char** argv) command line parameters in visual stdio (VS)
高通再次「押宝」中科创达,挑战智能驾驶软硬件全栈方案
A super easy-to-use artifact apifox, throw swagger a few streets... (glory Collection Edition)
Tencent cloud and smart industry business group (CSIG) adjusted the organizational structure and established the digital twin product department
C regards type as generic type T and uses it as generic type of method
今日睡眠质量记录75分
Kubernetes----Kubernetes常用插件简介
Kubernetes -- Introduction to common plug-ins of kubernetes
Data query where
可移动表空间
Various extensions of hcip-9.ospf
酷早报:7月25日Web3加密行业新闻大汇总
Paper reading MLPD: multi label pedestrian detector in multispectral domain (Internship Program of Hikvision Research Institute)