public void TestCancelTimedEvent() { // events for cancel testing var e1 = new GameEvent { EventType = GameEventType.StatusEvent, From = this, To = _helper, Id = 42 }; var e2 = new GameEvent { EventType = GameEventType.MovementEvent, From = this, To = _helper, Id = 633 }; _eventBus.RegisterTimedEvent(e1, TimePeriod.NewMilliseconds(100)); _eventBus.RegisterTimedEvent(e2, TimePeriod.NewMilliseconds(2000)); // event which should stay in event bus for a very long time, // and not be disturbed by cancelling the other event multiple times. var longWaitEvent = new GameEvent { EventType = GameEventType.TimedEvent, From = this, To = _helper, Id = 316 }; _eventBus.RegisterTimedEvent(longWaitEvent, TimePeriod.NewSeconds(30.0)); // sleep 150ms. // This should timeout e1 but not e2 Thread.Sleep(150); // cancel e1 which was timed out and ready for processing _eventBus.CancelTimedEvent(e1.Id); // cancel e2 which is not timed out _eventBus.CancelTimedEvent(e2.Id); // check that both events were removed Assert.IsFalse(_eventBus.HasTimedEvent(e1.Id)); Assert.IsFalse(_eventBus.HasTimedEvent(e2.Id)); // now check that neither event will be processed _eventBus.ProcessEvents(); Assert.AreEqual(0, _helper.EventCounter); // test that cancelling did not disturb the other event Assert.IsTrue(_eventBus.HasTimedEvent(longWaitEvent.Id)); }