Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I properly simulate high latency on a C# socket server test?

I have a class that uses 'System.Net.Sockets.Socket' directly for network comunication, and currently I use the following two interfaces to break dependency on the Socket class :

public interface ISocketListener
    {
        void Listen(int backlog);

        ISocket Accept();

        void Bind(EndPoint endpoint);               
    }

public interface ISocket
    {
        void Connect (EndPoint ep);

        Stream CommunicationStream { get; }

        void Close();

        void Close(int timeout);

        void Shutdown();
    }

In the production implementation I just redirect all the method calls to the private Socket object. In testing environment I use a MemoryStream as the comunication 'pipe' between the sockets. Since I have little experience in the subject, some questions appeared in my head while writing tests : Are there any 'formal' good practices in testing this kind of software? When doing integration testing, how do I test the performance of this server in multiple connections/high latency situations (more specifically, how to simulate these situations)? Why there are asynchronous versions of Socket.Accept/Socket.Receive? Can I replace the asynchronous methods for handling their synchronous versions in separate threads?

like image 684
Thiago Padilha Avatar asked Nov 05 '22 11:11

Thiago Padilha


1 Answers

You could simulate high latency by creating a proxy server to sit inbetween your connection, then you can just add a delay when re-sending the data.

like image 96
Chris Almond Avatar answered Nov 12 '22 14:11

Chris Almond