I would like to leverage Network Emulation to simulate various network speeds and packet loss rates from a Unit Test. I am trying to benchmark my network layer in combination with different packet loss rates. I have followed these instructions here, but am still having trouble getting it to work.
I have tried testing through loopback connection 127.0.0.1 as well as downloading a remote file from a unit test. In both cases network speed is not reduced.
This is using Visual Studio 2013 Premium
How can I get Network Emulation settigns to work with a unit test?
To get this to work:
An image file that took less than a second to download previously, now took almost a minute with the 56kbps emulation:
[TestMethod]
public void TestMethod1()
{
string page = "http://upload.wikimedia.org/wikipedia/commons/5/53/Wikipedia-logo-en-big.png";
// ... Use HttpClient.
using (HttpClient client = new HttpClient())
{
byte[] result = client.GetByteArrayAsync(page).Result;
Console.WriteLine("length" + result.Length);
}
}
The testsettings GUI provides only a few network profiles. If you open the testsettings file as a XML file in something like Notepad++, you can tweak the network settings and adjust packet loss/latency to test various scenarios.
You can't use 127.0.0.1 because it bypasses much of the networking layer for performance, including bypassing the emulator. Installing the Microsoft Loopback Adapter adds an interface with its own IP address to which the emulator driver can bind.
If you installed the Microsoft Loopback Adapter after going through the above procedure to bind the Network Emulation driver, then it only bound to the existing interfaces. To bind to newly installed interface , you must uninstall and reinstall the network emulation driver . From Start->Programs->Visual Studio Tools->Developer Command Prompt..., run the two commands:
VSTestConfig NETWORKEMULATION /uninstall
VSTestConfig NETWORKEMULATION /install
The second command should indicate the number of interfaces it binds to.
To determine the IP address for your loopback run ipconfig/all
from a command line, and look for the entry with Description "Microsoft Loopback Adapter". This IP address will be the one you need to code your client/server tests to use.
Ethernet adapter Local Area Connection 2:
...
Description . . . . . . . . . . . : Microsoft Loopback Adapter
...
Link-local IPv6 Address . . . . . : fe80::e0d2:c0f8:b3f8:2199%20(Preferred)
Autoconfiguration IPv4 Address. . : 169.254.33.153(Preferred)
Because the Network Emulation driver binds to all available interfaces, then while you are running a unit test, and the emulation kicks in, your internet connection will also be slowed down. You can uncheck/disable the Emulation Driver from other interfaces from the Network Connection Properties dialog. It will be listed as Microsoft VSTS Network Emulation NDIS6 Driver under the This connection uses the following items: (don't do this while a unit test is running, I got a blue screen and it corrupted the driver and had to manually reinstall again)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.