com.wallstop-studios.dxmessaging 2.0.0-rc06 → 2.0.0-rc08

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.
@@ -1,6 +1,7 @@
1
1
  namespace DxMessaging.Tests.Runtime.Core
2
2
  {
3
3
  using System.Collections;
4
+ using System.Linq;
4
5
  using DxMessaging.Core;
5
6
  using DxMessaging.Core.Extensions;
6
7
  using DxMessaging.Core.Messages;
@@ -20,8 +21,10 @@
20
21
  GameObject test2 = new(nameof(SimpleNormal) + "2", typeof(EmptyMessageAwareComponent));
21
22
  _spawned.Add(test2);
22
23
 
23
- EmptyMessageAwareComponent component1 = test1.GetComponent<EmptyMessageAwareComponent>();
24
- EmptyMessageAwareComponent component2 = test2.GetComponent<EmptyMessageAwareComponent>();
24
+ EmptyMessageAwareComponent component1 =
25
+ test1.GetComponent<EmptyMessageAwareComponent>();
26
+ EmptyMessageAwareComponent component2 =
27
+ test2.GetComponent<EmptyMessageAwareComponent>();
25
28
 
26
29
  int count1 = 0;
27
30
  MessageRegistrationToken token1 = GetToken(component1);
@@ -48,8 +51,10 @@
48
51
  GameObject test2 = new(nameof(SimpleNormal) + "2", typeof(EmptyMessageAwareComponent));
49
52
  _spawned.Add(test2);
50
53
 
51
- EmptyMessageAwareComponent component1 = test1.GetComponent<EmptyMessageAwareComponent>();
52
- EmptyMessageAwareComponent component2 = test2.GetComponent<EmptyMessageAwareComponent>();
54
+ EmptyMessageAwareComponent component1 =
55
+ test1.GetComponent<EmptyMessageAwareComponent>();
56
+ EmptyMessageAwareComponent component2 =
57
+ test2.GetComponent<EmptyMessageAwareComponent>();
53
58
 
54
59
  int count1 = 0;
55
60
  void Receive1(ref SimpleUntargetedMessage message)
@@ -86,8 +91,10 @@
86
91
  GameObject test2 = new(nameof(SimpleNormal) + "2", typeof(EmptyMessageAwareComponent));
87
92
  _spawned.Add(test2);
88
93
 
89
- EmptyMessageAwareComponent component1 = test1.GetComponent<EmptyMessageAwareComponent>();
90
- EmptyMessageAwareComponent component2 = test2.GetComponent<EmptyMessageAwareComponent>();
94
+ EmptyMessageAwareComponent component1 =
95
+ test1.GetComponent<EmptyMessageAwareComponent>();
96
+ EmptyMessageAwareComponent component2 =
97
+ test2.GetComponent<EmptyMessageAwareComponent>();
91
98
 
92
99
  int count1 = 0;
93
100
  void Receive1(ref SimpleUntargetedMessage message)
@@ -120,7 +127,10 @@
120
127
  [UnityTest]
121
128
  public IEnumerator UntargetedUntyped()
122
129
  {
123
- GameObject test = new(nameof(UntargetedUntyped) + "1", typeof(EmptyMessageAwareComponent));
130
+ GameObject test = new(
131
+ nameof(UntargetedUntyped) + "1",
132
+ typeof(EmptyMessageAwareComponent)
133
+ );
124
134
  _spawned.Add(test);
125
135
 
126
136
  int count = 0;
@@ -145,5 +155,118 @@
145
155
 
146
156
  yield break;
147
157
  }
158
+
159
+ [UnityTest]
160
+ public IEnumerator Priority()
161
+ {
162
+ GameObject test = new(nameof(Priority) + "1", typeof(EmptyMessageAwareComponent));
163
+ _spawned.Add(test);
164
+
165
+ int[] received = new int[100];
166
+ EmptyMessageAwareComponent component = test.GetComponent<EmptyMessageAwareComponent>();
167
+ MessageRegistrationToken token = GetToken(component);
168
+ for (int i = 0; i < received.Length; ++i)
169
+ {
170
+ int priority = i;
171
+ token.RegisterUntargeted(
172
+ (ref SimpleUntargetedMessage _) =>
173
+ {
174
+ int previous = received[priority]++;
175
+ for (int j = priority - 1; j >= 0; --j)
176
+ {
177
+ Assert.AreEqual(previous + 1, received[j]);
178
+ }
179
+ for (int j = priority + 1; j < received.Length; ++j)
180
+ {
181
+ Assert.AreEqual(previous, received[j]);
182
+ }
183
+ },
184
+ priority: priority
185
+ );
186
+ token.RegisterUntargetedPostProcessor(
187
+ (ref SimpleUntargetedMessage _) =>
188
+ {
189
+ int previous = received[priority]++;
190
+ Assert.AreEqual(1, previous % 2);
191
+ for (int j = priority - 1; j >= 0; --j)
192
+ {
193
+ Assert.AreEqual(previous + 1, received[j]);
194
+ }
195
+ for (int j = priority + 1; j < received.Length; ++j)
196
+ {
197
+ Assert.AreEqual(previous, received[j]);
198
+ }
199
+ },
200
+ priority: priority
201
+ );
202
+ }
203
+
204
+ SimpleUntargetedMessage message = new();
205
+ const int numRuns = 100;
206
+ for (int i = 0; i < numRuns; ++i)
207
+ {
208
+ // Should do something
209
+ message.EmitUntargeted();
210
+ }
211
+
212
+ Assert.AreEqual(
213
+ 1,
214
+ received.Distinct().Count(),
215
+ "Expected received to be uniform, found: [{0}].",
216
+ string.Join(",", received.Distinct().OrderBy(x => x))
217
+ );
218
+
219
+ Assert.AreEqual(numRuns * 2, received.Distinct().Single());
220
+ yield break;
221
+ }
222
+
223
+ [UnityTest]
224
+ public IEnumerator Interceptor()
225
+ {
226
+ GameObject test = new(nameof(Interceptor), typeof(EmptyMessageAwareComponent));
227
+ _spawned.Add(test);
228
+
229
+ int[] received = new int[100];
230
+ EmptyMessageAwareComponent component = test.GetComponent<EmptyMessageAwareComponent>();
231
+ MessageRegistrationToken token = GetToken(component);
232
+ for (int i = 0; i < received.Length; ++i)
233
+ {
234
+ int priority = i;
235
+ token.RegisterUntargetedInterceptor(
236
+ (ref SimpleUntargetedMessage _) =>
237
+ {
238
+ int previous = received[priority]++;
239
+ for (int j = priority - 1; j >= 0; --j)
240
+ {
241
+ Assert.AreEqual(previous + 1, received[j]);
242
+ }
243
+ for (int j = priority + 1; j < received.Length; ++j)
244
+ {
245
+ Assert.AreEqual(previous, received[j]);
246
+ }
247
+
248
+ return true;
249
+ },
250
+ priority: priority
251
+ );
252
+ }
253
+
254
+ SimpleUntargetedMessage message = new();
255
+ const int numRuns = 100;
256
+ for (int i = 0; i < numRuns; ++i)
257
+ {
258
+ message.EmitUntargeted();
259
+ }
260
+
261
+ Assert.AreEqual(
262
+ 1,
263
+ received.Distinct().Count(),
264
+ "Expected received to be uniform, found: [{0}].",
265
+ string.Join(",", received.Distinct().OrderBy(x => x))
266
+ );
267
+
268
+ Assert.AreEqual(numRuns, received.Distinct().Single());
269
+ yield break;
270
+ }
148
271
  }
