Skip to content

Commit

Permalink
Tests possible fixes, temporarily disable synchronization context cal…
Browse files Browse the repository at this point in the history
…lback workflow
  • Loading branch information
jakub-grzesiowski committed Jan 30, 2025
1 parent 454e631 commit 4adc1c0
Show file tree
Hide file tree
Showing 10 changed files with 147 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ public void Setup()
talkUser = chat.GetOrCreateUser("talk_user");
}

[TearDown]
public async Task CleanUp()
{
chat.Destroy();
await Task.Delay(3000);
}

[Test]
public async Task TestGetUserSuggestions()
{
Expand Down Expand Up @@ -157,7 +164,7 @@ public void TestUnPinMessage()
};
channel.SendText("message to pin");

var received = receivedManualEvent.WaitOne(6000);
var received = receivedManualEvent.WaitOne(12000);
Assert.IsTrue(received);
}

Expand Down
10 changes: 10 additions & 0 deletions c-sharp-chat/PubnubChatApi/PubNubChatApi.Tests/ChatEventTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Diagnostics;
using PubNubChatAPI.Entities;
using PubnubChatApi.Entities.Data;

Expand Down Expand Up @@ -26,6 +27,15 @@ public void Setup()
channel.Join();
}

[TearDown]
public async Task CleanUp()
{
channel.Leave();
await Task.Delay(3000);
chat.Destroy();
await Task.Delay(3000);
}

[Test]
public void TestModerationEvents()
{
Expand Down
13 changes: 11 additions & 2 deletions c-sharp-chat/PubnubChatApi/PubNubChatApi.Tests/ChatTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ public void Setup()
}
channel.Join();
}

[TearDown]
public async Task CleanUp()
{
channel.Leave();
await Task.Delay(3000);
chat.Destroy();
await Task.Delay(3000);
}

[Test]
public async Task TestGetCurrentUserMentions()
Expand Down Expand Up @@ -151,7 +160,7 @@ public void TestForwardMessage()

channel.SendText("message_to_forward");

var forwarded = messageForwardReceivedManualEvent.WaitOne(6000);
var forwarded = messageForwardReceivedManualEvent.WaitOne(12000);
forwardingChannel.Leave();
Assert.True(forwarded);
}
Expand All @@ -168,7 +177,7 @@ public void TestEmitEvent()
channel.Join();
chat.EmitEvent(PubnubChatEventType.Report, channel.Id, "{\"test\":\"some_nonsense\"}");

var eventReceived = reportManualEvent.WaitOne(5000);
var eventReceived = reportManualEvent.WaitOne(8000);
Assert.True(eventReceived);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ public void Setup()
}
channel.Join();
}

[TearDown]
public async Task CleanUp()
{
channel.Leave();
await Task.Delay(3000);
chat.Destroy();
await Task.Delay(3000);
}

[Test]
public async Task TestGetMemberships()
Expand Down
26 changes: 18 additions & 8 deletions c-sharp-chat/PubnubChatApi/PubNubChatApi.Tests/MessageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ public void Setup()
channel.Join();
}

[TearDown]
public async Task CleanUp()
{
channel.Leave();
await Task.Delay(3000);
chat.Destroy();
await Task.Delay(3000);
}

[Test]
public void TestSendAndReceive()
{
Expand Down Expand Up @@ -80,18 +89,19 @@ public void TestReceivingMessageData()
public void TestTryGetMessage()
{
var manualReceiveEvent = new ManualResetEvent(false);
var timeToken = string.Empty;
channel.OnMessageReceived += message =>
{
if (message.ChannelId == channel.Id)
{
Assert.True(chat.TryGetMessage(channel.Id, message.TimeToken, out _));
timeToken = message.TimeToken;
manualReceiveEvent.Set();
}
};
channel.SendText("something");

var received = manualReceiveEvent.WaitOne(4000);
Assert.IsTrue(received);
Assert.True(received);
Assert.True(chat.TryGetMessage(channel.Id, timeToken, out _));
}

[Test]
Expand Down Expand Up @@ -208,7 +218,7 @@ public void TestMessageReactions()
var reactions = message.Reactions;
Assert.True(reactions.Count == 1 && reactions.Any(x => x.Value == "happy"));*/

await Task.Delay(3000);
await Task.Delay(5000);

var has = message.HasUserReaction("happy");
Assert.True(has);
Expand All @@ -217,15 +227,14 @@ public void TestMessageReactions()
manualReset.Set();
};
channel.SendText("a_message");
var reacted = manualReset.WaitOne(10000);
var reacted = manualReset.WaitOne(12000);
Assert.True(reacted);
}

