PC Review


Reply
Thread Tools Rate Thread

Simulating network connection failure via C#

 
 
Phil Haack
Guest
Posts: n/a
 
      2nd Feb 2004
Hello all,

Does anyone have a creative quick way to simulate the loss of network
connectivity via C#? I am trying to write a Unit Test of a long
running network operation (initiated by a 3rd party component) and
would like to ensure that the component and my containing code handles
the loss of network connectivity appropriately. Thanks!
 
Reply With Quote
 
 
 
 
DalePres
Guest
Posts: n/a
 
      3rd Feb 2004
public class WireCutter
{
Wire wire;
public WireCutter(Wire wire)
{
this.wire = wire;
}

public NetworkCrash CutWire(wire)
{
cut wire;
}
}

Dale

"Phil Haack" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello all,
>
> Does anyone have a creative quick way to simulate the loss of network
> connectivity via C#? I am trying to write a Unit Test of a long
> running network operation (initiated by a 3rd party component) and
> would like to ensure that the component and my containing code handles
> the loss of network connectivity appropriately. Thanks!



 
Reply With Quote
 
Chad Z. Hower aka Kudzu
Guest
Posts: n/a
 
      3rd Feb 2004
(E-Mail Removed) (Phil Haack) wrote in
news:(E-Mail Removed):
> Does anyone have a creative quick way to simulate the loss of network
> connectivity via C#? I am trying to write a Unit Test of a long
> running network operation (initiated by a 3rd party component) and
> would like to ensure that the component and my containing code handles
> the loss of network connectivity appropriately. Thanks!


Pull the network cable.


--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"


ELKNews - Get your free copy at http://www.atozedsoftware.com

 
Reply With Quote
 
Phil Haack
Guest
Posts: n/a
 
      4th Feb 2004
ha ha! Thanks for the suggestions. Maybe I didn't make myself clear.
I am attempting to write this as an AUTOMATED unit test that can run
nightly on our build server. I'd hate to have to come in every night
to pull the network plug as part of our scheduled process .


"Chad Z. Hower aka Kudzu" <(E-Mail Removed)> wrote in message news:<Xns9484B938481CEcpub@127.0.0.1>...
> (E-Mail Removed) (Phil Haack) wrote in
> news:(E-Mail Removed):
> > Does anyone have a creative quick way to simulate the loss of network
> > connectivity via C#? I am trying to write a Unit Test of a long
> > running network operation (initiated by a 3rd party component) and
> > would like to ensure that the component and my containing code handles
> > the loss of network connectivity appropriately. Thanks!

>
> Pull the network cable.

 
Reply With Quote
 
Chad Z. Hower aka Kudzu
Guest
Posts: n/a
 
      4th Feb 2004
(E-Mail Removed) (Phil Haack) wrote in
news:(E-Mail Removed):
> ha ha! Thanks for the suggestions. Maybe I didn't make myself clear.
> I am attempting to write this as an AUTOMATED unit test that can run


You can get Lego mindstorms and hook it to your serial port to disconnect it
each night.

> nightly on our build server. I'd hate to have to come in every night
> to pull the network plug as part of our scheduled process .


You can run through a mapped port, and simply introduce the errors there by
forcibly closing the connection.

Indy has mapped port components you could implement it with if you dont want
to build them from scratch. Its also free.
http://www.indyproject.org/indy.html



--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"


ELKNews - Get your free copy at http://www.atozedsoftware.com

 
Reply With Quote
 
Nick Malik
Guest
Posts: n/a
 
      5th Feb 2004
you've got some interesting responses there Phil.

I would insert a testing proxy component in the unit test module (Nunit or
CSunit?).

In other words, you have an interface for this long-running network
component. While standing in front of the machine, actually pull the
network cable to see what error is generated, and it what part of the
interface. Then, hide that part of the interface under a proxy method that
simply passes through or does nothing (in production). For the unit test,
pass in an object that will allow that method to run for a predetermined
clock time and then return the error you detected. See if your application
handles it well.

