com.wallstop-studios.dxmessaging 2.1.3 → 2.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/dotnet-tests.yml +2 -2
- package/.github/workflows/prettier-autofix.yml +0 -7
- package/.pre-commit-config.yaml +8 -5
- package/CONTRIBUTING.md +8 -2
- package/Docs/Performance.md +11 -11
- package/Runtime/Core/MessageBus/MessageBus.cs +75 -159
- package/Tests/Runtime/Core/Extensions/MessageBusExtensionsTests.cs +12 -31
- package/Tests/Runtime/Core/OrderingManyRegistrationsTests.cs +683 -0
- package/Tests/Runtime/Core/OrderingManyRegistrationsTests.cs.meta +11 -0
- package/package.json +1 -1
- package/scripts/fix-eol.js +38 -3
|
@@ -0,0 +1,683 @@
|
|
|
1
|
+
#if UNITY_2021_3_OR_NEWER
|
|
2
|
+
namespace DxMessaging.Tests.Runtime.Core
|
|
3
|
+
{
|
|
4
|
+
using System.Collections;
|
|
5
|
+
using System.Collections.Generic;
|
|
6
|
+
using DxMessaging.Core;
|
|
7
|
+
using DxMessaging.Core.Extensions;
|
|
8
|
+
using DxMessaging.Core.Messages;
|
|
9
|
+
using DxMessaging.Tests.Runtime.Scripts.Components;
|
|
10
|
+
using DxMessaging.Tests.Runtime.Scripts.Messages;
|
|
11
|
+
using NUnit.Framework;
|
|
12
|
+
using UnityEngine;
|
|
13
|
+
using UnityEngine.TestTools;
|
|
14
|
+
|
|
15
|
+
public sealed class OrderingManyRegistrationsTests : MessagingTestBase
|
|
16
|
+
{
|
|
17
|
+
private const int ManyRegistrationCount = 32;
|
|
18
|
+
|
|
19
|
+
private static int[] BuildSequentialExpected(int count)
|
|
20
|
+
{
|
|
21
|
+
int[] expected = new int[count];
|
|
22
|
+
for (int i = 0; i < count; i++)
|
|
23
|
+
{
|
|
24
|
+
expected[i] = i;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return expected;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
private static void AssertSequence(IList<int> actual, string message)
|
|
31
|
+
{
|
|
32
|
+
int[] expected = BuildSequentialExpected(actual.Count);
|
|
33
|
+
int[] actualCopy = new int[actual.Count];
|
|
34
|
+
for (int i = 0; i < actual.Count; i++)
|
|
35
|
+
{
|
|
36
|
+
actualCopy[i] = actual[i];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
Assert.AreEqual(expected, actualCopy, message);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
[UnityTest]
|
|
43
|
+
public IEnumerator UntargetedHandlersManyRegistrationsMaintainOrder()
|
|
44
|
+
{
|
|
45
|
+
GameObject host = new(
|
|
46
|
+
nameof(UntargetedHandlersManyRegistrationsMaintainOrder),
|
|
47
|
+
typeof(EmptyMessageAwareComponent)
|
|
48
|
+
);
|
|
49
|
+
_spawned.Add(host);
|
|
50
|
+
EmptyMessageAwareComponent component = host.GetComponent<EmptyMessageAwareComponent>();
|
|
51
|
+
MessageRegistrationToken token = GetToken(component);
|
|
52
|
+
|
|
53
|
+
List<int> fastOrder = new(ManyRegistrationCount);
|
|
54
|
+
List<int> actionOrder = new(ManyRegistrationCount);
|
|
55
|
+
|
|
56
|
+
for (int i = 0; i < ManyRegistrationCount; i++)
|
|
57
|
+
{
|
|
58
|
+
int index = i;
|
|
59
|
+
_ = token.RegisterUntargeted(
|
|
60
|
+
(ref SimpleUntargetedMessage _) => fastOrder.Add(index)
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
for (int i = 0; i < ManyRegistrationCount; i++)
|
|
65
|
+
{
|
|
66
|
+
int index = i;
|
|
67
|
+
_ = token.RegisterUntargeted((SimpleUntargetedMessage _) => actionOrder.Add(index));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
SimpleUntargetedMessage message = new();
|
|
71
|
+
message.EmitUntargeted();
|
|
72
|
+
|
|
73
|
+
AssertSequence(
|
|
74
|
+
fastOrder,
|
|
75
|
+
"Untargeted fast handlers should run in registration order even with many entries."
|
|
76
|
+
);
|
|
77
|
+
AssertSequence(
|
|
78
|
+
actionOrder,
|
|
79
|
+
"Untargeted action handlers should run in registration order even with many entries."
|
|
80
|
+
);
|
|
81
|
+
yield break;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
[UnityTest]
|
|
85
|
+
public IEnumerator UntargetedPostProcessorsManyRegistrationsMaintainOrder()
|
|
86
|
+
{
|
|
87
|
+
GameObject host = new(
|
|
88
|
+
nameof(UntargetedPostProcessorsManyRegistrationsMaintainOrder),
|
|
89
|
+
typeof(EmptyMessageAwareComponent)
|
|
90
|
+
);
|
|
91
|
+
_spawned.Add(host);
|
|
92
|
+
EmptyMessageAwareComponent component = host.GetComponent<EmptyMessageAwareComponent>();
|
|
93
|
+
MessageRegistrationToken token = GetToken(component);
|
|
94
|
+
|
|
95
|
+
List<int> postProcessorOrder = new(ManyRegistrationCount);
|
|
96
|
+
|
|
97
|
+
for (int i = 0; i < ManyRegistrationCount; i++)
|
|
98
|
+
{
|
|
99
|
+
int index = i;
|
|
100
|
+
_ = token.RegisterUntargetedPostProcessor(
|
|
101
|
+
(ref SimpleUntargetedMessage _) => postProcessorOrder.Add(index)
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
SimpleUntargetedMessage message = new();
|
|
106
|
+
message.EmitUntargeted();
|
|
107
|
+
|
|
108
|
+
AssertSequence(
|
|
109
|
+
postProcessorOrder,
|
|
110
|
+
"Untargeted post-processors should run in registration order even with many entries."
|
|
111
|
+
);
|
|
112
|
+
yield break;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
[UnityTest]
|
|
116
|
+
public IEnumerator TargetedHandlersManyRegistrationsMaintainOrder()
|
|
117
|
+
{
|
|
118
|
+
GameObject host = new(
|
|
119
|
+
nameof(TargetedHandlersManyRegistrationsMaintainOrder),
|
|
120
|
+
typeof(EmptyMessageAwareComponent)
|
|
121
|
+
);
|
|
122
|
+
_spawned.Add(host);
|
|
123
|
+
EmptyMessageAwareComponent component = host.GetComponent<EmptyMessageAwareComponent>();
|
|
124
|
+
MessageRegistrationToken token = GetToken(component);
|
|
125
|
+
|
|
126
|
+
List<int> fastOrder = new(ManyRegistrationCount);
|
|
127
|
+
List<int> actionOrder = new(ManyRegistrationCount);
|
|
128
|
+
|
|
129
|
+
for (int i = 0; i < ManyRegistrationCount; i++)
|
|
130
|
+
{
|
|
131
|
+
int index = i;
|
|
132
|
+
_ = token.RegisterComponentTargeted(
|
|
133
|
+
component,
|
|
134
|
+
(ref SimpleTargetedMessage _) => fastOrder.Add(index)
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
for (int i = 0; i < ManyRegistrationCount; i++)
|
|
139
|
+
{
|
|
140
|
+
int index = i;
|
|
141
|
+
_ = token.RegisterComponentTargeted(
|
|
142
|
+
component,
|
|
143
|
+
(SimpleTargetedMessage _) => actionOrder.Add(index)
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
SimpleTargetedMessage message = new();
|
|
148
|
+
message.EmitComponentTargeted(component);
|
|
149
|
+
|
|
150
|
+
AssertSequence(
|
|
151
|
+
fastOrder,
|
|
152
|
+
"Targeted fast handlers should run in registration order even with many entries."
|
|
153
|
+
);
|
|
154
|
+
AssertSequence(
|
|
155
|
+
actionOrder,
|
|
156
|
+
"Targeted action handlers should run in registration order even with many entries."
|
|
157
|
+
);
|
|
158
|
+
yield break;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
[UnityTest]
|
|
162
|
+
public IEnumerator TargetedPostProcessorsManyRegistrationsMaintainOrder()
|
|
163
|
+
{
|
|
164
|
+
GameObject host = new(
|
|
165
|
+
nameof(TargetedPostProcessorsManyRegistrationsMaintainOrder),
|
|
166
|
+
typeof(EmptyMessageAwareComponent)
|
|
167
|
+
);
|
|
168
|
+
_spawned.Add(host);
|
|
169
|
+
EmptyMessageAwareComponent component = host.GetComponent<EmptyMessageAwareComponent>();
|
|
170
|
+
MessageRegistrationToken token = GetToken(component);
|
|
171
|
+
|
|
172
|
+
List<int> fastOrder = new(ManyRegistrationCount);
|
|
173
|
+
List<int> actionOrder = new(ManyRegistrationCount);
|
|
174
|
+
|
|
175
|
+
InstanceId target = component;
|
|
176
|
+
|
|
177
|
+
for (int i = 0; i < ManyRegistrationCount; i++)
|
|
178
|
+
{
|
|
179
|
+
int index = i;
|
|
180
|
+
_ = token.RegisterTargetedPostProcessor(
|
|
181
|
+
target,
|
|
182
|
+
(ref SimpleTargetedMessage _) => fastOrder.Add(index)
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
for (int i = 0; i < ManyRegistrationCount; i++)
|
|
187
|
+
{
|
|
188
|
+
int index = i;
|
|
189
|
+
_ = token.RegisterTargetedPostProcessor(
|
|
190
|
+
target,
|
|
191
|
+
(SimpleTargetedMessage _) => actionOrder.Add(index)
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
SimpleTargetedMessage message = new();
|
|
196
|
+
message.EmitComponentTargeted(component);
|
|
197
|
+
|
|
198
|
+
AssertSequence(
|
|
199
|
+
fastOrder,
|
|
200
|
+
"Targeted fast post-processors should run in registration order even with many entries."
|
|
201
|
+
);
|
|
202
|
+
AssertSequence(
|
|
203
|
+
actionOrder,
|
|
204
|
+
"Targeted action post-processors should run in registration order even with many entries."
|
|
205
|
+
);
|
|
206
|
+
yield break;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
[UnityTest]
|
|
210
|
+
public IEnumerator TargetedWithoutTargetingManyRegistrationsMaintainOrder()
|
|
211
|
+
{
|
|
212
|
+
GameObject host = new(
|
|
213
|
+
nameof(TargetedWithoutTargetingManyRegistrationsMaintainOrder),
|
|
214
|
+
typeof(EmptyMessageAwareComponent)
|
|
215
|
+
);
|
|
216
|
+
_spawned.Add(host);
|
|
217
|
+
EmptyMessageAwareComponent component = host.GetComponent<EmptyMessageAwareComponent>();
|
|
218
|
+
MessageRegistrationToken token = GetToken(component);
|
|
219
|
+
|
|
220
|
+
List<int> fastOrder = new(ManyRegistrationCount);
|
|
221
|
+
List<int> actionOrder = new(ManyRegistrationCount);
|
|
222
|
+
|
|
223
|
+
for (int i = 0; i < ManyRegistrationCount; i++)
|
|
224
|
+
{
|
|
225
|
+
int index = i;
|
|
226
|
+
_ = token.RegisterTargetedWithoutTargeting(
|
|
227
|
+
(ref InstanceId _, ref SimpleTargetedMessage _) => fastOrder.Add(index)
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
for (int i = 0; i < ManyRegistrationCount; i++)
|
|
232
|
+
{
|
|
233
|
+
int index = i;
|
|
234
|
+
_ = token.RegisterTargetedWithoutTargeting(
|
|
235
|
+
(InstanceId _, SimpleTargetedMessage _) => actionOrder.Add(index)
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
SimpleTargetedMessage message = new();
|
|
240
|
+
message.EmitComponentTargeted(component);
|
|
241
|
+
|
|
242
|
+
AssertSequence(
|
|
243
|
+
fastOrder,
|
|
244
|
+
"Targeted-without-targeting fast handlers should run in registration order even with many entries."
|
|
245
|
+
);
|
|
246
|
+
AssertSequence(
|
|
247
|
+
actionOrder,
|
|
248
|
+
"Targeted-without-targeting action handlers should run in registration order even with many entries."
|
|
249
|
+
);
|
|
250
|
+
yield break;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
[UnityTest]
|
|
254
|
+
public IEnumerator TargetedWithoutTargetingPostProcessorsManyRegistrationsMaintainOrder()
|
|
255
|
+
{
|
|
256
|
+
GameObject host = new(
|
|
257
|
+
nameof(TargetedWithoutTargetingPostProcessorsManyRegistrationsMaintainOrder),
|
|
258
|
+
typeof(EmptyMessageAwareComponent)
|
|
259
|
+
);
|
|
260
|
+
_spawned.Add(host);
|
|
261
|
+
EmptyMessageAwareComponent component = host.GetComponent<EmptyMessageAwareComponent>();
|
|
262
|
+
MessageRegistrationToken token = GetToken(component);
|
|
263
|
+
|
|
264
|
+
List<int> fastOrder = new(ManyRegistrationCount);
|
|
265
|
+
List<int> actionOrder = new(ManyRegistrationCount);
|
|
266
|
+
|
|
267
|
+
for (int i = 0; i < ManyRegistrationCount; i++)
|
|
268
|
+
{
|
|
269
|
+
int index = i;
|
|
270
|
+
_ = token.RegisterTargetedWithoutTargetingPostProcessor(
|
|
271
|
+
(ref InstanceId _, ref SimpleTargetedMessage _) => fastOrder.Add(index)
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
for (int i = 0; i < ManyRegistrationCount; i++)
|
|
276
|
+
{
|
|
277
|
+
int index = i;
|
|
278
|
+
_ = token.RegisterTargetedWithoutTargetingPostProcessor(
|
|
279
|
+
(InstanceId _, SimpleTargetedMessage _) => actionOrder.Add(index)
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
SimpleTargetedMessage message = new();
|
|
284
|
+
message.EmitComponentTargeted(component);
|
|
285
|
+
|
|
286
|
+
AssertSequence(
|
|
287
|
+
fastOrder,
|
|
288
|
+
"Targeted-without-targeting fast post-processors should run in registration order even with many entries."
|
|
289
|
+
);
|
|
290
|
+
AssertSequence(
|
|
291
|
+
actionOrder,
|
|
292
|
+
"Targeted-without-targeting action post-processors should run in registration order even with many entries."
|
|
293
|
+
);
|
|
294
|
+
yield break;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
[UnityTest]
|
|
298
|
+
public IEnumerator BroadcastHandlersManyRegistrationsMaintainOrder()
|
|
299
|
+
{
|
|
300
|
+
GameObject host = new(
|
|
301
|
+
nameof(BroadcastHandlersManyRegistrationsMaintainOrder),
|
|
302
|
+
typeof(EmptyMessageAwareComponent)
|
|
303
|
+
);
|
|
304
|
+
_spawned.Add(host);
|
|
305
|
+
EmptyMessageAwareComponent component = host.GetComponent<EmptyMessageAwareComponent>();
|
|
306
|
+
MessageRegistrationToken token = GetToken(component);
|
|
307
|
+
|
|
308
|
+
List<int> fastOrder = new(ManyRegistrationCount);
|
|
309
|
+
List<int> actionOrder = new(ManyRegistrationCount);
|
|
310
|
+
|
|
311
|
+
for (int i = 0; i < ManyRegistrationCount; i++)
|
|
312
|
+
{
|
|
313
|
+
int index = i;
|
|
314
|
+
_ = token.RegisterComponentBroadcast(
|
|
315
|
+
component,
|
|
316
|
+
(ref SimpleBroadcastMessage _) => fastOrder.Add(index)
|
|
317
|
+
);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
for (int i = 0; i < ManyRegistrationCount; i++)
|
|
321
|
+
{
|
|
322
|
+
int index = i;
|
|
323
|
+
_ = token.RegisterComponentBroadcast(
|
|
324
|
+
component,
|
|
325
|
+
(SimpleBroadcastMessage _) => actionOrder.Add(index)
|
|
326
|
+
);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
SimpleBroadcastMessage message = new();
|
|
330
|
+
message.EmitComponentBroadcast(component);
|
|
331
|
+
|
|
332
|
+
AssertSequence(
|
|
333
|
+
fastOrder,
|
|
334
|
+
"Broadcast fast handlers should run in registration order even with many entries."
|
|
335
|
+
);
|
|
336
|
+
AssertSequence(
|
|
337
|
+
actionOrder,
|
|
338
|
+
"Broadcast action handlers should run in registration order even with many entries."
|
|
339
|
+
);
|
|
340
|
+
yield break;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
[UnityTest]
|
|
344
|
+
public IEnumerator BroadcastPostProcessorsManyRegistrationsMaintainOrder()
|
|
345
|
+
{
|
|
346
|
+
GameObject host = new(
|
|
347
|
+
nameof(BroadcastPostProcessorsManyRegistrationsMaintainOrder),
|
|
348
|
+
typeof(EmptyMessageAwareComponent)
|
|
349
|
+
);
|
|
350
|
+
_spawned.Add(host);
|
|
351
|
+
EmptyMessageAwareComponent component = host.GetComponent<EmptyMessageAwareComponent>();
|
|
352
|
+
MessageRegistrationToken token = GetToken(component);
|
|
353
|
+
|
|
354
|
+
List<int> fastOrder = new(ManyRegistrationCount);
|
|
355
|
+
List<int> actionOrder = new(ManyRegistrationCount);
|
|
356
|
+
|
|
357
|
+
InstanceId source = component;
|
|
358
|
+
|
|
359
|
+
for (int i = 0; i < ManyRegistrationCount; i++)
|
|
360
|
+
{
|
|
361
|
+
int index = i;
|
|
362
|
+
_ = token.RegisterBroadcastPostProcessor(
|
|
363
|
+
source,
|
|
364
|
+
(ref SimpleBroadcastMessage _) => fastOrder.Add(index)
|
|
365
|
+
);
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
for (int i = 0; i < ManyRegistrationCount; i++)
|
|
369
|
+
{
|
|
370
|
+
int index = i;
|
|
371
|
+
_ = token.RegisterBroadcastPostProcessor(
|
|
372
|
+
source,
|
|
373
|
+
(SimpleBroadcastMessage _) => actionOrder.Add(index)
|
|
374
|
+
);
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
SimpleBroadcastMessage message = new();
|
|
378
|
+
message.EmitComponentBroadcast(component);
|
|
379
|
+
|
|
380
|
+
AssertSequence(
|
|
381
|
+
fastOrder,
|
|
382
|
+
"Broadcast fast post-processors should run in registration order even with many entries."
|
|
383
|
+
);
|
|
384
|
+
AssertSequence(
|
|
385
|
+
actionOrder,
|
|
386
|
+
"Broadcast action post-processors should run in registration order even with many entries."
|
|
387
|
+
);
|
|
388
|
+
yield break;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
[UnityTest]
|
|
392
|
+
public IEnumerator BroadcastWithoutSourceManyRegistrationsMaintainOrder()
|
|
393
|
+
{
|
|
394
|
+
GameObject host = new(
|
|
395
|
+
nameof(BroadcastWithoutSourceManyRegistrationsMaintainOrder),
|
|
396
|
+
typeof(EmptyMessageAwareComponent)
|
|
397
|
+
);
|
|
398
|
+
_spawned.Add(host);
|
|
399
|
+
EmptyMessageAwareComponent component = host.GetComponent<EmptyMessageAwareComponent>();
|
|
400
|
+
MessageRegistrationToken token = GetToken(component);
|
|
401
|
+
|
|
402
|
+
List<int> fastOrder = new(ManyRegistrationCount);
|
|
403
|
+
List<int> actionOrder = new(ManyRegistrationCount);
|
|
404
|
+
|
|
405
|
+
for (int i = 0; i < ManyRegistrationCount; i++)
|
|
406
|
+
{
|
|
407
|
+
int index = i;
|
|
408
|
+
_ = token.RegisterBroadcastWithoutSource(
|
|
409
|
+
(ref InstanceId _, ref SimpleBroadcastMessage _) => fastOrder.Add(index)
|
|
410
|
+
);
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
for (int i = 0; i < ManyRegistrationCount; i++)
|
|
414
|
+
{
|
|
415
|
+
int index = i;
|
|
416
|
+
_ = token.RegisterBroadcastWithoutSource(
|
|
417
|
+
(InstanceId _, SimpleBroadcastMessage _) => actionOrder.Add(index)
|
|
418
|
+
);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
SimpleBroadcastMessage message = new();
|
|
422
|
+
message.EmitComponentBroadcast(component);
|
|
423
|
+
|
|
424
|
+
AssertSequence(
|
|
425
|
+
fastOrder,
|
|
426
|
+
"Broadcast-without-source fast handlers should run in registration order even with many entries."
|
|
427
|
+
);
|
|
428
|
+
AssertSequence(
|
|
429
|
+
actionOrder,
|
|
430
|
+
"Broadcast-without-source action handlers should run in registration order even with many entries."
|
|
431
|
+
);
|
|
432
|
+
yield break;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
[UnityTest]
|
|
436
|
+
public IEnumerator BroadcastWithoutSourcePostProcessorsManyRegistrationsMaintainOrder()
|
|
437
|
+
{
|
|
438
|
+
GameObject host = new(
|
|
439
|
+
nameof(BroadcastWithoutSourcePostProcessorsManyRegistrationsMaintainOrder),
|
|
440
|
+
typeof(EmptyMessageAwareComponent)
|
|
441
|
+
);
|
|
442
|
+
_spawned.Add(host);
|
|
443
|
+
EmptyMessageAwareComponent component = host.GetComponent<EmptyMessageAwareComponent>();
|
|
444
|
+
MessageRegistrationToken token = GetToken(component);
|
|
445
|
+
|
|
446
|
+
List<int> fastOrder = new(ManyRegistrationCount);
|
|
447
|
+
List<int> actionOrder = new(ManyRegistrationCount);
|
|
448
|
+
|
|
449
|
+
for (int i = 0; i < ManyRegistrationCount; i++)
|
|
450
|
+
{
|
|
451
|
+
int index = i;
|
|
452
|
+
_ = token.RegisterBroadcastWithoutSourcePostProcessor(
|
|
453
|
+
(ref InstanceId _, ref SimpleBroadcastMessage _) => fastOrder.Add(index)
|
|
454
|
+
);
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
for (int i = 0; i < ManyRegistrationCount; i++)
|
|
458
|
+
{
|
|
459
|
+
int index = i;
|
|
460
|
+
_ = token.RegisterBroadcastWithoutSourcePostProcessor(
|
|
461
|
+
(InstanceId _, SimpleBroadcastMessage _) => actionOrder.Add(index)
|
|
462
|
+
);
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
SimpleBroadcastMessage message = new();
|
|
466
|
+
message.EmitComponentBroadcast(component);
|
|
467
|
+
|
|
468
|
+
AssertSequence(
|
|
469
|
+
fastOrder,
|
|
470
|
+
"Broadcast-without-source fast post-processors should run in registration order even with many entries."
|
|
471
|
+
);
|
|
472
|
+
AssertSequence(
|
|
473
|
+
actionOrder,
|
|
474
|
+
"Broadcast-without-source action post-processors should run in registration order even with many entries."
|
|
475
|
+
);
|
|
476
|
+
yield break;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
[UnityTest]
|
|
480
|
+
public IEnumerator GlobalAcceptAllActionsManyRegistrationsMaintainOrder()
|
|
481
|
+
{
|
|
482
|
+
GameObject host = new(
|
|
483
|
+
nameof(GlobalAcceptAllActionsManyRegistrationsMaintainOrder),
|
|
484
|
+
typeof(EmptyMessageAwareComponent)
|
|
485
|
+
);
|
|
486
|
+
_spawned.Add(host);
|
|
487
|
+
EmptyMessageAwareComponent component = host.GetComponent<EmptyMessageAwareComponent>();
|
|
488
|
+
MessageRegistrationToken token = GetToken(component);
|
|
489
|
+
|
|
490
|
+
List<int> untargetedOrder = new(ManyRegistrationCount);
|
|
491
|
+
List<int> targetedOrder = new(ManyRegistrationCount);
|
|
492
|
+
List<int> broadcastOrder = new(ManyRegistrationCount);
|
|
493
|
+
|
|
494
|
+
for (int i = 0; i < ManyRegistrationCount; i++)
|
|
495
|
+
{
|
|
496
|
+
int index = i;
|
|
497
|
+
_ = token.RegisterGlobalAcceptAll(
|
|
498
|
+
_ => untargetedOrder.Add(index),
|
|
499
|
+
(_, _) => targetedOrder.Add(index),
|
|
500
|
+
(_, _) => broadcastOrder.Add(index)
|
|
501
|
+
);
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
SimpleUntargetedMessage untargeted = new();
|
|
505
|
+
untargeted.EmitUntargeted();
|
|
506
|
+
|
|
507
|
+
SimpleTargetedMessage targeted = new();
|
|
508
|
+
targeted.EmitComponentTargeted(component);
|
|
509
|
+
|
|
510
|
+
SimpleBroadcastMessage broadcast = new();
|
|
511
|
+
broadcast.EmitComponentBroadcast(component);
|
|
512
|
+
|
|
513
|
+
AssertSequence(
|
|
514
|
+
untargetedOrder,
|
|
515
|
+
"Global accept-all action handlers for untargeted messages should run in registration order even with many entries."
|
|
516
|
+
);
|
|
517
|
+
AssertSequence(
|
|
518
|
+
targetedOrder,
|
|
519
|
+
"Global accept-all action handlers for targeted messages should run in registration order even with many entries."
|
|
520
|
+
);
|
|
521
|
+
AssertSequence(
|
|
522
|
+
broadcastOrder,
|
|
523
|
+
"Global accept-all action handlers for broadcast messages should run in registration order even with many entries."
|
|
524
|
+
);
|
|
525
|
+
yield break;
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
[UnityTest]
|
|
529
|
+
public IEnumerator GlobalAcceptAllFastManyRegistrationsMaintainOrder()
|
|
530
|
+
{
|
|
531
|
+
GameObject host = new(
|
|
532
|
+
nameof(GlobalAcceptAllFastManyRegistrationsMaintainOrder),
|
|
533
|
+
typeof(EmptyMessageAwareComponent)
|
|
534
|
+
);
|
|
535
|
+
_spawned.Add(host);
|
|
536
|
+
EmptyMessageAwareComponent component = host.GetComponent<EmptyMessageAwareComponent>();
|
|
537
|
+
MessageRegistrationToken token = GetToken(component);
|
|
538
|
+
|
|
539
|
+
List<int> untargetedOrder = new(ManyRegistrationCount);
|
|
540
|
+
List<int> targetedOrder = new(ManyRegistrationCount);
|
|
541
|
+
List<int> broadcastOrder = new(ManyRegistrationCount);
|
|
542
|
+
|
|
543
|
+
for (int i = 0; i < ManyRegistrationCount; i++)
|
|
544
|
+
{
|
|
545
|
+
int index = i;
|
|
546
|
+
_ = token.RegisterGlobalAcceptAll(
|
|
547
|
+
(ref IUntargetedMessage _) => untargetedOrder.Add(index),
|
|
548
|
+
(ref InstanceId _, ref ITargetedMessage _) => targetedOrder.Add(index),
|
|
549
|
+
(ref InstanceId _, ref IBroadcastMessage _) => broadcastOrder.Add(index)
|
|
550
|
+
);
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
SimpleUntargetedMessage untargeted = new();
|
|
554
|
+
untargeted.EmitUntargeted();
|
|
555
|
+
|
|
556
|
+
SimpleTargetedMessage targeted = new();
|
|
557
|
+
targeted.EmitComponentTargeted(component);
|
|
558
|
+
|
|
559
|
+
SimpleBroadcastMessage broadcast = new();
|
|
560
|
+
broadcast.EmitComponentBroadcast(component);
|
|
561
|
+
|
|
562
|
+
AssertSequence(
|
|
563
|
+
untargetedOrder,
|
|
564
|
+
"Global accept-all fast handlers for untargeted messages should run in registration order even with many entries."
|
|
565
|
+
);
|
|
566
|
+
AssertSequence(
|
|
567
|
+
targetedOrder,
|
|
568
|
+
"Global accept-all fast handlers for targeted messages should run in registration order even with many entries."
|
|
569
|
+
);
|
|
570
|
+
AssertSequence(
|
|
571
|
+
broadcastOrder,
|
|
572
|
+
"Global accept-all fast handlers for broadcast messages should run in registration order even with many entries."
|
|
573
|
+
);
|
|
574
|
+
yield break;
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
[UnityTest]
|
|
578
|
+
public IEnumerator UntargetedInterceptorsManyRegistrationsMaintainOrder()
|
|
579
|
+
{
|
|
580
|
+
GameObject host = new(
|
|
581
|
+
nameof(UntargetedInterceptorsManyRegistrationsMaintainOrder),
|
|
582
|
+
typeof(EmptyMessageAwareComponent)
|
|
583
|
+
);
|
|
584
|
+
_spawned.Add(host);
|
|
585
|
+
EmptyMessageAwareComponent component = host.GetComponent<EmptyMessageAwareComponent>();
|
|
586
|
+
MessageRegistrationToken token = GetToken(component);
|
|
587
|
+
|
|
588
|
+
List<int> order = new(ManyRegistrationCount);
|
|
589
|
+
|
|
590
|
+
for (int i = 0; i < ManyRegistrationCount; i++)
|
|
591
|
+
{
|
|
592
|
+
int index = i;
|
|
593
|
+
_ = token.RegisterUntargetedInterceptor(
|
|
594
|
+
(ref SimpleUntargetedMessage _) =>
|
|
595
|
+
{
|
|
596
|
+
order.Add(index);
|
|
597
|
+
return true;
|
|
598
|
+
}
|
|
599
|
+
);
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
SimpleUntargetedMessage message = new();
|
|
603
|
+
message.EmitUntargeted();
|
|
604
|
+
|
|
605
|
+
AssertSequence(
|
|
606
|
+
order,
|
|
607
|
+
"Untargeted interceptors should run in registration order even with many entries."
|
|
608
|
+
);
|
|
609
|
+
yield break;
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
[UnityTest]
|
|
613
|
+
public IEnumerator TargetedInterceptorsManyRegistrationsMaintainOrder()
|
|
614
|
+
{
|
|
615
|
+
GameObject host = new(
|
|
616
|
+
nameof(TargetedInterceptorsManyRegistrationsMaintainOrder),
|
|
617
|
+
typeof(EmptyMessageAwareComponent)
|
|
618
|
+
);
|
|
619
|
+
_spawned.Add(host);
|
|
620
|
+
EmptyMessageAwareComponent component = host.GetComponent<EmptyMessageAwareComponent>();
|
|
621
|
+
MessageRegistrationToken token = GetToken(component);
|
|
622
|
+
|
|
623
|
+
List<int> order = new(ManyRegistrationCount);
|
|
624
|
+
|
|
625
|
+
for (int i = 0; i < ManyRegistrationCount; i++)
|
|
626
|
+
{
|
|
627
|
+
int index = i;
|
|
628
|
+
_ = token.RegisterTargetedInterceptor(
|
|
629
|
+
(ref InstanceId _, ref SimpleTargetedMessage _) =>
|
|
630
|
+
{
|
|
631
|
+
order.Add(index);
|
|
632
|
+
return true;
|
|
633
|
+
}
|
|
634
|
+
);
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
SimpleTargetedMessage message = new();
|
|
638
|
+
message.EmitComponentTargeted(component);
|
|
639
|
+
|
|
640
|
+
AssertSequence(
|
|
641
|
+
order,
|
|
642
|
+
"Targeted interceptors should run in registration order even with many entries."
|
|
643
|
+
);
|
|
644
|
+
yield break;
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
[UnityTest]
|
|
648
|
+
public IEnumerator BroadcastInterceptorsManyRegistrationsMaintainOrder()
|
|
649
|
+
{
|
|
650
|
+
GameObject host = new(
|
|
651
|
+
nameof(BroadcastInterceptorsManyRegistrationsMaintainOrder),
|
|
652
|
+
typeof(EmptyMessageAwareComponent)
|
|
653
|
+
);
|
|
654
|
+
_spawned.Add(host);
|
|
655
|
+
EmptyMessageAwareComponent component = host.GetComponent<EmptyMessageAwareComponent>();
|
|
656
|
+
MessageRegistrationToken token = GetToken(component);
|
|
657
|
+
|
|
658
|
+
List<int> order = new(ManyRegistrationCount);
|
|
659
|
+
|
|
660
|
+
for (int i = 0; i < ManyRegistrationCount; i++)
|
|
661
|
+
{
|
|
662
|
+
int index = i;
|
|
663
|
+
_ = token.RegisterBroadcastInterceptor(
|
|
664
|
+
(ref InstanceId _, ref SimpleBroadcastMessage _) =>
|
|
665
|
+
{
|
|
666
|
+
order.Add(index);
|
|
667
|
+
return true;
|
|
668
|
+
}
|
|
669
|
+
);
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
SimpleBroadcastMessage message = new();
|
|
673
|
+
message.EmitComponentBroadcast(component);
|
|
674
|
+
|
|
675
|
+
AssertSequence(
|
|
676
|
+
order,
|
|
677
|
+
"Broadcast interceptors should run in registration order even with many entries."
|
|
678
|
+
);
|
|
679
|
+
yield break;
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
#endif
|