Skip to content

Commit 11aad56

Browse files
fix(audience-sample-app): make sample build under Unity 2022 + Unity 6 (SDK-256)
- Adds Immutable.Audience.Samples.SampleApp.Editor.asmdef pinning ScriptingBackendOverride.cs into a discoverable Editor assembly; without an asmdef the implicit Assembly-CSharp-Editor may not be picked up by Unity 6's sandboxed test-runner build context. - Bumps com.unity.test-framework 1.1.33 -> 1.4.5 so [UnityTest] coroutines surface timeouts correctly under UTF 2.x. - Drops com.unity.toolchain.macos-arm64-linux-x86_64 2.0.5; the toolchain naming convention changed past 2022 and Unity auto-selects the macOS toolchain anyway. - Deletes packages-lock.json so each Unity version regenerates a lock matching its own UPM resolution. - Guards FindObjectOfType<AudienceSample> with #if UNITY_2023_1_OR_NEWER so APIUpdater can't silently drop the includeInactive parameter when rewriting to FindFirstObjectByType. - Converts deadline-style WaitForSecondsRealtime in two test methods to a polling pattern (Time.realtimeSinceStartup against a budget); adds the WaitForCondition helper used elsewhere in the test suite.
1 parent 489b100 commit 11aad56

6 files changed

Lines changed: 63 additions & 434 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "Immutable.Audience.Samples.SampleApp.Editor",
3+
"rootNamespace": "Immutable.Audience.Samples.SampleApp.Editor",
4+
"references": [],
5+
"includePlatforms": [
6+
"Editor"
7+
],
8+
"excludePlatforms": [],
9+
"allowUnsafeCode": false,
10+
"overrideReferences": false,
11+
"precompiledReferences": [],
12+
"autoReferenced": false,
13+
"defineConstraints": [],
14+
"versionDefines": [],
15+
"noEngineReferences": false
16+
}

examples/audience/Assets/Editor/Immutable.Audience.Samples.SampleApp.Editor.asmdef.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/audience/Assets/SampleApp/Tests/Runtime/SampleAppLiveFireTests.cs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ namespace Immutable.Audience.Samples.SampleApp.Tests
1313
[TestFixture]
1414
internal class SampleAppLiveFireTests
1515
{
16+
// Cached allocations for fixed-delay yields (SDK needs time to flush
17+
// rather than "wait up to N seconds for a condition"). Static readonly
18+
// so the WaitForSecondsRealtime instance is created once per class load.
19+
private static readonly WaitForSecondsRealtime _twoSeconds = new(2f);
20+
1621
private VisualElement? _root;
1722
private string _key = "";
1823

@@ -84,7 +89,11 @@ private IEnumerator LoadSceneOnly()
8489
yield return SceneManager.LoadSceneAsync(SampleAppUi.SceneName, LoadSceneMode.Single);
8590
yield return null; // one extra frame for Awake/InitializeUi
8691

87-
var sample = UnityEngine.Object.FindObjectOfType<AudienceSample>();
92+
#if UNITY_2023_1_OR_NEWER
93+
var sample = UnityEngine.Object.FindFirstObjectByType<AudienceSample>(FindObjectsInactive.Include);
94+
#else
95+
var sample = UnityEngine.Object.FindObjectOfType<AudienceSample>(includeInactive: true);
96+
#endif
8897
Assume.That(sample, Is.Not.Null, "AudienceSample MonoBehaviour expected in scene");
8998

9099
_root = sample!.GetComponent<UIDocument>().rootVisualElement;
@@ -226,7 +235,7 @@ public IEnumerator SetConsent_None_PurgesQueueAndPersists()
226235

227236
// Flushing after revocation should be a no-op (queue purged) — no error.
228237
_root.Q<Button>(SampleAppUi.Buttons.Flush).Click();
229-
yield return new WaitForSecondsRealtime(2f);
238+
yield return _twoSeconds;
230239

231240
AssertNoErrors();
232241
}
@@ -329,11 +338,12 @@ public IEnumerator ReInit_AfterShutdown_AcceptsTrack()
329338

