public void IdleTime() { ManualClock clock = new ManualClock(); clock.Start(); VariableStepTimer timer = new VariableStepTimer(clock); timer.Idle += timer_Idle; timer.TimeChanged += timer_TimeChanged; timer.MinDeltaTime = TimeSpan.FromMilliseconds(20); timer.Start(); clock.Update(TimeSpan.FromMilliseconds(20)); CheckNoIdleEvent(); CheckTimeChangedEvent(TimeSpan.FromMilliseconds(20), TimeSpan.FromMilliseconds(20)); Assert.AreEqual(TimeSpan.Zero, timer.IdleTime); clock.Update(TimeSpan.FromMilliseconds(20)); CheckNoIdleEvent(); CheckTimeChangedEvent(TimeSpan.FromMilliseconds(40), TimeSpan.FromMilliseconds(20)); Assert.AreEqual(TimeSpan.Zero, timer.IdleTime); clock.Update(TimeSpan.FromMilliseconds(15)); CheckIdleEvent(TimeSpan.FromMilliseconds(20 - 15)); CheckNoTimeChangedEvent(); Assert.AreEqual(TimeSpan.FromMilliseconds(20 - 15), timer.IdleTime); clock.Update(TimeSpan.FromMilliseconds(2)); CheckIdleEvent(TimeSpan.FromMilliseconds(20 - (15 + 2))); CheckNoTimeChangedEvent(); Assert.AreEqual(TimeSpan.FromMilliseconds(20 - (15 + 2)), timer.IdleTime); }
public void LostTime() { ManualClock clock = new ManualClock(); clock.Start(); VariableStepTimer timer = new VariableStepTimer(clock); timer.TimeChanged += timer_TimeChanged; timer.MaxDeltaTime = TimeSpan.FromMilliseconds(50); timer.Start(); clock.Update(TimeSpan.FromMilliseconds(20)); CheckTimeChangedEvent(TimeSpan.FromMilliseconds(20), TimeSpan.FromMilliseconds(20)); Assert.AreEqual(TimeSpan.Zero, timer.LostTime); clock.Update(TimeSpan.FromMilliseconds(20)); CheckTimeChangedEvent(TimeSpan.FromMilliseconds(40), TimeSpan.FromMilliseconds(20)); Assert.AreEqual(TimeSpan.Zero, timer.LostTime); clock.Update(TimeSpan.FromMilliseconds(50)); CheckTimeChangedEvent(TimeSpan.FromMilliseconds(90), TimeSpan.FromMilliseconds(50)); Assert.AreEqual(TimeSpan.Zero, timer.LostTime); clock.Update(TimeSpan.FromMilliseconds(70)); CheckTimeChangedEvent(TimeSpan.FromMilliseconds(140), TimeSpan.FromMilliseconds(50)); Assert.AreEqual(TimeSpan.FromMilliseconds(70 - 50), timer.LostTime); clock.Update(TimeSpan.FromMilliseconds(80)); CheckTimeChangedEvent(TimeSpan.FromMilliseconds(190), TimeSpan.FromMilliseconds(50)); Assert.AreEqual(TimeSpan.FromMilliseconds(80 - 50), timer.LostTime); clock.Update(TimeSpan.FromMilliseconds(20)); CheckTimeChangedEvent(TimeSpan.FromMilliseconds(210), TimeSpan.FromMilliseconds(20)); Assert.AreEqual(TimeSpan.Zero, timer.LostTime); }
public void InitialValues() { var clock = new ManualClock(); Assert.IsFalse(clock.IsRunning); Assert.AreEqual(TimeSpan.Zero, clock.DeltaTime); Assert.AreEqual(TimeSpan.Zero, clock.GameTime); Assert.AreEqual(TimeSpan.Zero, clock.TotalTime); }
public void IsRunning() { var clock = new ManualClock(); Assert.IsFalse(clock.IsRunning); clock.Start(); Assert.IsTrue(clock.IsRunning); clock.Start(); Assert.IsTrue(clock.IsRunning); clock.Stop(); Assert.IsFalse(clock.IsRunning); clock.Start(); Assert.IsTrue(clock.IsRunning); clock.Stop(); clock.Stop(); Assert.IsFalse(clock.IsRunning); }
public void StartStop() { var clock = new ManualClock(); var step = new TimeSpan(100000); clock.Update(step); Assert.IsFalse(clock.IsRunning); Assert.AreEqual(TimeSpan.Zero, clock.DeltaTime); Assert.AreEqual(TimeSpan.Zero, clock.GameTime); Assert.AreEqual(TimeSpan.Zero, clock.TotalTime); clock.Start(); Assert.IsTrue(clock.IsRunning); Assert.AreEqual(TimeSpan.Zero, clock.DeltaTime); Assert.AreEqual(TimeSpan.Zero, clock.GameTime); Assert.AreEqual(TimeSpan.Zero, clock.TotalTime); clock.Update(step); Assert.IsTrue(clock.IsRunning); Assert.AreEqual(step.Ticks, clock.DeltaTime.Ticks); Assert.AreEqual(1 * step.Ticks, clock.GameTime.Ticks); Assert.AreEqual(1 * step.Ticks, clock.TotalTime.Ticks); clock.Stop(); clock.Update(step); Assert.IsFalse(clock.IsRunning); Assert.AreEqual(step.Ticks, clock.DeltaTime.Ticks); Assert.AreEqual(1 * step.Ticks, clock.GameTime.Ticks); Assert.AreEqual(1 * step.Ticks, clock.TotalTime.Ticks); clock.Start(); clock.Update(step); clock.Update(step); clock.Update(new TimeSpan(step.Ticks * 2)); Assert.IsTrue(clock.IsRunning); Assert.AreEqual(2 * step.Ticks, clock.DeltaTime.Ticks); Assert.AreEqual(5 * step.Ticks, clock.GameTime.Ticks); Assert.AreEqual(5 * step.Ticks, clock.TotalTime.Ticks); }
public void AccumulatedStepsAndPendingSteps() { ManualClock clock = new ManualClock(); clock.Start(); FixedStepTimer timer = new FixedStepTimer(clock) { StepSize = TimeSpan.FromMilliseconds(10), MaxNumberOfSteps = 5, }; timer.Idle += timer_Idle; timer.TimeChanged += timer_TimeChanged; timer.Start(); timer.AccumulateTimeSteps = true; int desiredPendingSteps = 0; int desiredAccumlatedSteps = 2; timer.TimeChanged += (s, e) => { Assert.AreEqual(desiredPendingSteps, timer.PendingSteps); Assert.AreEqual(desiredAccumlatedSteps, timer.AccumulatedSteps); desiredPendingSteps--; }; clock.Update(TimeSpan.FromMilliseconds(22)); timer.Reset(); timer.Start(); timer.AccumulateTimeSteps = false; desiredPendingSteps = 3; desiredAccumlatedSteps = 1; clock.Update(TimeSpan.FromMilliseconds(42)); Assert.AreEqual(-1, desiredPendingSteps); }
public void Reset() { var clock = new ManualClock(); clock.Start(); clock.Update(new TimeSpan(100000)); clock.Reset(); Assert.IsFalse(clock.IsRunning); Assert.AreEqual(TimeSpan.Zero, clock.DeltaTime); Assert.AreEqual(TimeSpan.Zero, clock.GameTime); Assert.AreEqual(TimeSpan.Zero, clock.TotalTime); clock.Start(); clock.Update(new TimeSpan(100000)); clock.Stop(); clock.Reset(); Assert.IsFalse(clock.IsRunning); Assert.AreEqual(TimeSpan.Zero, clock.DeltaTime); Assert.AreEqual(TimeSpan.Zero, clock.GameTime); Assert.AreEqual(TimeSpan.Zero, clock.TotalTime); }
public void AccumlateTimeSteps() { int handleTimeStepCallCount = 0; ManualClock clock = new ManualClock(); clock.Start(); var timeIncrement = new TimeSpan(166666); FixedStepTimer timer = new FixedStepTimer(clock) { StepSize = timeIncrement, MaxNumberOfSteps = 8, }; timer.TimeChanged += (obj, timeEventArgs) => { Assert.AreEqual(timeIncrement, timeEventArgs.DeltaTime); handleTimeStepCallCount++; }; Assert.AreEqual(true, timer.AccumulateTimeSteps); timer.AccumulateTimeSteps = false; Assert.AreEqual(false, timer.AccumulateTimeSteps); timer.Start(); handleTimeStepCallCount = 0; clock.Update(new TimeSpan(timeIncrement.Ticks * 6)); Assert.AreEqual(6, handleTimeStepCallCount); handleTimeStepCallCount = 0; clock.Update(timeIncrement); Assert.AreEqual(1, handleTimeStepCallCount); handleTimeStepCallCount = 0; clock.Update(new TimeSpan(timeIncrement.Ticks / 2)); Assert.AreEqual(0, handleTimeStepCallCount); clock.Update(new TimeSpan(timeIncrement.Ticks / 2)); Assert.AreEqual(1, handleTimeStepCallCount); }
private void load(TournamentStorage storage) { var stream = storage.GetStream($@"videos/{filename}"); if (stream != null) { InternalChild = video = new VideoSprite(stream, false) { RelativeSizeAxes = Axes.Both, FillMode = FillMode.Fit, Clock = new FramedClock(manualClock = new ManualClock()), Loop = loop, }; } else if (drawFallbackGradient) { InternalChild = new Box { Colour = ColourInfo.GradientVertical(OsuColour.Gray(0.3f), OsuColour.Gray(0.6f)), RelativeSizeAxes = Axes.Both, }; } }
public void TestCustomTransformsClearedBetweenReuses() { ManualClock clock = null; createTest(new Beatmap { HitObjects = { new HitObject(), new HitObject { StartTime = 2000 } } }, 1, () => new FramedClock(clock = new ManualClock())); DrawableTestHitObject firstObject = null; Vector2 position = default; AddUntilStep("first object shown", () => this.ChildrenOfType <DrawableTestHitObject>().SingleOrDefault()?.HitObject == drawableRuleset.Beatmap.HitObjects[0]); AddStep("get DHO", () => firstObject = this.ChildrenOfType <DrawableTestHitObject>().Single()); AddStep("store position", () => position = firstObject.Position); AddStep("add custom transform", () => firstObject.ApplyCustomUpdateState += onStateUpdate); AddStep("fast forward past first object", () => clock.CurrentTime = 1500); AddStep("unapply custom transform", () => firstObject.ApplyCustomUpdateState -= onStateUpdate); AddStep("fast forward to second object", () => clock.CurrentTime = drawableRuleset.Beatmap.HitObjects[1].StartTime); AddUntilStep("second object shown", () => this.ChildrenOfType <DrawableTestHitObject>().SingleOrDefault()?.HitObject == drawableRuleset.Beatmap.HitObjects[1]); AddAssert("DHO reused", () => this.ChildrenOfType <DrawableTestHitObject>().Single() == firstObject); AddAssert("object in new position", () => firstObject.Position != position); void onStateUpdate(DrawableHitObject hitObject, ArmedState state) { using (hitObject.BeginAbsoluteSequence(hitObject.StateUpdateTime)) hitObject.MoveToOffset(new Vector2(-100, 0)); } }
public TestDrawableCatchHitObjectSpecimen(DrawableCatchHitObject d) { AutoSizeAxes = Axes.Both; Anchor = Anchor.Centre; Origin = Anchor.Centre; ManualClock = new ManualClock(); Clock = new FramedClock(ManualClock); var hitObject = d.HitObject; hitObject.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty()); hitObject.Scale = 1.5f; hitObject.StartTime = 500; d.Anchor = Anchor.Centre; d.HitObjectApplied += _ => { d.LifetimeStart = double.NegativeInfinity; d.LifetimeEnd = double.PositiveInfinity; }; InternalChild = d; }
public void LostTime() { ManualClock clock = new ManualClock(); clock.Start(); FixedStepTimer timer = new FixedStepTimer(clock) { StepSize = TimeSpan.FromMilliseconds(10), MaxNumberOfSteps = 5, }; timer.Idle += timer_Idle; timer.TimeChanged += timer_TimeChanged; timer.Start(); clock.Update(TimeSpan.FromMilliseconds(10)); CheckNoIdleEvent(); CheckTimeChangedEvent(TimeSpan.FromMilliseconds(10), TimeSpan.FromMilliseconds(10)); Assert.AreEqual(TimeSpan.Zero, timer.LostTime); clock.Update(TimeSpan.FromMilliseconds(50)); CheckNoIdleEvent(); CheckTimeChangedEvent(TimeSpan.FromMilliseconds(60), TimeSpan.FromMilliseconds(50)); Assert.AreEqual(TimeSpan.Zero, timer.LostTime); clock.Update(TimeSpan.FromMilliseconds(51)); CheckNoIdleEvent(); CheckTimeChangedEvent(TimeSpan.FromMilliseconds(110), TimeSpan.FromMilliseconds(50)); Assert.AreEqual(TimeSpan.FromMilliseconds(1), timer.LostTime); clock.Update(TimeSpan.FromMilliseconds(49)); CheckNoIdleEvent(); CheckTimeChangedEvent(TimeSpan.FromMilliseconds(150), TimeSpan.FromMilliseconds(40)); Assert.AreEqual(TimeSpan.Zero, timer.LostTime); }
public void TestDrawablePreparedWhenClockRewound() { resetWithNewPool(() => new TestPool(TimePerAction, 1)); TestDrawable drawable = null; AddStep("consume item and rewind clock", () => { var clock = new ManualClock { CurrentTime = Time.Current }; Add(new Container { RelativeSizeAxes = Axes.Both, Clock = new FramedClock(clock), Child = drawable = consumeDrawable(false) }); clock.CurrentTime = 0; }); AddAssert("child prepared", () => drawable.PreparedCount == 1); }
public override void SetUp() { base.SetUp(); const int transforms_count = 10000; ManualClock clock; target = new TestBox { Clock = new FramedClock(clock = new ManualClock()) }; // transform one target member over a long period target.RotateTo(360, transforms_count * 2); // transform another over the same period many times for (int i = 0; i < transforms_count; i++) { target.Delay(i).MoveTo(new Vector2(0.01f), 1f); } clock.CurrentTime = target.LatestTransformEndTime; target.Clock.ProcessFrame(); }
public void RequestProxied_MultipleConcurrentRequests_MarkDestinationUnhealthyAndHealthyAgain() { var options = Options.Create( new TransportFailureRateHealthPolicyOptions { DefaultFailureRateLimit = 0.5, DetectionWindowSize = TimeSpan.FromSeconds(30), MinimalTotalCountThreshold = 1 }); var clock = new ManualClock(TimeSpan.FromMilliseconds(10000)); var healthUpdater = new Mock <IDestinationHealthUpdater>(); var reactivationPeriod = TimeSpan.FromSeconds(40); var policy = new TransportFailureRateHealthPolicy(options, clock, healthUpdater.Object); var cluster = GetClusterInfo("cluster0", destinationCount: 2, reactivationPeriod: reactivationPeriod); // Initial state Assert.All(cluster.Destinations.Values, d => Assert.Equal(DestinationHealth.Unknown, d.Health.Passive)); // Initial sucessful requests for (var i = 0; i < 2; i++) { policy.RequestProxied(new DefaultHttpContext(), cluster, cluster.Destinations.Values.Skip(1).First()); } healthUpdater.Verify(u => u.SetPassive(cluster, cluster.Destinations.Values.Skip(1).First(), DestinationHealth.Healthy, reactivationPeriod), Times.Exactly(2)); healthUpdater.VerifyNoOtherCalls(); // Concurrent failed requests. // They are 'concurrent' because the clock is not updated. for (var i = 0; i < 2; i++) { policy.RequestProxied(GetFailedRequestContext(ForwarderError.RequestTimedOut), cluster, cluster.Destinations.Values.Skip(1).First()); } healthUpdater.Verify(u => u.SetPassive(cluster, cluster.Destinations.Values.Skip(1).First(), DestinationHealth.Healthy, reactivationPeriod), Times.Exactly(3)); healthUpdater.Verify(u => u.SetPassive(cluster, cluster.Destinations.Values.Skip(1).First(), DestinationHealth.Unhealthy, reactivationPeriod), Times.Once); healthUpdater.VerifyNoOtherCalls(); // More successful requests for (var i = 0; i < 2; i++) { policy.RequestProxied(new DefaultHttpContext(), cluster, cluster.Destinations.Values.Skip(1).First()); clock.AdvanceClockBy(TimeSpan.FromMilliseconds(100)); } healthUpdater.Verify(u => u.SetPassive(cluster, cluster.Destinations.Values.Skip(1).First(), DestinationHealth.Healthy, reactivationPeriod), Times.Exactly(5)); healthUpdater.Verify(u => u.SetPassive(cluster, cluster.Destinations.Values.Skip(1).First(), DestinationHealth.Unhealthy, reactivationPeriod), Times.Once); healthUpdater.VerifyNoOtherCalls(); // More failed requests for (var i = 0; i < 2; i++) { policy.RequestProxied(GetFailedRequestContext(ForwarderError.RequestTimedOut), cluster, cluster.Destinations.Values.Skip(1).First()); clock.AdvanceClockBy(TimeSpan.FromMilliseconds(100)); } healthUpdater.Verify(u => u.SetPassive(cluster, cluster.Destinations.Values.Skip(1).First(), DestinationHealth.Healthy, reactivationPeriod), Times.Exactly(6)); healthUpdater.Verify(u => u.SetPassive(cluster, cluster.Destinations.Values.Skip(1).First(), DestinationHealth.Unhealthy, reactivationPeriod), Times.Exactly(2)); healthUpdater.VerifyNoOtherCalls(); policy.RequestProxied(new DefaultHttpContext(), cluster, cluster.Destinations.Values.First()); healthUpdater.Verify(u => u.SetPassive(cluster, cluster.Destinations.Values.First(), DestinationHealth.Healthy, reactivationPeriod), Times.Once); healthUpdater.VerifyNoOtherCalls(); }
public void SetUp() => Schedule(() => { Clear(); manualClock = new ManualClock(); manualFramedClock = new FramedClock(manualClock); });
public void NormalRun() { ManualClock clock = new ManualClock(); clock.Start(); FixedStepTimer timer = new FixedStepTimer(clock) { StepSize = TimeSpan.FromMilliseconds(10), MaxNumberOfSteps = 5, }; timer.Idle += timer_Idle; timer.TimeChanged += timer_TimeChanged; // Clock is running. Timer is stopped. clock.Update(TimeSpan.FromMilliseconds(10)); CheckNoIdleEvent(); CheckNoTimeChangedEvent(); // Start timer.Start(); clock.Update(TimeSpan.FromMilliseconds(10)); CheckNoIdleEvent(); CheckTimeChangedEvent(TimeSpan.FromMilliseconds(10), TimeSpan.FromMilliseconds(10)); clock.Update(TimeSpan.FromMilliseconds(10)); CheckNoIdleEvent(); CheckTimeChangedEvent(TimeSpan.FromMilliseconds(20), TimeSpan.FromMilliseconds(10)); Assert.AreEqual(TimeSpan.FromMilliseconds(20), timer.Time); Assert.AreEqual(TimeSpan.FromMilliseconds(10), timer.DeltaTime); // Pause timer.Stop(); clock.Update(TimeSpan.FromMilliseconds(10)); CheckNoIdleEvent(); CheckNoTimeChangedEvent(); Assert.AreEqual(TimeSpan.FromMilliseconds(20), timer.Time); // Resume timer.Start(); clock.Update(TimeSpan.FromMilliseconds(10)); CheckNoIdleEvent(); CheckTimeChangedEvent(TimeSpan.FromMilliseconds(30), TimeSpan.FromMilliseconds(10)); Assert.AreEqual(TimeSpan.FromMilliseconds(30), timer.Time); Assert.AreEqual(TimeSpan.FromMilliseconds(10), timer.DeltaTime); Assert.AreEqual(0, timer.AccumulatedSteps); Assert.AreEqual(0, timer.PendingSteps); // Time step = 3 ∙ step size clock.Update(TimeSpan.FromMilliseconds(34)); CheckNoIdleEvent(); CheckTimeChangedEvent(TimeSpan.FromMilliseconds(60), TimeSpan.FromMilliseconds(30)); Assert.AreEqual(TimeSpan.FromMilliseconds(60), timer.Time); Assert.AreEqual(TimeSpan.FromMilliseconds(30), timer.DeltaTime); Assert.AreEqual(0, timer.AccumulatedSteps); Assert.AreEqual(0, timer.PendingSteps); // Time step = 3 ∙ step size // (27 ms + 4 ms from previous step = 31 ms) clock.Update(TimeSpan.FromMilliseconds(27)); CheckNoIdleEvent(); CheckTimeChangedEvent(TimeSpan.FromMilliseconds(90), TimeSpan.FromMilliseconds(30)); Assert.AreEqual(TimeSpan.FromMilliseconds(90), timer.Time); Assert.AreEqual(TimeSpan.FromMilliseconds(30), timer.DeltaTime); Assert.AreEqual(0, timer.AccumulatedSteps); Assert.AreEqual(0, timer.PendingSteps); // Time step = step size // (9 ms + 1 ms from previous step = 10 ms) clock.Update(TimeSpan.FromMilliseconds(9)); CheckNoIdleEvent(); CheckTimeChangedEvent(TimeSpan.FromMilliseconds(100), TimeSpan.FromMilliseconds(10)); Assert.AreEqual(TimeSpan.FromMilliseconds(100), timer.Time); Assert.AreEqual(TimeSpan.FromMilliseconds(10), timer.DeltaTime); Assert.AreEqual(0, timer.AccumulatedSteps); Assert.AreEqual(0, timer.PendingSteps); }
public TestBreakTracker() { FramedManualClock = new FramedClock(manualClock = new ManualClock()); ProcessCustomClock = false; }
public async Task StreamShedulingIsAppliedAccordingToClockAndSchedulers() { var clock = new ManualClock(new DateTime(2000, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc)); var stream = new MemoryStream(); var scheduler = new ShapeStreamAverage(BandwidthStreamCost.Default, 1000, 2000, 10, averageSpan: TimeSpan.FromSeconds(5), clock: clock); var bw = stream.Shape(scheduler); // Writing (2000b/s over 5s = 10kb/5s) await WriteAsync(bw, 1, 9000).ConfigureAwait(false); stream.Length.Should().Be(9000); await WriteAsync(bw, 2, 1000).ConfigureAwait(false); stream.Length.Should().Be(10000); await Task.WhenAll(clock.Advance(TimeSpan.FromSeconds(4), CancellationToken)).ConfigureAwait(false); // Exceed the shaping: will timeout and not get invoked await Waiter.TimesOut(ct => WriteAsync(bw, 3, 2000, ct), cancellationToken : CancellationToken).ConfigureAwait(false); stream.Length.Should().Be(10000); // Try writing again var wtask = WriteAsync(bw, 4, 2000); // That won't run immediately await Waiter.TimesOut(wtask.WaitAsync, cancellationToken : CancellationToken).ConfigureAwait(false); // And one second is not enough, as we are accounted the 2000 from time timed out write await Task.WhenAll(clock.Advance(TimeSpan.FromSeconds(1), CancellationToken)).ConfigureAwait(false); await Waiter.TimesOut(wtask.WaitAsync, cancellationToken : CancellationToken).ConfigureAwait(false); // So we need another second await Task.WhenAll(clock.Advance(TimeSpan.FromSeconds(1), CancellationToken)); // Now, It will be completed (pretty quickly) await Waiter.WaitAsync(wtask.WaitAsync, cancellationToken : CancellationToken); // And now have the required state stream.Length.Should().Be(12000); stream.Position = 0; var streamBytes = stream.ToArray(); IList <IList <byte> > readParts = new List <IList <byte> >(); // ReSharper disable once ImplicitlyCapturedClosure - bw, this captured void AssertReadCorrect() => readParts.Aggregate(0, (offset, part) => { part.Should().BeEquivalentTo(streamBytes.Skip(offset).Take(part.Count)); return(offset + part.Count); }); // Reading (1000b/s over 5s = 50kb/5s) readParts.Add(await ReadAsync(bw, 4999, CancellationToken).ConfigureAwait(false)); AssertReadCorrect(); readParts.Add(await ReadAsync(bw, 1).ConfigureAwait(false)); AssertReadCorrect(); // Exceed the shaping: will timeout and not get invoked // ReSharper disable once ImplicitlyCapturedClosure -- streamBytes captured await Waiter.TimesOut(async ct => readParts.Add(await ReadAsync(bw, 1, ct).ConfigureAwait(false)), cancellationToken : CancellationToken).ConfigureAwait(false); AssertReadCorrect(); // Try reading again var rtask = ReadAsync(bw, 6000); // That won't run immediately await Waiter.TimesOut(rtask.WaitAsync, cancellationToken : CancellationToken).ConfigureAwait(false); // And 6 seconds is not enough, as we are exceeding average in the read itself and pay for the extra 1 failing byte await Task.WhenAll(clock.Advance(TimeSpan.FromSeconds(6), CancellationToken)).ConfigureAwait(false); await Waiter.TimesOut(rtask.WaitAsync, cancellationToken : CancellationToken).ConfigureAwait(false); // But a little more is await Task.WhenAll(clock.Advance(TimeSpan.FromSeconds(.1), CancellationToken)).ConfigureAwait(false); // Now, It will be completed (pretty quickly) readParts.Add(await Waiter.WaitAsync(rtask.WaitAsync, cancellationToken: CancellationToken)); AssertReadCorrect(); readParts.Sum(x => x.Count).Should().Be(4999 + 1 + 6000); }
public void NegativeScale() { ManualClock clock = new ManualClock(); clock.Start(); VariableStepTimer timer = new VariableStepTimer(clock); timer.Idle += timer_Idle; timer.TimeChanged += timer_TimeChanged; timer.Speed = -2.0; timer.Start(); Assert.AreEqual(-2.0, timer.Speed); clock.Update(TimeSpan.FromMilliseconds(10)); CheckNoIdleEvent(); CheckTimeChangedEvent(TimeSpan.FromMilliseconds(-20), TimeSpan.FromMilliseconds(-20)); clock.Update(TimeSpan.FromMilliseconds(10)); CheckNoIdleEvent(); CheckTimeChangedEvent(TimeSpan.FromMilliseconds(-40), TimeSpan.FromMilliseconds(-20)); timer.MinDeltaTime = TimeSpan.FromMilliseconds(20); timer.MaxDeltaTime = TimeSpan.FromMilliseconds(50); clock.Update(TimeSpan.FromMilliseconds(10)); CheckNoIdleEvent(); CheckTimeChangedEvent(TimeSpan.FromSeconds(-0.06f), TimeSpan.FromMilliseconds(-20)); clock.Update(TimeSpan.FromMilliseconds(9)); CheckIdleEvent(TimeSpan.FromMilliseconds(20 - 18)); CheckNoTimeChangedEvent(); clock.Update(TimeSpan.FromTicks(5000)); // 0.5 ms CheckIdleEvent(TimeSpan.FromMilliseconds(20 - 19)); CheckNoTimeChangedEvent(); clock.Update(TimeSpan.FromMilliseconds(10)); CheckNoIdleEvent(); CheckTimeChangedEvent(TimeSpan.FromMilliseconds(-60 - 39), TimeSpan.FromMilliseconds(-39)); clock.Update(TimeSpan.FromMilliseconds(30)); CheckNoIdleEvent(); CheckTimeChangedEvent(TimeSpan.FromMilliseconds(-60 - 39 - 50), TimeSpan.FromMilliseconds(-50)); Assert.AreEqual(TimeSpan.FromMilliseconds(10), timer.LostTime); }
public void Scale() { ManualClock clock = new ManualClock(); clock.Start(); FixedStepTimer timer = new FixedStepTimer(clock) { StepSize = TimeSpan.FromMilliseconds(10), MaxNumberOfSteps = 5, }; timer.TimeChanged += timer_TimeChanged; timer.Start(); Assert.AreEqual(1.0, timer.Speed); clock.Update(TimeSpan.FromMilliseconds(10)); CheckTimeChangedEvent(TimeSpan.FromMilliseconds(10), TimeSpan.FromMilliseconds(10)); clock.Update(TimeSpan.FromMilliseconds(10)); CheckTimeChangedEvent(TimeSpan.FromMilliseconds(20), TimeSpan.FromMilliseconds(10)); timer.Speed = 0.5; Assert.AreEqual(0.5, timer.Speed); clock.Update(TimeSpan.FromMilliseconds(10)); CheckNoTimeChangedEvent(); clock.Update(TimeSpan.FromMilliseconds(10)); CheckTimeChangedEvent(TimeSpan.FromMilliseconds(30), TimeSpan.FromMilliseconds(10)); timer.Speed = 2.0; Assert.AreEqual(2.0, timer.Speed); clock.Update(TimeSpan.FromMilliseconds(10)); CheckTimeChangedEvent(TimeSpan.FromMilliseconds(50), TimeSpan.FromMilliseconds(20)); timer.Speed = -3.0; Assert.AreEqual(-3.0, timer.Speed); clock.Update(TimeSpan.FromMilliseconds(10)); CheckTimeChangedEvent(TimeSpan.FromMilliseconds(20), TimeSpan.FromMilliseconds(-30)); Assert.AreEqual(TimeSpan.FromMilliseconds(20), timer.Time); Assert.AreEqual(TimeSpan.FromMilliseconds(-30), timer.DeltaTime); }
public void TimerReset() { ManualClock clock = new ManualClock(); clock.Start(); VariableStepTimer timer = new VariableStepTimer(clock); timer.Idle += timer_Idle; timer.TimeChanged += timer_TimeChanged; timer.Reset(); timer.Start(); clock.Update(TimeSpan.FromMilliseconds(10)); CheckTimeChangedEvent(TimeSpan.FromMilliseconds(10), TimeSpan.FromMilliseconds(10)); timer.Reset(); Assert.IsFalse(timer.IsRunning); Assert.AreEqual(TimeSpan.Zero, timer.Time); Assert.AreEqual(TimeSpan.Zero, timer.DeltaTime); timer.Start(); clock.Update(TimeSpan.FromMilliseconds(10)); clock.Update(TimeSpan.FromMilliseconds(10)); CheckTimeChangedEvent(TimeSpan.FromMilliseconds(20), TimeSpan.FromMilliseconds(10)); timer.Stop(); Assert.AreEqual(TimeSpan.FromMilliseconds(20), timer.Time); Assert.AreEqual(TimeSpan.Zero, timer.DeltaTime); timer.Reset(); Assert.AreEqual(TimeSpan.Zero, timer.Time); Assert.AreEqual(TimeSpan.Zero, timer.DeltaTime); }
public void SwitchClocks() { ManualClock clock1 = new ManualClock(); ManualClock clock2 = new ManualClock(); clock1.Start(); clock2.Start(); IGameTimer timer = new VariableStepTimer(clock1); timer.TimeChanged += timer_TimeChanged; timer.Start(); clock1.Update(TimeSpan.FromMilliseconds(10)); CheckTimeChangedEvent(TimeSpan.FromMilliseconds(10), TimeSpan.FromMilliseconds(10)); timer.Clock = clock2; Assert.AreSame(clock2, timer.Clock); clock1.Update(TimeSpan.FromMilliseconds(10)); CheckNoTimeChangedEvent(); clock2.Update(TimeSpan.FromMilliseconds(20)); CheckTimeChangedEvent(TimeSpan.FromMilliseconds(30), TimeSpan.FromMilliseconds(20)); timer.Clock = null; Assert.IsNull(timer.Clock); clock1.Update(TimeSpan.FromMilliseconds(10)); clock2.Update(TimeSpan.FromMilliseconds(20)); CheckNoTimeChangedEvent(); Assert.AreEqual(TimeSpan.FromMilliseconds(30), timer.Time); Assert.AreEqual(TimeSpan.FromMilliseconds(20), timer.DeltaTime); }
public void Scale() { ManualClock clock = new ManualClock(); clock.Start(); VariableStepTimer timer = new VariableStepTimer(clock); timer.TimeChanged += timer_TimeChanged; timer.Start(); Assert.AreEqual(1.0, timer.Speed); clock.Update(TimeSpan.FromMilliseconds(20)); CheckTimeChangedEvent(TimeSpan.FromMilliseconds(20), TimeSpan.FromMilliseconds(20)); clock.Update(TimeSpan.FromMilliseconds(20)); CheckTimeChangedEvent(TimeSpan.FromMilliseconds(40), TimeSpan.FromMilliseconds(20)); timer.Speed = 0.5; Assert.AreEqual(0.5, timer.Speed); clock.Update(TimeSpan.FromMilliseconds(20)); CheckTimeChangedEvent(TimeSpan.FromMilliseconds(50), TimeSpan.FromMilliseconds(10)); clock.Update(TimeSpan.FromMilliseconds(20)); CheckTimeChangedEvent(TimeSpan.FromMilliseconds(60), TimeSpan.FromMilliseconds(10)); timer.Speed = 2.0; Assert.AreEqual(2.0, timer.Speed); clock.Update(TimeSpan.FromMilliseconds(20)); CheckTimeChangedEvent(TimeSpan.FromMilliseconds(100), TimeSpan.FromMilliseconds(40)); timer.Speed = -3.0; Assert.AreEqual(-3.0, timer.Speed); clock.Update(TimeSpan.FromMilliseconds(20)); CheckTimeChangedEvent(TimeSpan.FromMilliseconds(40), TimeSpan.FromMilliseconds(-60)); Assert.AreEqual(TimeSpan.FromMilliseconds(40), timer.Time); Assert.AreEqual(TimeSpan.FromMilliseconds(-60), timer.DeltaTime); }
protected RulesetInputManager(RulesetInfo ruleset, int variant, SimultaneousBindingMode unique) { InternalChild = KeyBindingContainer = CreateKeyBindingContainer(ruleset, variant, unique); gameplayClock = new GameplayClock(framedClock = new FramedClock(manualClock = new ManualClock())); }
public void NormalRun() { ManualClock clock = new ManualClock(); clock.Start(); VariableStepTimer timer = new VariableStepTimer(clock); timer.Idle += timer_Idle; timer.TimeChanged += timer_TimeChanged; // Clock is not running clock.Update(TimeSpan.FromMilliseconds(10)); Assert.IsFalse(timer.IsRunning); CheckNoIdleEvent(); CheckNoTimeChangedEvent(); // Start/Stop ... not running timer.Start(); timer.Stop(); clock.Update(TimeSpan.FromMilliseconds(10)); Assert.IsFalse(timer.IsRunning); CheckNoIdleEvent(); CheckNoTimeChangedEvent(); // Start timer.Start(); clock.Update(TimeSpan.FromMilliseconds(10)); Assert.IsTrue(timer.IsRunning); CheckNoIdleEvent(); CheckTimeChangedEvent(TimeSpan.FromMilliseconds(10), TimeSpan.FromMilliseconds(10)); clock.Update(TimeSpan.FromMilliseconds(10)); CheckNoIdleEvent(); CheckTimeChangedEvent(TimeSpan.FromMilliseconds(20), TimeSpan.FromMilliseconds(10)); Assert.AreEqual(TimeSpan.FromMilliseconds(20), timer.Time); Assert.AreEqual(TimeSpan.FromMilliseconds(10), timer.DeltaTime); Assert.AreEqual(TimeSpan.Zero, timer.IdleTime); Assert.AreEqual(TimeSpan.Zero, timer.LostTime); // Pause timer.Stop(); clock.Update(TimeSpan.FromMilliseconds(10)); Assert.IsFalse(timer.IsRunning); CheckNoIdleEvent(); CheckNoTimeChangedEvent(); Assert.AreEqual(TimeSpan.FromMilliseconds(20), timer.Time); // Resume timer.Start(); clock.Update(TimeSpan.FromMilliseconds(10)); Assert.IsTrue(timer.IsRunning); CheckNoIdleEvent(); CheckTimeChangedEvent(TimeSpan.FromMilliseconds(30), TimeSpan.FromMilliseconds(10)); Assert.AreEqual(TimeSpan.FromMilliseconds(30), timer.Time); Assert.AreEqual(TimeSpan.FromMilliseconds(10), timer.DeltaTime); Assert.AreEqual(TimeSpan.Zero, timer.IdleTime); Assert.AreEqual(TimeSpan.Zero, timer.LostTime); // Stop timer.Stop(); clock.Update(TimeSpan.FromMilliseconds(10)); CheckNoIdleEvent(); CheckNoTimeChangedEvent(); }
public void SerializerSerializesFullSpanCorrectly() { var clock = ManualClock.FromUtcNow(); var tracer = new Tracer(new TraceOptions() { Clock = clock.Now, NewId = () => 45, Endpoint = new Endpoint("test-host", "127.0.0.1", 56) }); IScope scope = null; DateTimeOffset startSomething, completeSomething; using (scope = tracer.NewSpan("test", new SpanContext(345, 2542, 3535, true, true, true)) .SetKind(SpanKind.CLIENT) .Tag("tag1", 1) .Tag("tag2", true) .Tag("tag3", 4.5) .Tag("tag4", "please work") .SetRemoteEndpoint(new Endpoint("server-host", "192.168.0.1", 67)) .Tag("peer.address", "http://server-host:67/") .Activate()) { clock.Move(TimeSpan.FromMilliseconds(10)); startSomething = clock.Now(); scope.Span.Annotate("starting something"); clock.Move(TimeSpan.FromMilliseconds(456)); scope.Span.Annotate("completed something"); completeSomething = clock.Now(); } var serializer = new V2JsonSerializer(); var jobj = JArray.Parse(serializer.Serialize(new Span[] { scope.Span })); var spanObj = jobj[0]; Assert.Equal(345.ToString("x16"), spanObj["traceId"].Value <string>()); Assert.Equal(45.ToString("x16"), spanObj["id"].Value <string>()); Assert.Equal(2542.ToString("x16"), spanObj["parentId"].Value <string>()); Assert.Equal("test", spanObj["name"].Value <string>()); Assert.Equal("CLIENT", spanObj["kind"].Value <string>()); Assert.Equal(ZipkinUtil.ToUnixMs(scope.Span.StartTimeStamp.Value), spanObj["timestamp"].Value <long>()); Assert.Equal(ZipkinUtil.DurationMs(scope.Span), spanObj["duration"].Value <long>()); Assert.Equal(scope.Span.Context.Debug, spanObj["debug"].Value <bool>()); Assert.Equal(scope.Span.Context.Shared, spanObj["shared"].Value <bool>()); var endpoint = spanObj["localEndpoint"]; Assert.Equal("test-host", endpoint["serviceName"]); Assert.Equal("127.0.0.1", endpoint["ipv4"]); Assert.Equal(56, endpoint["port"].Value <int>()); endpoint = spanObj["remoteEndpoint"]; Assert.Equal("server-host", endpoint["serviceName"]); Assert.Equal("192.168.0.1", endpoint["ipv4"]); Assert.Equal(67, endpoint["port"].Value <int>()); var tags = spanObj["tags"]; Assert.Equal(1, tags["tag1"].Value <int>()); Assert.True(tags["tag2"].Value <bool>()); Assert.Equal(4.5, tags["tag3"].Value <double>()); Assert.Equal("please work", tags["tag4"].Value <string>()); var annotations = (JArray)spanObj["annotations"]; Assert.Equal(ZipkinUtil.ToUnixMs(startSomething), annotations[0]["timestamp"].Value <long>()); Assert.Equal("starting something", annotations[0]["value"].Value <string>()); Assert.Equal(ZipkinUtil.ToUnixMs(completeSomething), annotations[1]["timestamp"].Value <long>()); Assert.Equal("completed something", annotations[1]["value"].Value <string>()); }
public async Task LongContentTransfer_TelemetryReportsTransferringEvents(bool isRequest) { var events = TestEventListener.Collect(); const int SourceSize = 123; var sourceBytes = new byte[SourceSize]; var source = new MemoryStream(sourceBytes); var destination = new MemoryStream(); var clock = new ManualClock(); var sourceWaitTime = TimeSpan.FromMilliseconds(789); // Every second read triggers ContentTransferring var destinationWaitTime = TimeSpan.FromMilliseconds(42); const int BytesPerRead = 3; var contentReads = (int)Math.Ceiling((double)SourceSize / BytesPerRead); await StreamCopier.CopyAsync( isRequest, new SlowStream(source, clock, sourceWaitTime) { MaxBytesPerRead = BytesPerRead }, new SlowStream(destination, clock, destinationWaitTime), clock, CancellationToken.None); Assert.Equal(sourceBytes, destination.ToArray()); AssertContentTransferred(events, isRequest, SourceSize, iops: contentReads + 1, firstReadTime: sourceWaitTime, readTime: (contentReads + 1) * sourceWaitTime, writeTime: contentReads * destinationWaitTime); var transferringEvents = events.Where(e => e.EventName == "ContentTransferring").ToArray(); Assert.Equal(contentReads / 2, transferringEvents.Length); for (var i = 0; i < transferringEvents.Length; i++) { var payload = transferringEvents[i].Payload; Assert.Equal(5, payload.Count); Assert.Equal(isRequest, (bool)payload[0]); var contentLength = (long)payload[1]; var iops = (long)payload[2]; Assert.Equal((i + 1) * 2, iops); if (contentLength % BytesPerRead == 0) { Assert.Equal(iops * BytesPerRead, contentLength); } else { Assert.Equal(transferringEvents.Length - 1, i); Assert.Equal(SourceSize, contentLength); } var readTime = new TimeSpan((long)payload[3]); Assert.Equal(iops * sourceWaitTime, readTime, new ApproximateTimeSpanComparer()); var writeTime = new TimeSpan((long)payload[4]); Assert.Equal(iops * destinationWaitTime, writeTime, new ApproximateTimeSpanComparer()); } }
public TestBreakOverlay(bool letterboxing) : base(letterboxing) { framedManualClock = new FramedClock(manualClock = new ManualClock()); ProcessCustomClock = false; }
public void AccumulatedTime() { ManualClock clock = new ManualClock(); clock.Start(); FixedStepTimer timer = new FixedStepTimer(clock) { StepSize = TimeSpan.FromMilliseconds(10), MaxNumberOfSteps = 5, }; timer.Idle += timer_Idle; timer.TimeChanged += timer_TimeChanged; timer.Start(); clock.Update(TimeSpan.FromMilliseconds(10)); Assert.AreEqual(TimeSpan.Zero, timer.AccumulatedTime); clock.Update(TimeSpan.FromMilliseconds(3)); Assert.AreEqual(TimeSpan.FromMilliseconds(3), timer.AccumulatedTime); clock.Update(TimeSpan.FromMilliseconds(6)); Assert.AreEqual(TimeSpan.FromMilliseconds(9), timer.AccumulatedTime); clock.Update(TimeSpan.FromMilliseconds(12)); Assert.AreEqual(TimeSpan.FromMilliseconds(1), timer.AccumulatedTime); // MaxNumberOfSteps exceeded: clock.Update(TimeSpan.FromMilliseconds(1000000)); Assert.AreEqual(TimeSpan.Zero, timer.AccumulatedTime); // Accumulated steps. timer.AccumulateTimeSteps = true; clock.Update(TimeSpan.FromMilliseconds(22)); Assert.AreEqual(TimeSpan.FromMilliseconds(2), timer.AccumulatedTime); timer.AccumulateTimeSteps = false; clock.Update(TimeSpan.FromMilliseconds(22)); timer.TimeChanged += (s, e) => { if (timer.PendingSteps > 0) Assert.AreEqual(TimeSpan.Zero, timer.AccumulatedTime); else Assert.AreEqual(TimeSpan.FromMilliseconds(4), timer.AccumulatedTime); }; }
public void NegativeScale() { ManualClock clock = new ManualClock(); clock.Start(); FixedStepTimer timer = new FixedStepTimer(clock) { StepSize = TimeSpan.FromMilliseconds(10), MaxNumberOfSteps = 5, }; timer.Idle += timer_Idle; timer.TimeChanged += timer_TimeChanged; timer.Speed = -2.0; timer.Start(); Assert.AreEqual(-2.0, timer.Speed); clock.Update(TimeSpan.FromMilliseconds(10)); CheckNoIdleEvent(); CheckTimeChangedEvent(TimeSpan.FromMilliseconds(-20), TimeSpan.FromMilliseconds(-20)); Assert.AreEqual(0, timer.AccumulatedSteps); Assert.AreEqual(0, timer.PendingSteps); clock.Update(TimeSpan.FromMilliseconds(10)); CheckNoIdleEvent(); CheckTimeChangedEvent(TimeSpan.FromMilliseconds(-40), TimeSpan.FromMilliseconds(-20)); Assert.AreEqual(0, timer.AccumulatedSteps); Assert.AreEqual(0, timer.PendingSteps); clock.Update(TimeSpan.FromMilliseconds(21)); CheckNoIdleEvent(); CheckTimeChangedEvent(TimeSpan.FromMilliseconds(-80), TimeSpan.FromMilliseconds(-40)); Assert.AreEqual(0, timer.AccumulatedSteps); Assert.AreEqual(0, timer.PendingSteps); clock.Update(TimeSpan.FromMilliseconds(2)); CheckIdleEvent(TimeSpan.FromMilliseconds(4)); CheckNoTimeChangedEvent(); Assert.AreEqual(0, timer.AccumulatedSteps); Assert.AreEqual(0, timer.PendingSteps); clock.Update(TimeSpan.FromMilliseconds(4)); CheckNoIdleEvent(); CheckTimeChangedEvent(TimeSpan.FromMilliseconds(-90), TimeSpan.FromMilliseconds(-10)); Assert.AreEqual(0, timer.AccumulatedSteps); Assert.AreEqual(0, timer.PendingSteps); clock.Update(TimeSpan.FromMilliseconds(1)); CheckIdleEvent(TimeSpan.FromMilliseconds(4)); CheckNoTimeChangedEvent(); Assert.AreEqual(0, timer.AccumulatedSteps); Assert.AreEqual(0, timer.PendingSteps); clock.Update(TimeSpan.FromMilliseconds(13)); CheckNoIdleEvent(); CheckTimeChangedEvent(TimeSpan.FromMilliseconds(-120), TimeSpan.FromMilliseconds(-30)); Assert.AreEqual(0, timer.AccumulatedSteps); Assert.AreEqual(0, timer.PendingSteps); // 1 ms wall clock time remaining from previous step. clock.Update(TimeSpan.FromMilliseconds(25)); CheckNoIdleEvent(); CheckTimeChangedEvent(TimeSpan.FromMilliseconds(-170), TimeSpan.FromMilliseconds(-50)); Assert.AreEqual(TimeSpan.FromMilliseconds(2), timer.LostTime); }
public void SetUp() { Clear(); manualClock = new ManualClock(); manualFramedClock = new FramedClock(manualClock); }
public void ResetDeltaTime() { IGameClock clock = new ManualClock(); Assert.Throws <NotSupportedException>(clock.ResetDeltaTime); }
public FrameStabilityContainer() { RelativeSizeAxes = Axes.Both; gameplayClock = new GameplayClock(framedClock = new FramedClock(manualClock = new ManualClock())); }
public void TimeChanged() { var clock = new ManualClock(); var step = new TimeSpan(100000); int numberOfEvents = 0; TimeSpan deltaTime = TimeSpan.Zero; TimeSpan gameTime = TimeSpan.Zero; TimeSpan totalTime = TimeSpan.Zero; clock.TimeChanged += (s, e) => { numberOfEvents++; deltaTime = e.DeltaTime; gameTime = e.GameTime; totalTime = e.TotalTime; }; clock.Update(step); Assert.AreEqual(0, numberOfEvents); clock.Start(); clock.Update(step); clock.Update(step); Assert.AreEqual(step.Ticks, deltaTime.Ticks); Assert.AreEqual(2 * step.Ticks, gameTime.Ticks); Assert.AreEqual(2 * step.Ticks, totalTime.Ticks); clock.Stop(); clock.Update(step); }
public void SetUpSteps() { AddStep("Reset recorder state", cleanUpState); AddStep("Setup containers", () => { replay = new Replay(); manualClock = new ManualClock(); spectatorClient.OnNewFrames += onNewFrames; users.BindTo(spectatorClient.PlayingUsers); users.BindCollectionChanged((obj, args) => { switch (args.Action) { case NotifyCollectionChangedAction.Add: Debug.Assert(args.NewItems != null); foreach (int user in args.NewItems) { if (user == api.LocalUser.Value.Id) { spectatorClient.WatchUser(user); } } break; case NotifyCollectionChangedAction.Remove: Debug.Assert(args.OldItems != null); foreach (int user in args.OldItems) { if (user == api.LocalUser.Value.Id) { spectatorClient.StopWatchingUser(user); } } break; } }, true); Children = new Drawable[] { new GridContainer { RelativeSizeAxes = Axes.Both, Content = new[] { new Drawable[] { recordingManager = new TestRulesetInputManager(TestSceneModSettings.CreateTestRulesetInfo(), 0, SimultaneousBindingMode.Unique) { Recorder = recorder = new TestReplayRecorder { ScreenSpaceToGamefield = pos => recordingManager.ToLocalSpace(pos), }, Child = new Container { RelativeSizeAxes = Axes.Both, Children = new Drawable[] { new Box { Colour = Color4.Brown, RelativeSizeAxes = Axes.Both, }, new OsuSpriteText { Text = "Sending", Scale = new Vector2(3), Anchor = Anchor.Centre, Origin = Anchor.Centre, }, new TestInputConsumer() } }, } }, new Drawable[] { playbackManager = new TestRulesetInputManager(TestSceneModSettings.CreateTestRulesetInfo(), 0, SimultaneousBindingMode.Unique) { Clock = new FramedClock(manualClock), ReplayInputHandler = replayHandler = new TestFramedReplayInputHandler(replay) { GamefieldToScreenSpace = pos => playbackManager.ToScreenSpace(pos), }, Child = new Container { RelativeSizeAxes = Axes.Both, Children = new Drawable[] { new Box { Colour = Color4.DarkBlue, RelativeSizeAxes = Axes.Both, }, new OsuSpriteText { Text = "Receiving", Scale = new Vector2(3), Anchor = Anchor.Centre, Origin = Anchor.Centre, }, new TestInputConsumer() } }, } } } }, latencyDisplay = new OsuSpriteText() }; }); }
public CachedServiceFabricCallerTests(ITestOutputHelper testOutputHelper) { _clock = new ManualClock(); Provide <IClock>(_clock); Provide <ILogger>(new XunitLogger <Discoverer>(testOutputHelper)); }
public TestAnimationTimeReference() { ManualClock = new ManualClock(); Clock = new FramedClock(ManualClock); }
public void RequestProxied_FailureMovedOutOfDetectionWindow_MarkDestinationHealthy() { var options = Options.Create( new TransportFailureRateHealthPolicyOptions { DefaultFailureRateLimit = 0.5, DetectionWindowSize = TimeSpan.FromSeconds(30), MinimalTotalCountThreshold = 1 }); var clock = new ManualClock(TimeSpan.FromMilliseconds(10000)); var healthUpdater = new Mock <IDestinationHealthUpdater>(); var policy = new TransportFailureRateHealthPolicy(options, clock, healthUpdater.Object); var cluster = GetClusterInfo("cluster0", destinationCount: 2); // Initial failed requests for (var i = 0; i < 2; i++) { policy.RequestProxied(GetFailedRequestContext(ForwarderError.RequestTimedOut), cluster, cluster.Destinations.Values.Skip(1).First()); clock.AdvanceClockBy(TimeSpan.FromMilliseconds(1000)); } healthUpdater.Verify(u => u.SetPassive(cluster, cluster.Destinations.Values.Skip(1).First(), DestinationHealth.Unhealthy, TimeSpan.FromSeconds(60)), Times.Exactly(2)); healthUpdater.VerifyNoOtherCalls(); // Successful requests for (var i = 0; i < 4; i++) { policy.RequestProxied(new DefaultHttpContext(), cluster, cluster.Destinations.Values.First()); policy.RequestProxied(new DefaultHttpContext(), cluster, cluster.Destinations.Values.Skip(1).First()); clock.AdvanceClockBy(TimeSpan.FromMilliseconds(5000)); } healthUpdater.Verify(u => u.SetPassive(cluster, cluster.Destinations.Values.First(), DestinationHealth.Healthy, TimeSpan.FromSeconds(60)), Times.Exactly(4)); healthUpdater.Verify(u => u.SetPassive(cluster, cluster.Destinations.Values.Skip(1).First(), DestinationHealth.Healthy, TimeSpan.FromSeconds(60)), Times.Exactly(2)); healthUpdater.Verify(u => u.SetPassive(cluster, cluster.Destinations.Values.Skip(1).First(), DestinationHealth.Unhealthy, TimeSpan.FromSeconds(60)), Times.Exactly(4)); healthUpdater.VerifyNoOtherCalls(); // Failed requests for (var i = 0; i < 2; i++) { policy.RequestProxied(GetFailedRequestContext(ForwarderError.RequestTimedOut), cluster, cluster.Destinations.Values.Skip(1).First()); clock.AdvanceClockBy(TimeSpan.FromMilliseconds(1)); } healthUpdater.Verify(u => u.SetPassive(cluster, cluster.Destinations.Values.Skip(1).First(), DestinationHealth.Healthy, TimeSpan.FromSeconds(60)), Times.Exactly(3)); healthUpdater.Verify(u => u.SetPassive(cluster, cluster.Destinations.Values.Skip(1).First(), DestinationHealth.Unhealthy, TimeSpan.FromSeconds(60)), Times.Exactly(5)); healthUpdater.VerifyNoOtherCalls(); // Shift the detection window to the future clock.AdvanceClockBy(TimeSpan.FromMilliseconds(10998)); // New successful requests for (var i = 0; i < 2; i++) { policy.RequestProxied(new DefaultHttpContext(), cluster, cluster.Destinations.Values.Skip(1).First()); clock.AdvanceClockBy(TimeSpan.FromMilliseconds(1)); } // New failed request, but 2 oldest failures have moved out of the detection window policy.RequestProxied(GetFailedRequestContext(ForwarderError.RequestTimedOut), cluster, cluster.Destinations.Values.Skip(1).First()); healthUpdater.Verify(u => u.SetPassive(cluster, cluster.Destinations.Values.Skip(1).First(), DestinationHealth.Healthy, TimeSpan.FromSeconds(60)), Times.Exactly(6)); healthUpdater.VerifyNoOtherCalls(); }
public void ResetDeltaTime() { IGameClock clock = new ManualClock(); Assert.Throws<NotSupportedException>(clock.ResetDeltaTime); }
public FrameStabilityContainer(double gameplayStartTime = double.MinValue) { RelativeSizeAxes = Axes.Both; stabilityGameplayClock = new StabilityGameplayClock(framedClock = new FramedClock(manualClock = new ManualClock())); this.gameplayStartTime = gameplayStartTime; }
public void Constructor() { ManualClock clock = new ManualClock(); clock.Start(); FixedStepTimer timer = new FixedStepTimer(clock); Assert.AreEqual(8, timer.MaxNumberOfSteps); Assert.AreEqual(TimeSpan.FromTicks(166666), timer.StepSize); timer = new FixedStepTimer(null); Assert.AreEqual(8, timer.MaxNumberOfSteps); Assert.AreEqual(TimeSpan.FromTicks(166666), timer.StepSize); }
public SlowStream(Stream innerStream, ManualClock clock, TimeSpan waitTime) : base(innerStream) { _clock = clock; _waitTime = waitTime; }