public void ChildWaiter_Waited_Wait_BlockThreadUntilChildrenAreResolved() { this.WithinTimeout(() => { //arrange ChildWaiter sut = CreateChildWaiter(); sut.Start(this, 0); sut.Wait(); int expectedChildrenCount = TestUtils.RandomBetween(1, 5); int resolvedChildrenCount = 0; sut.Start(this, expectedChildrenCount); Task.Run(() => { this.Sleep(50); Parallel.For(0, expectedChildrenCount, i => { resolvedChildrenCount++; sut.ResolvedChild(); }); }); //act sut.Wait(); //assert resolvedChildrenCount.Should().Be(expectedChildrenCount); }); }
public void ChildWaiter_Started_Start_ShouldUnblockThreadWhenFirstStartsChildrenAreResolved() { this.WithinTimeout(() => { //arrange ChildWaiter sut = CreateChildWaiter(); int expectedChildrenCount = TestUtils.RandomBetween(0, 5); bool isSecondStartRan = false; sut.Start(this, expectedChildrenCount); Task.Run(() => { //act sut.Start(this, TestUtils.RandomBetween(0, 5)); isSecondStartRan = true; }); this.Sleep(50); //ensures second start is called before continuing //assert Task.Run(() => { Parallel.For(0, expectedChildrenCount, i => { sut.ResolvedChild(); }); }); sut.Wait(); AwaitAssert(() => isSecondStartRan.Should().BeTrue()); }); }
public void ChildWaiter_Started_Start_ShouldBlockThread() { this.WithinTimeout(() => { //arrange ChildWaiter sut = CreateChildWaiter(); bool isSecondStartRan = false; sut.Start(this, TestUtils.RandomBetween(0, 5)); Task.Run(() => { //act sut.Start(this, TestUtils.RandomBetween(0, 5)); isSecondStartRan = true; }); //assert this.Sleep(this.GetTimeoutHalved()); isSecondStartRan.Should().BeFalse(); }); }
public void ChildWaiter_StartedWithNegativeExpectedChildren_Wait_DoesNotBlockThread() { //arrange ChildWaiter sut = CreateChildWaiter(); sut.Start(this, TestUtils.RandomBetween(int.MinValue, -1)); //act Action act = () => sut.Wait(); //assert this.WithinTimeout(act); }
public void ChildWaiter_StartedWithNoExpectedChildren_Wait_DoesNotBlockThread() { //arrange ChildWaiter sut = CreateChildWaiter(); sut.Start(this, 0); //act Action act = () => sut.Wait(); //assert this.WithinTimeout(act); }
public void ChildWaiter_Started_ResolveChild_DoesNotThrowAnyExceptions() { //arrange ChildWaiter sut = CreateChildWaiter(); sut.Start(this, TestUtils.Create <int>()); //act Action act = () => sut.ResolvedChild(); //assert act.ShouldNotThrow(); }
public void ChildWaiter_StartedWithNoExpectedChildren_Wait_DoesNotBlockThread() { //arrange ChildWaiter sut = CreateChildWaiter(); sut.Start(this, 0); //act Action act = () => sut.Wait(); //assert Within(TestKitSettings.DefaultTimeout, act); }
public void ChildWaiter_Started_Start_ShouldBlockThread() { Within(TimeSpan.FromSeconds(2), () => { //arrange ChildWaiter sut = CreateChildWaiter(); int expectedChildrenCount = TestUtils.RandomBetween(0, 5); bool isSecondStartRan = false; sut.Start(this, expectedChildrenCount); Task.Run(() => { //act sut.Start(this, TestUtils.RandomBetween(0, 5)); isSecondStartRan = true; }); //assert this.Sleep(TestKitSettings.DefaultTimeout); isSecondStartRan.Should().BeFalse(); }); }
public void ChildWaiter_Start_DoesNotThrowAnyExceptions() { this.WithinTimeout(() => { //arrange ChildWaiter sut = CreateChildWaiter(); //act Action act = () => sut.Start(this, TestUtils.Create <int>()); //assert act.ShouldNotThrow(); }); }
public void ChildWaiter_StartWithNullTestKitBase_ThrowsArgumentNullException() { this.WithinTimeout(() => { //arrange ChildWaiter sut = CreateChildWaiter(); //act Action act = () => sut.Start(null, TestUtils.Create <int>()); //assert act.ShouldThrow <ArgumentNullException>(); }); }
public void ChildWaiter_Start_DoesNotThrowAnyExceptions() { Within(TimeSpan.FromSeconds(2), () => { //arrange ChildWaiter sut = CreateChildWaiter(); //act Action act = () => sut.Start(this, TestUtils.Create <int>()); //assert act.ShouldNotThrow(); }); }
public void ChildWaiter_Started_Wait_ThrowsTimeoutExceptionWhenNotAllChildrenAreResolved() { this.WithinTimeout(() => { //arrange ChildWaiter sut = CreateChildWaiter(); int expectedChildrenCount = TestUtils.RandomBetween(2, 5); sut.Start(this, expectedChildrenCount); Task.Run(() => { this.Sleep(50); Parallel.For(0, expectedChildrenCount - 1, i => sut.ResolvedChild()); }); //act Action act = () => sut.Wait(); //assert act.ShouldThrow <TimeoutException>(); }); }
public void ChildWaiter_Started_Wait_ThrowsTimeoutExceptionWhenChildrenAreNotResolved() { Within(TimeSpan.FromSeconds(2), () => { //arrange ChildWaiter sut = CreateChildWaiter(); int expectedChildrenCount = TestUtils.RandomBetween(2, 5); sut.Start(this, expectedChildrenCount); Task.Run(() => { this.Sleep(new TimeSpan(TestKitSettings.DefaultTimeout.Ticks / 2)); Parallel.For(0, expectedChildrenCount - 1, i => sut.ResolvedChild()); }); //act Action act = () => sut.Wait(); //assert act.ShouldThrow <TimeoutException>(); }); }