330339
_root.Q<Button>(SampleAppUi.Buttons.Init).Click();
331340
// Two INIT@Ok rows now; WaitForLogEntry returns on the first
332-
// match it sees, but the original is already in the log so we
333-
// wait one frame for the second click to land then assert by
334-
// count instead.
341+
// match it sees, but the original is already in the log so poll
342+
// by count until the second Ok row appears or the deadline elapses.
335343
yield return null;
336-
yield return new WaitForSecondsRealtime(0.5f);
344+
yield return SampleAppTestHelpers.WaitForCondition(
345+
() => SampleAppTestHelpers.CountLogEntriesAtLevel(_root, LogLevels.Ok) > 1,
346+
2f, "second INIT@Ok row after re-init");
337347
Assert.Greater(SampleAppTestHelpers.CountLogEntriesAtLevel(_root, LogLevels.Ok), 1,
338348
"expected a second INIT@Ok row after re-init");
339349

@@ -554,7 +564,11 @@ public IEnumerator PersistedConsent_OverridesDropdownOnReInit()
554564

555565
// Dropdown is still at default Anonymous; re-Init must read disk.
556566
_root.Q<Button>(SampleAppUi.Buttons.Init).Click();
557-
yield return new WaitForSecondsRealtime(0.5f); // OnSdkStateChanged + RefreshStatusBar
567+
// Poll until OnSdkStateChanged + RefreshStatusBar has run and the
568+
// label reflects the re-loaded consent level.
569+
yield return SampleAppTestHelpers.WaitForCondition(
570+
() => _root.Q<Label>(SampleAppUi.StatusBar.Consent).text == SampleAppUi.Consent.Full,
571+
2f, "status-consent label to show Full after re-Init from persisted consent");
558572

559573
var statusConsent = _root.Q<Label>(SampleAppUi.StatusBar.Consent).text;
560574
Assert.AreEqual(SampleAppUi.Consent.Full, statusConsent,

examples/audience/Assets/SampleApp/Tests/Runtime/SampleAppTestHelpers.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Collections;
55
using System.Collections.Generic;
66
using System.Linq;
7+
using NUnit.Framework;
78
using UnityEngine;
89
using UnityEngine.UIElements;
910

@@ -14,6 +15,23 @@ namespace Immutable.Audience.Samples.SampleApp.Tests
1415
// the log pane via the userData stash on each log row.
1516
internal static class SampleAppTestHelpers
1617
{
18+
// Polls predicate once per frame until it returns true or the deadline
19+
// elapses. Calls Assert.Fail with description when the deadline is hit.
20+
// Use this instead of WaitForSecondsRealtime when a test is waiting
21+
// "at most N seconds for X to become true" — the polling exits as soon
22+
// as the condition is satisfied rather than burning the full N seconds.
23+
internal static IEnumerator WaitForCondition(
24+
Func<bool> predicate, float timeoutSeconds, string description)
25+
{
26+
var deadline = Time.realtimeSinceStartup + timeoutSeconds;
27+
while (Time.realtimeSinceStartup < deadline)
28+
{
29+
if (predicate()) yield break;
30+
yield return null;
31+
}
32+
Assert.Fail($"Timed out after {timeoutSeconds:F1}s waiting for: {description}");
33+
}
34+
1735
// Wait until the log pane contains an entry whose label matches `label`
1836
// and whose level matches `level`. Yields one frame per check.
1937
// Throws TimeoutException on deadline.

examples/audience/Packages/manifest.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66
"com.unity.ide.rider": "3.0.31",
77
"com.unity.ide.visualstudio": "2.0.22",
88
"com.unity.ide.vscode": "1.2.5",
9-
"com.unity.test-framework": "1.1.33",
9+
"com.unity.test-framework": "1.4.5",
1010
"com.unity.textmeshpro": "3.0.6",
1111
"com.unity.timeline": "1.6.5",
12-
"com.unity.toolchain.macos-arm64-linux-x86_64": "2.0.5",
1312
"com.unity.ugui": "1.0.0",
1413
"com.unity.visualscripting": "1.9.4",
1514
"com.unity.modules.ai": "1.0.0",

0 commit comments

Comments
 (0)