Showing posts with label 專案測試. Show all posts
Showing posts with label 專案測試. Show all posts

Monday, December 23, 2019

[SuperBenchmarker] Use different data for every request


 Stress Test    Load Test   Http   RESTful


▌Introduction


Sometime we need to have different data for load test with SuperBenchmarker.
SuperBenchmarker provides a convenient way to make different Url or payload.

▋Related articles



▌Implement


For example, we have an HttpPost API like this:

http://localhost:5000/seminar/signin/<my-token>

and Its payload is as following JSON,

{
    "id": "JB",
    "pwd": "1234"
}


▋Mocked dataset

Lets create a CSV file to store the
·         Token (For url)
·         Id (For payload)
·         Pwd (For payload)


▋SignIn_data.csv

token,id,pwd
AAAAA,JB1,1234
BBBBB,JB2,2345
CCCCC,JB3,3456
DDDDD,JB4,4567
EEEEE,JB5,5678


▋Http Raw file

Replace the Http Raw with {{{}}} to indicate that it will be replaced by the content from Dataset (SignIn_data.csv).


▋SignIn_data.csv

Content-Type: application/json

{"Id":"{{{id}}}", "Pwd":"{{{pwd}}}"}



▋Start testing the API


sb -u
"http://localhost:5000/seminar/signin/{{{token}}}" -n 5 -c 2 -m POST -f D:\Temp\SignIn_data.csv -t D:\Temp\HttpRaw_SignIn.txt


-u
Request URL
-n
How many requests you want to send.
-c
The number of concurrent requests for each boost.
-m
Http method type
-f
The path of mocked dataset
-t
Optional, if you have to add something to the header and message of Http request, then you have to put the complete http raw in a file.


Result:



What the API gets,



▌Reference


l   https://github.com/aliostad/SuperBenchmarker


Tuesday, March 8, 2016

[Lesson and learned] Sql Server restore database

 Microsoft Sql Server    Database Deploy





▌Background


這次在系統過版時,因為Database Table schema改變的相當多,在正式環境的資料並無重大隱私資料和個人資料(如密碼)已經加密的情況下; 決定將Production的Database先停止服務後,以備份Production→還原至測試環境→更新資料庫→還原至Production
的方式進行。

先說明各DB Server的環境 …
Production : Sql Server 20008 R2 Enterprise
Test : Sql Server 2012 SP1 Enterprise

備份Production→還原至測試環境 這一段是沒有問題的, 可是在還原至Production就失敗了。
原因是因為新版本的DB備份檔(.bak)是無法還原至舊版本的Sql Server!

所以在建立Solution時,也需要透過Secondary research了解一下限制,避免踩雷 L


▌Solve the problem


有兩種方式可以取代 backup & restore的方式。
另外節錄自StackFlow-Ohad Schneider 提供的觀念:

·         Backup / Restore - will not work when the target is an earlier MS SQL version.
·         Copy Database - will not work when the target is SQL Server Express: "The destination server cannot be a SQL Server 2005 or later Express instance."



▋Copy Database Wizard 複製資料庫精靈




 使用複製資料庫時,需要開啟一個UNC資料夾讓來源及目的端做資料傳輸。


▋Generate Scripts 產生指令碼

 

產生指令碼可以直接輸出Schema, 但是複製資料還是要透過「匯出資料」。

 


▌Reference



Thursday, October 15, 2015

使用SuperBenchmarker對Http服務進行簡易壓力測試

 Stress Test    Load Test   Http   Restful


▌背景


以前在開發線上交易的專案中,有實作一套從資料庫設定測試資料,搭配Visual Studio 負載測試工具,可模擬較複雜的壓測案例。

但如果是針對網站或較簡單的HTTP Methods進行壓測,SuperBenchmarker 這套Command line工具可以幫上很大的忙!

關於SuperBenchmarker的下載及使用方式,可參考此篇文章:



建議直接到SuperBenchmarker 的Github直接下載原始碼,在本機重新編譯及還原相關套件後就可以使用了。


本篇主要以測試Restful的POST方法為例。

▌測試Web Api的POST方法


參考指令:

sb -u
 http://localhost:8888/api/XXX -n 100 -c 5 -m POST -t D:\Temp\HttpRaw.txt

參數說明如下

-u
Request URL
-n
How many requests you want to send.
-c
The number of concurrent requests for each boost.
-m
Http method type
-t
Optional, if you have to add something to the header and message of Http request, then you have to put the complete http raw in a file.



因為我測試的POST方法需要帶JSON資料過去,所以需要建立一個 Http Raw file, 可以直接用POSTMAN或Fiddler先嘗試送一個Request,再擷取其完整Http Raw即可。






接下來可以準備開始壓測了,如果你需要用Fiddler看一下每筆Request的資料,記得將URL加上Fiddler listening port。



測試結果:




▌Refernece













Friday, August 21, 2015

[VS2015] 取消Cloud Test,以本機執行測試

 Visual Studio   Test  


▋Problem

相隔快兩年,再度使用Visual Studio做負載測試,版本已經從當時的VS2013 update1到目前的VS2015了,也改為以VSO  Cloud Test為主的測試架構。



不過很高興的註冊了VSO後進行測試,出現以下錯誤訊息:


心理OS : … 

好吧! 只好改回以本機為主的測試方式吧~

▋Change the default test-running environment

打開方案下:「Solution Items」→「Local.testsettings」
請選擇:使用本機電腦或測試控制器執行測試




另外如果要記錄負載測試結果,請先建立Load Test 資料庫:
開啟 「VS2015 開發人員命令提示字元」後輸入 :

cd Common7\IDE
SQLCMD /S [資料庫主機名稱] -U [User name] -P [Password] -i loadtestresultsrepository.sql

確定一下資料庫!






接著在已建好的負載測試內容中,開啟右上角的【管理Test Controller】





修改「負載測試結果存放區」, 將測試結果存在DB。


It’s back!  XD