Fiddler simulates a weak network environment test

 Why do weak network environment test?

Due to the fluctuation of the user's own network environment, or the relatively bad network environment, some unexpected non-functional bugs will appear, which will affect the user's physical examination. for example

Use Fiddler, Charles and other network traffic analysis software with proxy server function to realize.

The principle of fiddler simulation speed limit

Fiddler speed limit is implemented in the form of network delay, network delay time * network speed = number of bytes transmitted.

Fiddler is originally a proxy. It provides a callback interface before the client requests and before the server responds. We can customize some logic in these interfaces. Fiddler's analog speed limit is the logic of custom speed limit before the client request. This logic is to limit the download speed and upload speed of the network by delaying the time of sending or receiving data, so as to achieve the effect of speed limit.

How to use Fiddler to simulate a harsh network environment?

1. Enable "Simulate Modem Speed" 

        Rules – Performances – Simulate Modem Speeds       

        It is unchecked by default, and the network is normal. After checking this option, all the traffic through the Fiddler proxy will become as slow as the Internet access when the 56k kitten was many years ago. 

        Note: Before and after the speed limit is turned on, cooperate with the speed test tool speedtest (speedtest.net abroad / speedtest.cn domestic), you can see that ping, download, and upload will be affected, as shown in the figure below:

Before the speed limit 

after the speed limit 

2. Configure speed limit parameters (network environment parameters)

        The environment simulated by the default configuration is too harsh and does not necessarily meet the requirements. In this case, the parameters of the speed limit need to be adjusted. 


        (法一)Rules – Customize Rules…  

        The CustomRules.js file will be opened with a text editor, which is located in the \Fiddler2\Scripts location under the document directory of the user directory by default, and the suffix name is js. Then, find a m_SimulateModem flag (as shown in the figure below), and set the request delay and corresponding delay in ms.

As above, it is the two parameters of oSession. The value in request-trickle-delay represents how many milliseconds 1KB of data will be delayed when uploaded; response-trickle-delay corresponds to how many milliseconds 1KB of data will be delayed when downloaded. For example, if you want to simulate a network with an upload speed of 500KBps, then the upload delay is 1KB/500KBps=0.002s=2ms, so change it to 2.

 (Method 2) Or, directly open the "FiddlerScript" tab of the right monitoring panel, as follows:

If the network speed is quite fast, the value set here can approximate the upload and download bandwidth after the simulation is turned on. For example, the default upload delay is 300ms and the download delay is 150ms. The approximate simulation bandwidth can be calculated as:

        → Upload bandwidth=(1 * 8/1000) /0.300 ≈ 0.027Mbps

        → Download bandwidth=(1 * 8/1000) /0.150 ≈ 0.053Mbps

        However, in reality, the bandwidth twice this value is obtained. It is speculated that there may be some differences between the internal implementation of Fiddler and the description. Why this phenomenon is not very clear, so the above formula needs to be corrected at the end. A coefficient of 2.0, that is:

        → Upload bandwidth=((1*8/1000)/0.300)*2.0≈0.053Mbps

         → Download bandwidth=((1*8/1000)/0.150)*2.0≈0.106Mbps

Popular Science 1: The unit used to measure bandwidth refers to the number of binary digits transmitted per second;

                Mbps is Milionbit pro second (million bits per second);

                Kbps is Kilobit pro second (thousand bits per second);

                bps is bit pro second (bits per second);

                1 Mbps =1000  Kbps =1000000 bps 

Popular Science 2: Usually, the speed displayed on the software refers to the number of bytes transmitted per second (Byte), which is usually represented by B (uppercase);

                MB means megabytes, also known as megabytes;

                KB means kilobytes;

                B is byte;

                The relationship between 1MB=1024KB=1024*1024B;

                1B=8b;

                →   So 1M bandwidth means 1Mbps=1000Kbps=1000/8KBps=125KBps;

3. Write custom scripts

        That is, to extend or add the logic in CustomRules.js. For example, to add a random delay, so that the network bandwidth is not constant at a low-speed value as in the previous step, but will jitter randomly within a certain range. As follows, change code segment 1 to code segment 1: 

Code snippet 1:

if (m_SimulateModem) {

// Delay sends by 300ms per KB uploaded.

oSession["request-trickle-delay"] = "500";

// Delay receives by 150ms per KB downloaded.

oSession["response-trickle-delay"] = "500";

}

Code snippet 2:

static function randInt(min, max) {

return Math.round(Math.random()*(max-min)+min);

}

if (m_SimulateModem) {

// Delay sends by 300ms per KB uploaded.

oSession["request-trickle-delay"] = ""+randInt(1,500);

// Delay receives by 150ms per KB downloaded.

oSession["response-trickle-delay"] = ""+randInt(1,500);

}

PS: After modification, save the configuration file (Ctrl+S) or clear the cache (Rules –> Performances –>Disable Caching), and check Rules –> Performances –> Simulate Modem Speeds again for speed measurement. Note: After editing and saving the configuration file each time, the Simulate Modem Speeds option will be canceled, please check it again.

Problems encountered: After the above revision, the Rules –> Performances menu may disappear, just roll back or restart.

Limitations of Fiddler simulating harsh network environments

Using Fiddler to simulate a harsh network environment is simple and intuitive. The disadvantage is that it can only support services that use HTTP for communication and interaction, and does not support applications of other protocols.

Finally, I would like to thank everyone who has read my article carefully. Reciprocity is always necessary. Although it is not a very valuable thing, you can take it away if you need it:

These materials should be the most comprehensive and complete preparation warehouse for [software testing] friends. This warehouse has also accompanied tens of thousands of test engineers through the most difficult journey, and I hope it can help you! Partners can click the small card below to receive 

Guess you like

Origin blog.csdn.net/kk_lzvvkpj/article/details/130566760