-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Copy pathReminderTests_AzureTable.cs
357 lines (298 loc) · 15.6 KB
/
ReminderTests_AzureTable.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
using Orleans.Runtime;
using Orleans.TestingHost;
using UnitTests.GrainInterfaces;
using Xunit;
using Microsoft.Extensions.Logging;
using UnitTests.TimerTests;
using Orleans.Internal;
// ReSharper disable InconsistentNaming
// ReSharper disable UnusedVariable
namespace Tester.AzureUtils.TimerTests
{
[TestCategory("Reminders"), TestCategory("AzureStorage")]
public class ReminderTests_AzureTable : ReminderTests_Base, IClassFixture<ReminderTests_AzureTable.Fixture>
{
public class Fixture : BaseAzureTestClusterFixture
{
protected override void ConfigureTestCluster(TestClusterBuilder builder)
{
builder.AddSiloBuilderConfigurator<SiloConfigurator>();
}
}
public class SiloConfigurator : ISiloConfigurator
{
public void Configure(ISiloBuilder hostBuilder)
{
hostBuilder.UseAzureTableReminderService(options =>
{
options.ConfigureTestDefaults();
});
}
}
public ReminderTests_AzureTable(Fixture fixture) : base(fixture)
{
fixture.EnsurePreconditionsMet();
}
// Basic tests
[SkippableFact, TestCategory("Functional")]
public async Task Rem_Azure_Basic_StopByRef()
{
await Test_Reminders_Basic_StopByRef();
}
[SkippableFact, TestCategory("Functional")]
public async Task Rem_Azure_Basic_ListOps()
{
await Test_Reminders_Basic_ListOps();
}
// Single join tests ... multi grain, multi reminders
[SkippableFact, TestCategory("Functional")]
public async Task Rem_Azure_1J_MultiGrainMultiReminders()
{
await Test_Reminders_1J_MultiGrainMultiReminders();
}
[SkippableFact, TestCategory("Functional")]
public async Task Rem_Azure_ReminderNotFound()
{
await Test_Reminders_ReminderNotFound();
}
[SkippableFact, TestCategory("Functional")]
public async Task Rem_Azure_Basic()
{
// start up a test grain and get the period that it's programmed to use.
IReminderTestGrain2 grain = this.GrainFactory.GetGrain<IReminderTestGrain2>(Guid.NewGuid());
TimeSpan period = await grain.GetReminderPeriod(DR);
// start up the 'DR' reminder and wait for two ticks to pass.
await grain.StartReminder(DR);
Thread.Sleep(period.Multiply(2) + LEEWAY); // giving some leeway
// retrieve the value of the counter-- it should match the sequence number which is the number of periods
// we've waited.
long last = await grain.GetCounter(DR);
Assert.Equal(2, last);
// stop the timer and wait for a whole period.
await grain.StopReminder(DR);
Thread.Sleep(period.Multiply(1) + LEEWAY); // giving some leeway
// the counter should not have changed.
long curr = await grain.GetCounter(DR);
Assert.Equal(last, curr);
}
[SkippableFact, TestCategory("Functional")]
public async Task Rem_Azure_Basic_Restart()
{
IReminderTestGrain2 grain = this.GrainFactory.GetGrain<IReminderTestGrain2>(Guid.NewGuid());
TimeSpan period = await grain.GetReminderPeriod(DR);
await grain.StartReminder(DR);
Thread.Sleep(period.Multiply(2) + LEEWAY); // giving some leeway
long last = await grain.GetCounter(DR);
Assert.Equal(2, last);
await grain.StopReminder(DR);
TimeSpan sleepFor = period.Multiply(1) + LEEWAY;
Thread.Sleep(sleepFor); // giving some leeway
long curr = await grain.GetCounter(DR);
Assert.Equal(last, curr);
AssertIsInRange(curr, last, last + 1, grain, DR, sleepFor);
// start the same reminder again
await grain.StartReminder(DR);
sleepFor = period.Multiply(2) + LEEWAY;
Thread.Sleep(sleepFor); // giving some leeway
curr = await grain.GetCounter(DR);
AssertIsInRange(curr, 2, 3, grain, DR, sleepFor);
await grain.StopReminder(DR); // cleanup
}
[SkippableFact, TestCategory("Functional")]
public async Task Rem_Azure_MultipleReminders()
{
IReminderTestGrain2 grain = this.GrainFactory.GetGrain<IReminderTestGrain2>(Guid.NewGuid());
await PerGrainMultiReminderTest(grain);
}
[SkippableFact, TestCategory("Functional")]
public async Task Rem_Azure_2J_MultiGrainMultiReminders()
{
IReminderTestGrain2 g1 = this.GrainFactory.GetGrain<IReminderTestGrain2>(Guid.NewGuid());
IReminderTestGrain2 g2 = this.GrainFactory.GetGrain<IReminderTestGrain2>(Guid.NewGuid());
IReminderTestGrain2 g3 = this.GrainFactory.GetGrain<IReminderTestGrain2>(Guid.NewGuid());
IReminderTestGrain2 g4 = this.GrainFactory.GetGrain<IReminderTestGrain2>(Guid.NewGuid());
IReminderTestGrain2 g5 = this.GrainFactory.GetGrain<IReminderTestGrain2>(Guid.NewGuid());
TimeSpan period = await g1.GetReminderPeriod(DR);
Task<bool>[] tasks =
{
Task.Run(() => PerGrainMultiReminderTestChurn(g1)),
Task.Run(() => PerGrainMultiReminderTestChurn(g2)),
Task.Run(() => PerGrainMultiReminderTestChurn(g3)),
Task.Run(() => PerGrainMultiReminderTestChurn(g4)),
Task.Run(() => PerGrainMultiReminderTestChurn(g5)),
};
await Task.Delay(period.Multiply(5));
// start two extra silos ... although it will take it a while before they stabilize
log.LogInformation("Starting 2 extra silos");
await this.HostedCluster.StartAdditionalSilosAsync(2, true);
await this.HostedCluster.WaitForLivenessToStabilizeAsync();
//Block until all tasks complete.
await Task.WhenAll(tasks).WaitAsync(ENDWAIT);
}
[SkippableFact, TestCategory("Functional")]
public async Task Rem_Azure_MultiGrainMultiReminders()
{
IReminderTestGrain2 g1 = this.GrainFactory.GetGrain<IReminderTestGrain2>(Guid.NewGuid());
IReminderTestGrain2 g2 = this.GrainFactory.GetGrain<IReminderTestGrain2>(Guid.NewGuid());
IReminderTestGrain2 g3 = this.GrainFactory.GetGrain<IReminderTestGrain2>(Guid.NewGuid());
IReminderTestGrain2 g4 = this.GrainFactory.GetGrain<IReminderTestGrain2>(Guid.NewGuid());
IReminderTestGrain2 g5 = this.GrainFactory.GetGrain<IReminderTestGrain2>(Guid.NewGuid());
Task<bool>[] tasks =
{
Task.Run(() => PerGrainMultiReminderTest(g1)),
Task.Run(() => PerGrainMultiReminderTest(g2)),
Task.Run(() => PerGrainMultiReminderTest(g3)),
Task.Run(() => PerGrainMultiReminderTest(g4)),
Task.Run(() => PerGrainMultiReminderTest(g5)),
};
//Block until all tasks complete.
await Task.WhenAll(tasks).WaitAsync(ENDWAIT);
}
[SkippableFact, TestCategory("Functional")]
public async Task Rem_Azure_1F_Basic()
{
IReminderTestGrain2 g1 = this.GrainFactory.GetGrain<IReminderTestGrain2>(Guid.NewGuid());
TimeSpan period = await g1.GetReminderPeriod(DR);
Task<bool> test = Task.Run(async () => { await PerGrainFailureTest(g1); return true; });
Thread.Sleep(period.Multiply(failAfter));
// stop the secondary silo
log.LogInformation("Stopping secondary silo");
await this.HostedCluster.StopSiloAsync(this.HostedCluster.SecondarySilos.First());
await test; // Block until test completes.
}
[SkippableFact, TestCategory("Functional")]
public async Task Rem_Azure_2F_MultiGrain()
{
List<SiloHandle> silos = await this.HostedCluster.StartAdditionalSilosAsync(2,true);
IReminderTestGrain2 g1 = this.GrainFactory.GetGrain<IReminderTestGrain2>(Guid.NewGuid());
IReminderTestGrain2 g2 = this.GrainFactory.GetGrain<IReminderTestGrain2>(Guid.NewGuid());
IReminderTestGrain2 g3 = this.GrainFactory.GetGrain<IReminderTestGrain2>(Guid.NewGuid());
IReminderTestGrain2 g4 = this.GrainFactory.GetGrain<IReminderTestGrain2>(Guid.NewGuid());
IReminderTestGrain2 g5 = this.GrainFactory.GetGrain<IReminderTestGrain2>(Guid.NewGuid());
TimeSpan period = await g1.GetReminderPeriod(DR);
Task[] tasks =
{
Task.Run(() => PerGrainFailureTest(g1)),
Task.Run(() => PerGrainFailureTest(g2)),
Task.Run(() => PerGrainFailureTest(g3)),
Task.Run(() => PerGrainFailureTest(g4)),
Task.Run(() => PerGrainFailureTest(g5)),
};
Thread.Sleep(period.Multiply(failAfter));
// stop a couple of silos
log.LogInformation("Stopping 2 silos");
int i = Random.Shared.Next(silos.Count);
await this.HostedCluster.StopSiloAsync(silos[i]);
silos.RemoveAt(i);
await this.HostedCluster.StopSiloAsync(silos[Random.Shared.Next(silos.Count)]);
await Task.WhenAll(tasks).WaitAsync(ENDWAIT); // Block until all tasks complete.
}
[SkippableFact, TestCategory("Functional")]
public async Task Rem_Azure_1F1J_MultiGrain()
{
List<SiloHandle> silos = await this.HostedCluster.StartAdditionalSilosAsync(1);
await this.HostedCluster.WaitForLivenessToStabilizeAsync();
IReminderTestGrain2 g1 = this.GrainFactory.GetGrain<IReminderTestGrain2>(Guid.NewGuid());
IReminderTestGrain2 g2 = this.GrainFactory.GetGrain<IReminderTestGrain2>(Guid.NewGuid());
IReminderTestGrain2 g3 = this.GrainFactory.GetGrain<IReminderTestGrain2>(Guid.NewGuid());
IReminderTestGrain2 g4 = this.GrainFactory.GetGrain<IReminderTestGrain2>(Guid.NewGuid());
IReminderTestGrain2 g5 = this.GrainFactory.GetGrain<IReminderTestGrain2>(Guid.NewGuid());
TimeSpan period = await g1.GetReminderPeriod(DR);
Task[] tasks =
{
Task.Run(() => PerGrainFailureTest(g1)),
Task.Run(() => PerGrainFailureTest(g2)),
Task.Run(() => PerGrainFailureTest(g3)),
Task.Run(() => PerGrainFailureTest(g4)),
Task.Run(() => PerGrainFailureTest(g5)),
};
Thread.Sleep(period.Multiply(failAfter));
var siloToKill = silos[Random.Shared.Next(silos.Count)];
// stop a silo and join a new one in parallel
log.LogInformation("Stopping a silo and joining a silo");
Task t1 = Task.Factory.StartNew(async () => await this.HostedCluster.StopSiloAsync(siloToKill));
Task t2 = this.HostedCluster.StartAdditionalSilosAsync(1, true).ContinueWith(t =>
{
t.GetAwaiter().GetResult();
});
await Task.WhenAll(new[] { t1, t2 }).WaitAsync(ENDWAIT);
await Task.WhenAll(tasks).WaitAsync(ENDWAIT); // Block until all tasks complete.
log.LogInformation("\n\n\nReminderTest_1F1J_MultiGrain passed OK.\n\n\n");
}
[SkippableFact, TestCategory("Functional")]
public async Task Rem_Azure_RegisterSameReminderTwice()
{
IReminderTestGrain2 grain = this.GrainFactory.GetGrain<IReminderTestGrain2>(Guid.NewGuid());
Task<IGrainReminder> promise1 = grain.StartReminder(DR);
Task<IGrainReminder> promise2 = grain.StartReminder(DR);
Task<IGrainReminder>[] tasks = { promise1, promise2 };
await Task.WhenAll(tasks).WaitAsync(TimeSpan.FromSeconds(15));
//Assert.NotEqual(promise1.Result, promise2.Result);
// TODO: write tests where period of a reminder is changed
}
[SkippableFact, TestCategory("Functional")]
public async Task Rem_Azure_GT_Basic()
{
IReminderTestGrain2 g1 = this.GrainFactory.GetGrain<IReminderTestGrain2>(Guid.NewGuid());
IReminderTestCopyGrain g2 = this.GrainFactory.GetGrain<IReminderTestCopyGrain>(Guid.NewGuid());
TimeSpan period = await g1.GetReminderPeriod(DR); // using same period
await g1.StartReminder(DR);
Thread.Sleep(period.Multiply(2) + LEEWAY); // giving some leeway
await g2.StartReminder(DR);
Thread.Sleep(period.Multiply(2) + LEEWAY); // giving some leeway
long last1 = await g1.GetCounter(DR);
Assert.Equal(4, last1);
long last2 = await g2.GetCounter(DR);
Assert.Equal(2, last2); // CopyGrain fault
await g1.StopReminder(DR);
Thread.Sleep(period.Multiply(2) + LEEWAY); // giving some leeway
await g2.StopReminder(DR);
long curr1 = await g1.GetCounter(DR);
Assert.Equal(last1, curr1);
long curr2 = await g2.GetCounter(DR);
Assert.Equal(4, curr2); // CopyGrain fault
}
[SkippableFact(Skip = "/~https://github.com/dotnet/orleans/issues/4319"), TestCategory("Functional")]
public async Task Rem_Azure_GT_1F1J_MultiGrain()
{
List<SiloHandle> silos = await this.HostedCluster.StartAdditionalSilosAsync(1);
await this.HostedCluster.WaitForLivenessToStabilizeAsync();
IReminderTestGrain2 g1 = this.GrainFactory.GetGrain<IReminderTestGrain2>(Guid.NewGuid());
IReminderTestGrain2 g2 = this.GrainFactory.GetGrain<IReminderTestGrain2>(Guid.NewGuid());
IReminderTestCopyGrain g3 = this.GrainFactory.GetGrain<IReminderTestCopyGrain>(Guid.NewGuid());
IReminderTestCopyGrain g4 = this.GrainFactory.GetGrain<IReminderTestCopyGrain>(Guid.NewGuid());
TimeSpan period = await g1.GetReminderPeriod(DR);
Task[] tasks =
{
Task.Run(() => PerGrainFailureTest(g1)),
Task.Run(() => PerGrainFailureTest(g2)),
Task.Run(() => PerCopyGrainFailureTest(g3)),
Task.Run(() => PerCopyGrainFailureTest(g4)),
};
Thread.Sleep(period.Multiply(failAfter));
var siloToKill = silos[Random.Shared.Next(silos.Count)];
// stop a silo and join a new one in parallel
log.LogInformation("Stopping a silo and joining a silo");
Task t1 = Task.Run(async () => await this.HostedCluster.StopSiloAsync(siloToKill));
Task t2 = Task.Run(async () => await this.HostedCluster.StartAdditionalSilosAsync(1));
await Task.WhenAll(new[] { t1, t2 }).WaitAsync(ENDWAIT);
await Task.WhenAll(tasks).WaitAsync(ENDWAIT); // Block until all tasks complete.
}
[SkippableFact, TestCategory("Functional")]
public async Task Rem_Azure_Wrong_LowerThanAllowedPeriod()
{
IReminderTestGrain2 grain = this.GrainFactory.GetGrain<IReminderTestGrain2>(Guid.NewGuid());
await Assert.ThrowsAsync<ArgumentException>(() =>
grain.StartReminder(DR, TimeSpan.FromMilliseconds(3000), true));
}
[SkippableFact, TestCategory("Functional")]
public async Task Rem_Azure_Wrong_Grain()
{
IReminderGrainWrong grain = this.GrainFactory.GetGrain<IReminderGrainWrong>(0);
await Assert.ThrowsAsync<InvalidOperationException>(() =>
grain.StartReminder(DR));
}
}
}
// ReSharper restore InconsistentNaming
// ReSharper restore UnusedVariable