您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
41 行
1.4 KiB
41 行
1.4 KiB
using LobbyRelaySample;
|
|
using NUnit.Framework;
|
|
using System;
|
|
using System.Text.RegularExpressions;
|
|
using UnityEngine.TestTools;
|
|
|
|
namespace Test
|
|
{
|
|
public class MessengerTests
|
|
{
|
|
/// <summary>Trivial message recipient that will run some action on any message.</summary>
|
|
private class Subscriber : IReceiveMessages
|
|
{
|
|
private Action m_thingToDo;
|
|
public Subscriber(Action thingToDo) { m_thingToDo = thingToDo; }
|
|
public void OnReceiveMessage(MessageType type, object msg) { m_thingToDo?.Invoke(); }
|
|
}
|
|
|
|
/// <summary>
|
|
/// If a message recipient takes a long time to process a message, we want to be made aware.
|
|
/// </summary>
|
|
[Test]
|
|
public void WhatIfAMessageIsVerySlow()
|
|
{
|
|
Messenger messenger = new Messenger();
|
|
int msgCount = 0;
|
|
string inefficientString = "";
|
|
Subscriber sub = new Subscriber(() =>
|
|
{ for (int n = 0; n < 12345; n++)
|
|
inefficientString += n.ToString();
|
|
msgCount++;
|
|
});
|
|
messenger.Subscribe(sub);
|
|
|
|
LogAssert.Expect(UnityEngine.LogType.Warning, new Regex(".*took too long.*"));
|
|
messenger.OnReceiveMessage(MessageType.None, "");
|
|
|
|
Assert.AreEqual(1, msgCount, "Should have acted on the message.");
|
|
}
|
|
}
|
|
}
|