diff --git a/.pubnub.yml b/.pubnub.yml index cc4db424..8ff8dadb 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,6 +1,13 @@ --- -version: v9.0.0 +version: v9.0.1 changelog: + - date: 2025-05-30 + version: v9.0.1 + changes: + - type: feature + text: "Improved Unity-side testing of core C# codebase." + - type: bug + text: "Updated the legacy Reconnect() call to properly call new C#-side signature." - date: 2025-05-08 version: v9.0.0 changes: @@ -772,7 +779,7 @@ sdks: distribution-type: package distribution-repository: git release package-name: PubNub.unitypackage - location: https://github.com/pubnub/unity/releases/download/v9.0.0/PubNub.unitypackage + location: https://github.com/pubnub/unity/releases/download/v9.0.1/PubNub.unitypackage requires: - name: "UnityEditor" @@ -904,7 +911,7 @@ sdks: distribution-type: package distribution-repository: git release package-name: PubNub.unitypackage - location: https://github.com/pubnub/unity/releases/download/v9.0.0/PubNub.unitypackage + location: https://github.com/pubnub/unity/releases/download/v9.0.1/PubNub.unitypackage requires: - name: "UnityEditor" diff --git a/PubNubUnity/Assets/PubNub/Runtime/Adapters/PubNub.cs b/PubNubUnity/Assets/PubNub/Runtime/Adapters/PubNub.cs index aebe10ec..2de3a438 100644 --- a/PubNubUnity/Assets/PubNub/Runtime/Adapters/PubNub.cs +++ b/PubNubUnity/Assets/PubNub/Runtime/Adapters/PubNub.cs @@ -11,7 +11,7 @@ public static class PubnubExtensions { public static ISubscribeOperation Subscribe(this Pubnub pn) => pn.Subscribe(); [Obsolete("Use the generic version instead")] - public static bool Reconnect(this Pubnub pn) => pn.Reconnect(); + public static bool Reconnect(this Pubnub pn) => pn.Reconnect().Result; /// /// Add an event listener that dispatches to the main Unity thread. This allows manipulation of the built-in classes within callbacks. diff --git a/PubNubUnity/Assets/PubNub/Runtime/Plugins/PubnubApiUnity.dll b/PubNubUnity/Assets/PubNub/Runtime/Plugins/PubnubApiUnity.dll index 2ebed403..598987e2 100644 Binary files a/PubNubUnity/Assets/PubNub/Runtime/Plugins/PubnubApiUnity.dll and b/PubNubUnity/Assets/PubNub/Runtime/Plugins/PubnubApiUnity.dll differ diff --git a/PubNubUnity/Assets/PubNub/Runtime/Util/UnityPNSDKSource.cs b/PubNubUnity/Assets/PubNub/Runtime/Util/UnityPNSDKSource.cs index 646e71b8..d1409304 100644 --- a/PubNubUnity/Assets/PubNub/Runtime/Util/UnityPNSDKSource.cs +++ b/PubNubUnity/Assets/PubNub/Runtime/Util/UnityPNSDKSource.cs @@ -5,7 +5,7 @@ namespace PubnubApi.Unity { public class UnityPNSDKSource : IPNSDKSource { - private const string build = "9.0.0"; + private const string build = "9.0.1"; public string GetPNSDK() { #if(UNITY_IOS) diff --git a/PubNubUnity/Assets/PubNub/Tests/PNTestBase.cs b/PubNubUnity/Assets/PubNub/Tests/PNTestBase.cs index 6076283e..03f9cf6c 100644 --- a/PubNubUnity/Assets/PubNub/Tests/PNTestBase.cs +++ b/PubNubUnity/Assets/PubNub/Tests/PNTestBase.cs @@ -5,18 +5,32 @@ using UnityEngine; namespace PubnubApi.Unity.Tests { + + public static class TestUtils { + public static IEnumerator AsCoroutine(this Task task) + { + while (!task.IsCompleted) yield return null; + // if task is faulted, throws the exception + task.GetAwaiter().GetResult(); + } + } + public class PNTestBase { protected static Pubnub pn; protected static SubscribeCallbackListener listener = new(); + protected static PNConfiguration configuration; [OneTimeSetUp] public void OneTimeSetUp() { - PNConfiguration pnConfiguration = new PNConfiguration(new UserId(System.Guid.NewGuid().ToString())) { - PublishKey = System.Environment.GetEnvironmentVariable("PUB_KEY"), - SubscribeKey = System.Environment.GetEnvironmentVariable("SUB_KEY"), - SecretKey = System.Environment.GetEnvironmentVariable("PAM_SECRET_KEY") + var envPub = System.Environment.GetEnvironmentVariable("PUB_KEY"); + var envSub = System.Environment.GetEnvironmentVariable("SUB_KEY"); + var envSec = System.Environment.GetEnvironmentVariable("PAM_SECRET_KEY"); + configuration = new PNConfiguration(new UserId(System.Guid.NewGuid().ToString())) { + PublishKey = string.IsNullOrEmpty(envPub) ? "demo-36" : envPub, + SubscribeKey = string.IsNullOrEmpty(envSub) ? "demo-36" : envSub, + SecretKey = envSec ?? "demo-36" }; - pn = new Pubnub(pnConfiguration); + pn = new Pubnub(configuration); pn.AddListener(listener); diff --git a/PubNubUnity/Assets/PubNub/Tests/Publish.cs b/PubNubUnity/Assets/PubNub/Tests/Publish.cs index 7f284ff1..4893f764 100644 --- a/PubNubUnity/Assets/PubNub/Tests/Publish.cs +++ b/PubNubUnity/Assets/PubNub/Tests/Publish.cs @@ -1,10 +1,21 @@ -using System.Collections; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Threading; using NUnit.Framework; +using System.Threading.Tasks; using UnityEngine; using UnityEngine.TestTools; namespace PubnubApi.Unity.Tests { + public class DummyCustomClass { + public string someText; + public int someInt; + public List someCollection; + } + public class Publish : PNTestBase { string lastMessage = null; @@ -39,6 +50,61 @@ public IEnumerator ReceiveMessage() { lastMessage = null; } + [UnityTest] + public IEnumerator PublishAndReceiveCustomMessageWithUnityJson() { + var mainThread = Thread.CurrentThread; + yield return TestTask().AsCoroutine(); + async Task TestTask() { + var randomChannelId = $"unity_test_{Guid.NewGuid()}"; + + pn.Subscribe().Channels(new []{randomChannelId}).Execute(); + await Task.Delay(3000); + + var correctMessage = false; + var correctThread = false; + + var receivedTaskSource = new TaskCompletionSource(); + var receiveCancellation = new CancellationTokenSource(15000); + receiveCancellation.Token.Register(() => receivedTaskSource.TrySetCanceled(), useSynchronizationContext: false); + + var messageDelegate = new Action>(delegate(Pubnub p, PNMessageResult message) { + if (Thread.CurrentThread.Equals(mainThread)) { + correctThread = true; + } + if (message.Message is DummyCustomClass dummyClassObject + && dummyClassObject.someCollection.SequenceEqual(new List() { 2, 1, 3, 7 }) + && dummyClassObject.someText == "hello there" + && dummyClassObject.someInt == 97) { + correctMessage = true; + } + receivedTaskSource.TrySetResult(true); + }); + listener.onMessage += messageDelegate; + + var publishResult = await pn.Publish().Channel(randomChannelId).Message(new DummyCustomClass() { + someCollection = new List() { 2, 1, 3, 7 }, + someInt = 97, + someText = "hello there" + }).ExecuteAsync(); + + Assert.IsNotNull(publishResult.Result, "publishResult.Result should not be null"); + Assert.IsNotNull(publishResult.Status, "publishResult.Status should not be null"); + Assert.IsFalse(publishResult.Status.Error, $"publishResult.Status.Error is true, error: {publishResult.Status.ErrorData?.Information}"); + + var received = true; + try { + await receivedTaskSource.Task.ConfigureAwait(false); + } catch (TaskCanceledException e) { + received = false; + } + Assert.IsTrue(received, "didn't receive message callback"); + Assert.IsTrue(correctThread, "callback was dispatched on wrong thread"); + Assert.IsTrue(correctMessage, "deserialized message had incorrect data"); + + listener.onMessage -= messageDelegate; + } + } + [TearDown] public void TearDown() { listener.onMessage -= OnMessage; diff --git a/PubNubUnity/Assets/PubNub/package.json b/PubNubUnity/Assets/PubNub/package.json index 3bcfbecd..349e790a 100644 --- a/PubNubUnity/Assets/PubNub/package.json +++ b/PubNubUnity/Assets/PubNub/package.json @@ -1,6 +1,6 @@ { "name": "com.pubnub.sdk", - "version": "9.0.0", + "version": "9.0.1", "displayName": "PubNub SDK", "description": "PubNub Real-time Cloud-Hosted Push API and Push Notification Client Frameworks", "unity": "2018.2", diff --git a/VERSION b/VERSION index f7ee0669..37ad5c8b 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -9.0.0 +9.0.1