Ejemplo n.º 1
0
 public void Async_Result_WhenDone_does_not_get_executed_task_state()
 {
     var state = new TaskLifeSpanState("baz");
     var allgood = false;
     var resetEvent = new ManualResetEvent(false);
     AsyncUtil.Fork(() => {
         _log.Debug("setting inner state");
         TaskEnv.Current.SetState("foo", state);
     }, new Result()).WhenDone(r => {
         _log.Debug("executing whendone");
         allgood = !r.HasException && state != TaskEnv.Current.GetState<TaskLifeSpanState>("foo");
         resetEvent.Set();
     });
     _log.Debug("waiting for fork");
     resetEvent.WaitOne();
     _log.Debug("done");
     Assert.IsTrue(allgood);
 }
Ejemplo n.º 2
0
 public void WhenDone_triggers_state_disposal()
 {
     var state = new TaskLifeSpanState("baz");
     Assert.IsFalse(state.IsDisposed);
     TaskEnv.Current.SetState(state);
     var resetEvent = new ManualResetEvent(false);
     var result = new Result(TaskEnv.Current);
     _log.Debug("setting up whendone");
     result.WhenDone(r => {
         _log.Debug("whendone called");
         resetEvent.Set();
     });
     result.Return();
     resetEvent.WaitOne();
     Assert.IsTrue(Wait.For(() => state.IsDisposed, TimeSpan.FromSeconds(10)));
 }
Ejemplo n.º 3
0
 public void Result_with_current_state_should_get_original_state_on_whendone_with_return_before_whendone()
 {
     var state = new TaskLifeSpanState("baz");
     TaskEnv.Current.SetState(state);
     var allgood = false;
     var resetEvent = new ManualResetEvent(false);
     var r = new Result(TaskEnv.Current);
     r.Return();
     r.WhenDone(r2 => {
         allgood = !r2.HasException && state == TaskEnv.Current.GetState<TaskLifeSpanState>();
         resetEvent.Set();
     });
     resetEvent.WaitOne();
     Assert.IsTrue(allgood);
 }
Ejemplo n.º 4
0
 public void ITaskCloneable_is_not_cloned_on_task_current_instantiation()
 {
     var state = new TaskLifeSpanState("baz");
     TaskEnv.Current.SetState("foo", state);
     bool? hasState = null;
     TaskEnv.Current.Acquire();
     TaskEnv.Current.InvokeNow(() => {
         hasState = state == TaskEnv.Current.GetState<TaskLifeSpanState>("foo");
     });
     Assert.IsTrue(hasState.HasValue);
     Assert.IsTrue(hasState.Value);
 }
Ejemplo n.º 5
0
 public void ITaskCloneable_is_cloned_on_task_copy()
 {
     var state = new TaskLifeSpanState("baz");
     TaskEnv.Current.SetState("foo", state);
     bool? hasState = null;
     bool stateExists = false;
     var env = TaskEnv.Clone();
     env.Acquire();
     env.InvokeNow(() => {
         stateExists = TaskEnv.Current.ContainsKey("foo");
         hasState = state == TaskEnv.Current.GetState<TaskLifeSpanState>("foo");
     });
     Assert.IsTrue(hasState.HasValue);
     Assert.IsFalse(hasState.Value);
 }
Ejemplo n.º 6
0
 public void Invokenow_does_not_release()
 {
     var state = new TaskLifeSpanState("baz");
     TaskEnv.Current.SetState(state);
     Assert.IsFalse(state.IsDisposed);
     TaskEnv.Current.Acquire();
     Assert.IsFalse(state.IsDisposed);
     TaskEnv.Current.InvokeNow(() => _log.Debug("invoke now"));
     Assert.IsFalse(state.IsDisposed);
     TaskEnv.Current.Release();
     Assert.IsTrue(state.IsDisposed);
 }
Ejemplo n.º 7
0
 public void Each_invokeNoArg_counteracts_one_acquire()
 {
     var state = new TaskLifeSpanState("baz");
     TaskEnv.Current.SetState(state);
     Assert.IsFalse(state.IsDisposed);
     TaskEnv.Current.Acquire();
     TaskEnv.Current.Acquire();
     Assert.IsFalse(state.IsDisposed);
     var resetEvent = new ManualResetEvent(false);
     TaskEnv.Current.Invoke(() => resetEvent.Set());
     resetEvent.WaitOne();
     resetEvent.Reset();
     // Note (arnec): got a race condition since the set happens before the release
     Thread.Sleep(100);
     Assert.IsFalse(state.IsDisposed);
     TaskEnv.Current.Invoke(() => resetEvent.Set());
     resetEvent.WaitOne();
     resetEvent.Reset();
     Thread.Sleep(100);
     Assert.IsTrue(state.IsDisposed);
 }