[Test]
public void TestMessageReport()
{
var reportManualEvent = new ManualResetEvent(false);
channel.Join();
chat.StartListeningForReportEvents(channel.Id);
chat.OnReportEvent += reportEvent =>
{
Expand Down Expand Up @@ -255,6 +264,7 @@ public async Task TestCreateThread()
}
catch (Exception e)
{
Debug.WriteLine(e);
Console.WriteLine(e);
Assert.Fail();
}
Expand All @@ -263,7 +273,7 @@ public async Task TestCreateThread()
Assert.True(message.TryGetThread(out var threadChannel));
message.RemoveThread();

await Task.Delay(8000);
await Task.Delay(12000);

//TODO: temporary way to get latest message pointer since remove_thread doesn't return a new pointer
chat.TryGetMessage(channel.Id, message.Id, out message);
Expand All @@ -273,7 +283,7 @@ public async Task TestCreateThread()
};
channel.SendText("thread_start_message");

var received = manualReceiveEvent.WaitOne(20000);
var received = manualReceiveEvent.WaitOne(30000);
Assert.IsTrue(received);
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Diagnostics;
using PubNubChatAPI.Entities;
using PubnubChatApi.Entities.Data;

Expand All @@ -17,6 +18,13 @@ public void Setup()
"restrictions_tests_user")
);
}

[TearDown]
public async Task CleanUp()
{
chat.Destroy();
await Task.Delay(3000);
}

[Test]
public async Task TestSetRestrictions()
Expand Down
11 changes: 10 additions & 1 deletion c-sharp-chat/PubnubChatApi/PubNubChatApi.Tests/ThreadsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,18 @@ public void Setup()
}
channel.Join();
}

[TearDown]
public async Task CleanUp()
{
channel.Leave();
await Task.Delay(3000);
chat.Destroy();
await Task.Delay(3000);
}

[Test]
public void TestGetThreadHistory()
public async Task TestGetThreadHistory()
{
var historyReadReset = new ManualResetEvent(false);
channel.OnMessageReceived += async message =>
Expand Down
9 changes: 9 additions & 0 deletions c-sharp-chat/PubnubChatApi/PubNubChatApi.Tests/UserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ public void Setup()
}
channel.Join();
}

[TearDown]
public async Task CleanUp()
{
channel.Leave();
await Task.Delay(3000);
chat.Destroy();
await Task.Delay(3000);
}

[Test]
public async Task TestUserActive()
Expand Down
4 changes: 2 additions & 2 deletions c-sharp-chat/PubnubChatApi/PubnubChatApi.sln
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ Global
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{8D3851D4-6FD7-4DE5-9960-DA386442603E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8D3851D4-6FD7-4DE5-9960-DA386442603E}.Release|Any CPU.Build.0 = Release|Any CPU
{8D3851D4-6FD7-4DE5-9960-DA386442603E}.Debug|Any CPU.ActiveCfg = Release|Any CPU
{8D3851D4-6FD7-4DE5-9960-DA386442603E}.Debug|Any CPU.Build.0 = Release|Any CPU
{8D3851D4-6FD7-4DE5-9960-DA386442603E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8D3851D4-6FD7-4DE5-9960-DA386442603E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{54ACBC4B-510A-499F-9494-24F9F90F7B67}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{54ACBC4B-510A-499F-9494-24F9F90F7B67}.Debug|Any CPU.Build.0 = Debug|Any CPU
{54ACBC4B-510A-499F-9494-24F9F90F7B67}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down
Loading

0 comments on commit 4adc1c0

Please sign in to comment.