Skip to content

Commit ddf5f23

Browse files
Integration test improvements + Reconnect() tweak (#118)
* Add Unity specific integration test setup + implementation * Import latest C# DLL * Fix obsolete Reconnect call * PubNub SDK v9.0.1 release. --------- Co-authored-by: PubNub Release Bot <[email protected]>
1 parent 6da33ec commit ddf5f23

File tree

8 files changed

+100
-13
lines changed

8 files changed

+100
-13
lines changed

.pubnub.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
---
2-
version: v9.0.0
2+
version: v9.0.1
33
changelog:
4+
- date: 2025-05-30
5+
version: v9.0.1
6+
changes:
7+
- type: feature
8+
text: "Improved Unity-side testing of core C# codebase."
9+
- type: bug
10+
text: "Updated the legacy Reconnect() call to properly call new C#-side signature."
411
- date: 2025-05-08
512
version: v9.0.0
613
changes:
@@ -772,7 +779,7 @@ sdks:
772779
distribution-type: package
773780
distribution-repository: git release
774781
package-name: PubNub.unitypackage
775-
location: https://github.com/pubnub/unity/releases/download/v9.0.0/PubNub.unitypackage
782+
location: https://github.com/pubnub/unity/releases/download/v9.0.1/PubNub.unitypackage
776783
requires:
777784
-
778785
name: "UnityEditor"
@@ -904,7 +911,7 @@ sdks:
904911
distribution-type: package
905912
distribution-repository: git release
906913
package-name: PubNub.unitypackage
907-
location: https://github.com/pubnub/unity/releases/download/v9.0.0/PubNub.unitypackage
914+
location: https://github.com/pubnub/unity/releases/download/v9.0.1/PubNub.unitypackage
908915
requires:
909916
-
910917
name: "UnityEditor"

PubNubUnity/Assets/PubNub/Runtime/Adapters/PubNub.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public static class PubnubExtensions {
1111
public static ISubscribeOperation<string> Subscribe(this Pubnub pn) => pn.Subscribe<string>();
1212

1313
[Obsolete("Use the generic version instead")]
14-
public static bool Reconnect(this Pubnub pn) => pn.Reconnect<string>();
14+
public static bool Reconnect(this Pubnub pn) => pn.Reconnect<string>().Result;
1515

1616
/// <summary>
1717
/// Add an event listener that dispatches to the main Unity thread. This allows manipulation of the built-in classes within callbacks.
Binary file not shown.

PubNubUnity/Assets/PubNub/Runtime/Util/UnityPNSDKSource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace PubnubApi.Unity
55
{
66
public class UnityPNSDKSource : IPNSDKSource {
77

8-
private const string build = "9.0.0";
8+
private const string build = "9.0.1";
99

1010
public string GetPNSDK() {
1111
#if(UNITY_IOS)

PubNubUnity/Assets/PubNub/Tests/PNTestBase.cs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,32 @@
55
using UnityEngine;
66

77
namespace PubnubApi.Unity.Tests {
8+
9+
public static class TestUtils {
10+
public static IEnumerator AsCoroutine(this Task task)
11+
{
12+
while (!task.IsCompleted) yield return null;
13+
// if task is faulted, throws the exception
14+
task.GetAwaiter().GetResult();
15+
}
16+
}
17+
818
public class PNTestBase {
919
protected static Pubnub pn;
1020
protected static SubscribeCallbackListener listener = new();
21+
protected static PNConfiguration configuration;
1122

1223
[OneTimeSetUp]
1324
public void OneTimeSetUp() {
14-
PNConfiguration pnConfiguration = new PNConfiguration(new UserId(System.Guid.NewGuid().ToString())) {
15-
PublishKey = System.Environment.GetEnvironmentVariable("PUB_KEY"),
16-
SubscribeKey = System.Environment.GetEnvironmentVariable("SUB_KEY"),
17-
SecretKey = System.Environment.GetEnvironmentVariable("PAM_SECRET_KEY")
25+
var envPub = System.Environment.GetEnvironmentVariable("PUB_KEY");
26+
var envSub = System.Environment.GetEnvironmentVariable("SUB_KEY");
27+
var envSec = System.Environment.GetEnvironmentVariable("PAM_SECRET_KEY");
28+
configuration = new PNConfiguration(new UserId(System.Guid.NewGuid().ToString())) {
29+
PublishKey = string.IsNullOrEmpty(envPub) ? "demo-36" : envPub,
30+
SubscribeKey = string.IsNullOrEmpty(envSub) ? "demo-36" : envSub,
31+
SecretKey = envSec ?? "demo-36"
1832
};
19-
pn = new Pubnub(pnConfiguration);
33+
pn = new Pubnub(configuration);
2034

2135
pn.AddListener(listener);
2236

PubNubUnity/Assets/PubNub/Tests/Publish.cs

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
1-
using System.Collections;
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Threading;
26
using NUnit.Framework;
7+
using System.Threading.Tasks;
38
using UnityEngine;
49
using UnityEngine.TestTools;
510

611
namespace PubnubApi.Unity.Tests {
712

13+
public class DummyCustomClass {
14+
public string someText;
15+
public int someInt;
16+
public List<int> someCollection;
17+
}
18+
819
public class Publish : PNTestBase {
920
string lastMessage = null;
1021

@@ -39,6 +50,61 @@ public IEnumerator ReceiveMessage() {
3950
lastMessage = null;
4051
}
4152

53+
[UnityTest]
54+
public IEnumerator PublishAndReceiveCustomMessageWithUnityJson() {
55+
var mainThread = Thread.CurrentThread;
56+
yield return TestTask().AsCoroutine();
57+
async Task TestTask() {
58+
var randomChannelId = $"unity_test_{Guid.NewGuid()}";
59+
60+
pn.Subscribe<DummyCustomClass>().Channels(new []{randomChannelId}).Execute();
61+
await Task.Delay(3000);
62+
63+
var correctMessage = false;
64+
var correctThread = false;
65+
66+
var receivedTaskSource = new TaskCompletionSource<bool>();
67+
var receiveCancellation = new CancellationTokenSource(15000);
68+
receiveCancellation.Token.Register(() => receivedTaskSource.TrySetCanceled(), useSynchronizationContext: false);
69+
70+
var messageDelegate = new Action<Pubnub,PNMessageResult<object>>(delegate(Pubnub p, PNMessageResult<object> message) {
71+
if (Thread.CurrentThread.Equals(mainThread)) {
72+
correctThread = true;
73+
}
74+
if (message.Message is DummyCustomClass dummyClassObject
75+
&& dummyClassObject.someCollection.SequenceEqual(new List<int>() { 2, 1, 3, 7 })
76+
&& dummyClassObject.someText == "hello there"
77+
&& dummyClassObject.someInt == 97) {
78+
correctMessage = true;
79+
}
80+
receivedTaskSource.TrySetResult(true);
81+
});
82+
listener.onMessage += messageDelegate;
83+
84+
var publishResult = await pn.Publish().Channel(randomChannelId).Message(new DummyCustomClass() {
85+
someCollection = new List<int>() { 2, 1, 3, 7 },
86+
someInt = 97,
87+
someText = "hello there"
88+
}).ExecuteAsync();
89+
90+
Assert.IsNotNull(publishResult.Result, "publishResult.Result should not be null");
91+
Assert.IsNotNull(publishResult.Status, "publishResult.Status should not be null");
92+
Assert.IsFalse(publishResult.Status.Error, $"publishResult.Status.Error is true, error: {publishResult.Status.ErrorData?.Information}");
93+
94+
var received = true;
95+
try {
96+
await receivedTaskSource.Task.ConfigureAwait(false);
97+
} catch (TaskCanceledException e) {
98+
received = false;
99+
}
100+
Assert.IsTrue(received, "didn't receive message callback");
101+
Assert.IsTrue(correctThread, "callback was dispatched on wrong thread");
102+
Assert.IsTrue(correctMessage, "deserialized message had incorrect data");
103+
104+
listener.onMessage -= messageDelegate;
105+
}
106+
}
107+
42108
[TearDown]
43109
public void TearDown() {
44110
listener.onMessage -= OnMessage;

PubNubUnity/Assets/PubNub/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "com.pubnub.sdk",
3-
"version": "9.0.0",
3+
"version": "9.0.1",
44
"displayName": "PubNub SDK",
55
"description": "PubNub Real-time Cloud-Hosted Push API and Push Notification Client Frameworks",
66
"unity": "2018.2",

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
9.0.0
1+
9.0.1

0 commit comments

Comments
 (0)