ChaoXingAutoClass
【WinUI】基于 XFEstudio 的 XFEWinUIApplication 模板重建的 WinUI 3 课程工作台。二维码和账号密码登录、课程 GridView、章节、播放进度、学习笔记及日志均使用原生 WinUI 控件。网页播放器运行在独立后台进程中,界面不显示课程网站。
关注
0
Fork
0
Star
0
using XFEExtension.NetCore.XUnit.Assertions;
using XFEExtension.NetCore.XUnit.Attributes;
namespace ChaoXingAutoClass.Test;
[TestFixture]
public sealed class CourseSchedulingTests
{
[Test]
public async Task MultipleCoursesRunUpToConfiguredLimitAndRemainingCoursesQueue()
{
using var gate = new AdaptiveCourseGate(2);
using var first = await gate.EnterAsync("one", () => { }, CancellationToken.None);
using var second = await gate.EnterAsync("two", () => { }, CancellationToken.None);
var third = gate.EnterAsync("three", () => { }, CancellationToken.None);
Assert.False(third.IsCompleted); second.Dispose();
using var admitted = await third.WaitAsync(TimeSpan.FromSeconds(3)); Assert.Equal(2, gate.EffectiveConcurrency);
}
[Test]
public async Task SiteRestrictionDrainsAllActiveCoursesBeforeSequentialRetries()
{
using var gate = new AdaptiveCourseGate(3); var restarts = 0;
using var first = await gate.EnterAsync("one", () => restarts++, CancellationToken.None);
using var second = await gate.EnterAsync("two", () => restarts++, CancellationToken.None);
Assert.True(gate.SwitchToSequential()); Assert.False(gate.SwitchToSequential()); Assert.Equal(2, restarts);
var retry = gate.EnterAsync("retry", () => { }, CancellationToken.None);
Assert.False(retry.IsCompleted); first.Dispose(); Assert.False(retry.IsCompleted); second.Dispose();
using var admitted = await retry.WaitAsync(TimeSpan.FromSeconds(3));
var next = gate.EnterAsync("next", () => { }, CancellationToken.None); Assert.False(next.IsCompleted);
admitted.Dispose(); using var last = await next.WaitAsync(TimeSpan.FromSeconds(3)); Assert.Equal(1, gate.EffectiveConcurrency);
}
[Test]
public async Task CancelledQueuedCourseCannotConsumeAConcurrencySlot()
{
using var gate = new AdaptiveCourseGate(1); using var first = await gate.EnterAsync("one", () => { }, CancellationToken.None);
using var cancelled = new CancellationTokenSource(); var queued = gate.EnterAsync("cancel", () => { }, cancelled.Token); cancelled.Cancel();
try { await queued; throw new Exception("Expected cancellation"); } catch (OperationCanceledException) { }
first.Dispose(); using var next = await gate.EnterAsync("next", () => { }, CancellationToken.None).WaitAsync(TimeSpan.FromSeconds(3));
}
}
using XFEExtension.NetCore.XUnit.Assertions;
using XFEExtension.NetCore.XUnit.Attributes;
namespace ChaoXingAutoClass.Test;
[TestFixture]
public sealed class CourseSchedulingTests
{
[Test]
public async Task MultipleCoursesRunUpToConfiguredLimitAndRemainingCoursesQueue()
{
using var gate = new AdaptiveCourseGate(2);
using var first = await gate.EnterAsync("one", () => { }, CancellationToken.None);
using var second = await gate.EnterAsync("two", () => { }, CancellationToken.None);
var third = gate.EnterAsync("three", () => { }, CancellationToken.None);
Assert.False(third.IsCompleted); second.Dispose();
using var admitted = await third.WaitAsync(TimeSpan.FromSeconds(3)); Assert.Equal(2, gate.EffectiveConcurrency);
}
[Test]
public async Task SiteRestrictionDrainsAllActiveCoursesBeforeSequentialRetries()
{
using var gate = new AdaptiveCourseGate(3); var restarts = 0;
using var first = await gate.EnterAsync("one", () => restarts++, CancellationToken.None);
using var second = await gate.EnterAsync("two", () => restarts++, CancellationToken.None);
Assert.True(gate.SwitchToSequential()); Assert.False(gate.SwitchToSequential()); Assert.Equal(2, restarts);
var retry = gate.EnterAsync("retry", () => { }, CancellationToken.None);
Assert.False(retry.IsCompleted); first.Dispose(); Assert.False(retry.IsCompleted); second.Dispose();
using var admitted = await retry.WaitAsync(TimeSpan.FromSeconds(3));
var next = gate.EnterAsync("next", () => { }, CancellationToken.None); Assert.False(next.IsCompleted);
admitted.Dispose(); using var last = await next.WaitAsync(TimeSpan.FromSeconds(3)); Assert.Equal(1, gate.EffectiveConcurrency);
}
[Test]
public async Task CancelledQueuedCourseCannotConsumeAConcurrencySlot()
{
using var gate = new AdaptiveCourseGate(1); using var first = await gate.EnterAsync("one", () => { }, CancellationToken.None);
using var cancelled = new CancellationTokenSource(); var queued = gate.EnterAsync("cancel", () => { }, cancelled.Token); cancelled.Cancel();
try { await queued; throw new Exception("Expected cancellation"); } catch (OperationCanceledException) { }
first.Dispose(); using var next = await gate.EnterAsync("next", () => { }, CancellationToken.None).WaitAsync(TimeSpan.FromSeconds(3));
}
}