Testing the server is a bit harder, because it won't know that the client is
performing a unit test. All it will know is that your client has stopped
communicating. However, that is typical of network outage errors, so you
should get the behavior you expect. Caveat: unit test scenarios are often
not good for this kind of testing, because the very next test may need to
re-establish the connection, which may affect how the server behaves.

Good Luck,
--- Nick

"Phil Haack" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello all,
>
> Does anyone have a creative quick way to simulate the loss of network
> connectivity via C#? I am trying to write a Unit Test of a long
> running network operation (initiated by a 3rd party component) and
> would like to ensure that the component and my containing code handles
> the loss of network connectivity appropriately. Thanks!



 
Reply With Quote
 
DalePres
Guest
Posts: n/a
 
      6th Feb 2004
Something that just occurred to me that WMI might be the answer.
Win32_NetworkAdapterConfiguration has the ability to set the static IP
address to something outside your network address range, thereby effectively
breaking the network.

There does not seem to be any classes that would allow you to specifically
disable the network adapter.

Search Win32_NetworkAdapterConfiguration on MSDN and you should be on your
way. You might want to hit the WMI newsgroup as well.

Dale


"Nick Malik" <(E-Mail Removed)> wrote in message
news:lCtUb.179153$Rc4.1334353@attbi_s54...
> you've got some interesting responses there Phil.
>
> I would insert a testing proxy component in the unit test module (Nunit or
> CSunit?).
>
> In other words, you have an interface for this long-running network
> component. While standing in front of the machine, actually pull the
> network cable to see what error is generated, and it what part of the
> interface. Then, hide that part of the interface under a proxy method

that
> simply passes through or does nothing (in production). For the unit test,
> pass in an object that will allow that method to run for a predetermined
> clock time and then return the error you detected. See if your

application
> handles it well.
>
> Testing the server is a bit harder, because it won't know that the client

is
> performing a unit test. All it will know is that your client has stopped
> communicating. However, that is typical of network outage errors, so you
> should get the behavior you expect. Caveat: unit test scenarios are often
> not good for this kind of testing, because the very next test may need to
> re-establish the connection, which may affect how the server behaves.
>
> Good Luck,
> --- Nick
>
> "Phil Haack" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Hello all,
> >
> > Does anyone have a creative quick way to simulate the loss of network
> > connectivity via C#? I am trying to write a Unit Test of a long
> > running network operation (initiated by a 3rd party component) and
> > would like to ensure that the component and my containing code handles
> > the loss of network connectivity appropriately. Thanks!

>
>



 
Reply With Quote
 
Kai Bohli
Guest
Posts: n/a
 
      6th Feb 2004
Hi Chad !

I've been using Indy for Delphi for years ! Oh boy - I didn't know that you made an C# version. I'm
really happe for that since I've just started with C# (Visual Studio).

>Indy has mapped port components you could implement it with if you dont want
>to build them from scratch. Its also free.
>http://www.indyproject.org/indy.html


Best wishes
Kai Bohli
(E-Mail Removed)
Norway
 
Reply With Quote
 
Chad Z. Hower aka Kudzu
Guest
Posts: n/a
 
      6th Feb 2004
Kai Bohli <(E-Mail Removed)> wrote in
news:(E-Mail Removed):
> I've been using Indy for Delphi for years ! Oh boy - I didn't know that


Great

> you made an C# version. I'm really happe for that since I've just
> started with C# (Visual Studio).


Yep. Its there:
http://www.indyproject.org/indy.html

Take a look, there are a few VB and C# samples online.


--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"


ELKNews - Get your free copy at http://www.atozedsoftware.com

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Network connection failure Rob Windows Vista General Discussion 2 24th Aug 2009 12:58 AM
Network Connection Failure Marina Windows XP General 0 13th Jul 2008 08:34 PM
network connection failure =?Utf-8?B?TWljaGFlbCBMaW5kZWt1Z2Vs?= Windows XP General 3 14th Jul 2006 06:18 PM
Failure using PRO/100 VE Network Connection Kapusta Windows XP Networking 0 15th Jan 2005 09:08 PM
Network Connection Failure on Updates Lawrie Windows XP Security 1 15th Aug 2003 11:30 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:42 PM.