Dreamine.FullKit.Tests 1.0.0.0
Dreamine.FullKit.Tests 기능을 검증하는 자동화 테스트 프로젝트입니다.
로딩중...
검색중...
일치하는것 없음
ThreadingPolicyTests.cs
이 파일의 문서화 페이지로 가기
1using Dreamine.Threading.Interfaces;
2using Dreamine.Threading.Models;
3using Dreamine.Threading.Options;
4using Dreamine.Threading.Policies;
5using Dreamine.Threading.Registration;
6using Dreamine.MVVM.Core;
8
10
19[Collection(DMContainerCollection.Name)]
20public sealed class ThreadingPolicyTests
21{
30 [Fact]
32 {
33 var options = new DreamineThreadOptions
34 {
35 Name = "",
36 IntervalMs = -5,
37 AutoThreadsPerCore = 0,
38 OverflowPollingIntervalMs = -1
39 }.Normalize();
40
41 Assert.Equal("DreamineThread", options.Name);
42 Assert.Equal(10, options.IntervalMs);
43 Assert.Equal(2, options.AutoThreadsPerCore);
44 Assert.Equal(100, options.OverflowPollingIntervalMs);
45 }
46
55 [Fact]
57 {
58 var options = new DreamineThreadJobOptions
59 {
60 Name = " ",
61 IntervalMs = -1
62 }.Normalize();
63
64 Assert.Equal("DreamineThreadJob", options.Name);
65 Assert.Equal(10, options.IntervalMs);
66 }
67
76 [Fact]
78 {
79 var options = new DreamineThreadOptions { IntervalMs = 25, OverflowPollingIntervalMs = 80 };
80 var context = new DreamineThreadCycleContext("worker", 1, 1, null, false, DateTimeOffset.UtcNow);
81
82 Assert.Equal(25, new FixedIntervalCyclePolicy().GetDelayMs(options, DreamineThreadCoreAssignment.None(), context));
83 Assert.Equal(80, new FixedIntervalCyclePolicy().GetDelayMs(options, DreamineThreadCoreAssignment.Overflow(), context));
84 Assert.Equal(80, new OverflowPollingPolicy().GetDelayMs(options, DreamineThreadCoreAssignment.None(), context));
85 }
86
111 [Theory]
112 [InlineData(10, 0)]
113 [InlineData(30, 1)]
114 [InlineData(50, 3)]
115 [InlineData(70, 5)]
116 public void AdaptiveCpuPolicy_ReturnsDelayByCpuUsage(double cpuUsage, int expectedDelay)
117 {
118 var policy = new AdaptiveCpuCyclePolicy(new CpuUsageProvider(cpuUsage));
119 var options = new DreamineThreadOptions { IntervalMs = 0, UseAdaptiveCpuDelay = true };
120 var context = new DreamineThreadCycleContext("worker", 1, 1, null, false, DateTimeOffset.UtcNow);
121
122 var delay = policy.GetDelayMs(options, DreamineThreadCoreAssignment.None(), context);
123
124 Assert.Equal(expectedDelay, delay);
125 }
126
135 [Fact]
137 {
138 Assert.False(DreamineThreadCoreAssignment.None().UseAffinity);
139 Assert.True(DreamineThreadCoreAssignment.Dedicated(2, true).IsDedicatedWorker);
140 Assert.True(DreamineThreadCoreAssignment.Overflow().IsOverflowPolling);
141 Assert.True(new DreamineThreadingOptions().RegisterWindowsServices);
142 }
143
152 [Fact]
154 {
155 DMContainer.Reset();
156
157 try
158 {
159 DreamineThreadingRegistration.Register(new DreamineThreadingOptions
160 {
161 UseAdaptiveCpuPolicy = true
162 });
163
164 Assert.IsType<FixedIntervalCyclePolicy>(
165 DMContainer.Resolve<IThreadCyclePolicy>());
166 Assert.NotNull(DMContainer.Resolve<IDreamineThreadManager>());
167 }
168 finally
169 {
170 DMContainer.Reset();
171 }
172 }
173
182 [Fact]
184 {
185 var options = new DreamineThreadOptions
186 {
187 StopTimeout = TimeSpan.Zero
188 }.Normalize();
189
190 Assert.Equal(TimeSpan.FromSeconds(2), options.StopTimeout);
191 }
192
201 private sealed class CpuUsageProvider : ICpuUsageProvider
202 {
211 private readonly double _cpuUsage;
212
229 public CpuUsageProvider(double cpuUsage)
230 {
231 _cpuUsage = cpuUsage;
232 }
233
251 {
252 return _cpuUsage;
253 }
254 }
255}
void AdaptiveCpuPolicy_ReturnsDelayByCpuUsage(double cpuUsage, int expectedDelay)