149
272
  }
@@ -4,7 +4,8 @@
4
4
  "references": [
5
5
  "UnityEngine.TestRunner",
6
6
  "UnityEditor.TestRunner",
7
- "WallstopStudios.DxMessaging"
7
+ "WallstopStudios.DxMessaging",
8
+ "Unity.PerformanceTesting"
8
9
  ],
9
10
  "includePlatforms": [],
10
11
  "excludePlatforms": [],
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "com.wallstop-studios.dxmessaging",
3
- "version": "2.0.0-rc06",
3
+ "version": "2.0.0-rc08",
4
4
  "displayName": "DxMessaging",
5
5
  "description": "Synchronous Event Bus for Unity",
6
6
  "unity": "2021.3",
7
7
  "dependencies": {
8
- "com.wallstop-studios.unity-helpers" : "2.0.0-rc04"
8
+ "com.wallstop-studios.unity-helpers" : "2.0.0-rc13"
9
9
  },
10
10
  "keywords": [
11
11
  "messaging",
package/Tests/Editor.meta DELETED
@@ -1,8 +0,0 @@
1
- fileFormatVersion: 2
2
- guid: 2f8663039d4ca4f43a9acdf5f22e30ed
3
- folderAsset: yes
4
- DefaultImporter:
5
- externalObjects: {}
6
- userData:
7
- assetBundleName:
8
- assetBundleVariant: