system.reactive - Testing Reactive Extensions - How do I use the test scheduler with ToTask()? -
I'm having trouble testing the responsive code that uses a work-based service. I use the work and use ToObservable to do reactive-y things with it.
Public Zero Method () {_svc.MyTaskServiceMethod (). ToObservable () ...) // do it pipe elsewhere and interesting things} Now I'm testing some time (using Moq for service) in a unit test
svcMock.Setup (x => MyTaskServiceMethod ()). Returns ((= =); Observable.Return ("VALUE", test scheduler) .Delay (timespainfamily milliseconds (100), test stabilizer) .totask ()); The problem is that despite using the test scheduler in the return / delay call, this task is still completing on different threads by writing some of the existing managed thread IDs of the code. Seeing by adding.
svcMock.Setup (x = & gt; x.MyServiceMethod ()). Returns ((=) => {var Task = Overview. Return ("VALUE", Test Scheduler) .Delay (Timespane) .FromMilliseconds (1000), testScheduler). (X = & gt; {Console.WriteLine (Thread.CurrentThread.ManagedThreadId.ToString () + "Obs");}) .to Task (); Work (with structure) ((_) => {Console.WriteLine (Thread.CurrentThread.ManagedThreadId.ToString () + "Task");}); Return work;}); Dro (..) executes on the primary test thread, and in fact this happens when I expect a testSchduler.AdvanceBy (..) call.
The work continuity is still happening in a different thread and is not basically executed until the body of the unit is tested. So in my body of aim, nothing really never gets pushed through my work. Observeable () illustrated
Task continuity will default to using a work pool thread, so your constant testing from the scheduler's control Is saved. If you specify the option TaskContinuationOptions.ExecuteSynchronously , it will use the same thread and the results will be seen as desired:
task.ContinueWith (( _) = & Gt; {Console.WriteLine (Thread.content.managementTrade Ed toString () + "Task");}, Task Continuation Option. Exits synchronous); Appendix
You can brighten the topic of concurrency in TPL-> Rx infections and especially in toobasewave () .
Comments
Post a Comment