c# - Unit testing - how to emulate a delay -


we've got large c# solution multiple apis, svcs , on. usual sort of enterprisy mess after same code has been worked on years multiple people.

anyway! have ability call external service , have unit tests in place use moq stub implementation of services interface.

it happens there can large delay in calling external service , it's not can control (it's gds interface).

we've been working on way streamline user experience part of our platform.

the problem is, stub doesn't @ - , of course, lightening fast, compared real thing.

we want introduce random delay 1 of stubbed methods, cause call take between 10 , 20 seconds complete.

the naive approach do:

int sleeptimer = random.next(10, 20); thread.sleep(sleeptimer * 1000); 

but gives me bad feeling. other ways people have of solving kind of scenario, or thread.sleep ok use in context ?

thanks time!

-russ

edit, answer of comments:

basically, don't want call live external service our test suite, because costs money , other business problems.

however, want test our new processes work well, when there's variable delay in essential call external service.

i love explain exact process, i'm not allowed to.

but yeah, summary our test needs ensure long running call external service doesn't obstruct rest of flow; , need ensure other tasks don't kind of race conditions, depend on result of call.

i agree calling unit-test incorrect now!


Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -