com.wallstop-studios.dxmessaging 2.0.0-rc07 → 2.0.0-rc09

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.
@@ -713,9 +713,13 @@
713
713
  (ref SimpleTargetedMessage _) =>
714
714
  {
715
715
  int previous = received[priority]++;
716
- if (0 < priority)
716
+ for (int j = priority - 1; j >= 0; --j)
717
717
  {
718
- Assert.AreEqual(previous + 1, received[priority - 1]);
718
+ Assert.AreEqual(previous + 1, received[j]);
719
+ }
720
+ for (int j = priority + 1; j < received.Length; ++j)
721
+ {
722
+ Assert.AreEqual(previous, received[j]);
719
723
  }
720
724
  },
721
725
  priority: priority
@@ -726,9 +730,13 @@
726
730
  {
727
731
  int previous = received[priority]++;
728
732
  Assert.AreEqual(1, previous % 2);
729
- if (0 < priority)
733
+ for (int j = priority - 1; j >= 0; --j)
734
+ {
735
+ Assert.AreEqual(previous + 1, received[j]);
736
+ }
737
+ for (int j = priority + 1; j < received.Length; ++j)
730
738
  {
731
- Assert.AreEqual(previous + 1, received[priority - 1]);
739
+ Assert.AreEqual(previous, received[j]);
732
740
  }
733
741
  },
734
742
  priority: priority
@@ -776,9 +784,13 @@
776
784
  (ref SimpleTargetedMessage _) =>
777
785
  {
778
786
  int previous = received[priority]++;
779
- if (0 < priority)
787
+ for (int j = priority - 1; j >= 0; --j)
780
788
  {
781
- Assert.AreEqual(previous + 1, received[priority - 1]);
789
+ Assert.AreEqual(previous + 1, received[j]);
790
+ }
791
+ for (int j = priority + 1; j < received.Length; ++j)
792
+ {
793
+ Assert.AreEqual(previous, received[j]);
782
794
  }
783
795
  },
784
796
  priority: priority
@@ -789,9 +801,13 @@
789
801
  {
790
802
  int previous = received[priority]++;
791
803
  Assert.AreEqual(1, previous % 2);
792
- if (0 < priority)
804
+ for (int j = priority - 1; j >= 0; --j)
793
805
  {
794
- Assert.AreEqual(previous + 1, received[priority - 1]);
806
+ Assert.AreEqual(previous + 1, received[j]);
807
+ }
808
+ for (int j = priority + 1; j < received.Length; ++j)
809
+ {
810
+ Assert.AreEqual(previous, received[j]);
795
811
  }
796
812
  },
797
813
  priority: priority
@@ -818,5 +834,55 @@
818
834
  Assert.AreEqual(numRuns * 2, received.Distinct().Single());
819
835
  yield break;
820
836
  }
837
+
838
+ [UnityTest]
839
+ public IEnumerator Interceptor()
840
+ {
841
+ GameObject test = new(nameof(Interceptor), typeof(EmptyMessageAwareComponent));
842
+ _spawned.Add(test);
843
+
844
+ int[] received = new int[100];
845
+ EmptyMessageAwareComponent component = test.GetComponent<EmptyMessageAwareComponent>();
846
+ MessageRegistrationToken token = GetToken(component);
847
+ for (int i = 0; i < received.Length; ++i)
848
+ {
849
+ int priority = i;
850
+ token.RegisterTargetedInterceptor(
851
+ (ref InstanceId source, ref SimpleTargetedMessage _) =>
852
+ {
853
+ int previous = received[priority]++;
854
+ for (int j = priority - 1; j >= 0; --j)
855
+ {
856
+ Assert.AreEqual(previous + 1, received[j]);
857
+ }
858
+ for (int j = priority + 1; j < received.Length; ++j)
859
+ {
860
+ Assert.AreEqual(previous, received[j]);
861
+ }
862
+
863
+ return true;
864
+ },
865
+ priority: priority
866
+ );
867
+ }
868
+
869
+ SimpleTargetedMessage message = new();
870
+ const int numRuns = 100;
871
+ for (int i = 0; i < numRuns; ++i)
872
+ {
873
+ message.EmitComponentTargeted(component);
874
+ message.EmitGameObjectTargeted(test);
875
+ }
876
+
877
+ Assert.AreEqual(
878
+ 1,
879
+ received.Distinct().Count(),
880
+ "Expected received to be uniform, found: [{0}].",
881
+ string.Join(",", received.Distinct().OrderBy(x => x))
882
+ );
883
+
884
+ Assert.AreEqual(numRuns * 2, received.Distinct().Single());
885
+ yield break;
886
+ }
821
887
  }
822
888
  }
@@ -172,9 +172,13 @@
172
172
  (ref SimpleUntargetedMessage _) =>
173
173
  {
174
174
  int previous = received[priority]++;
175
- if (0 < priority)
175
+ for (int j = priority - 1; j >= 0; --j)
176
176
  {
177
- Assert.AreEqual(previous + 1, received[priority - 1]);
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]);
178
182
  }
179
183
  },
180
184
  priority: priority
@@ -184,9 +188,13 @@
184
188
  {
185
189
  int previous = received[priority]++;
186
190
  Assert.AreEqual(1, previous % 2);
187
- if (0 < priority)
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)
188
196
  {
189
- Assert.AreEqual(previous + 1, received[priority - 1]);
197
+ Assert.AreEqual(previous, received[j]);
190
198
  }
191
199
  },
192
200
  priority: priority
@@ -211,5 +219,54 @@
211
219
  Assert.AreEqual(numRuns * 2, received.Distinct().Single());
212
220
  yield break;
213
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
+ }
214
271
  }
215
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-rc07",
3
+ "version": "2.0.0-rc09",
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: