Skip to content

Commit 77450c6

Browse files
committed
use test lock, randomise port
1 parent 3095bf0 commit 77450c6

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

Tests/Runtime/TestLLM.cs

+15-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Collections;
88
using System.IO;
99
using System.Linq;
10+
using System.Threading;
1011
using UnityEngine.TestTools;
1112
using UnityEditor;
1213
using UnityEditor.TestTools.TestRunner.Api;
@@ -116,7 +117,9 @@ public class TestLLM
116117
protected string reply2;
117118
protected int tokens1;
118119
protected int tokens2;
120+
protected int port;
119121

122+
static readonly object _lock = new object();
120123

121124
public TestLLM()
122125
{
@@ -126,6 +129,8 @@ public TestLLM()
126129

127130
public virtual async Task Init()
128131
{
132+
Monitor.Enter(_lock);
133+
port = new System.Random().Next(10000, 20000);
129134
SetParameters();
130135
await DownloadModels();
131136
gameObject = new GameObject();
@@ -226,6 +231,7 @@ public virtual LLM CreateLLM()
226231
LLM llm = gameObject.AddComponent<LLM>();
227232
llm.SetModel(modelNameLLManager);
228233
llm.parallelPrompts = 1;
234+
llm.port = port;
229235
return llm;
230236
}
231237

@@ -240,6 +246,7 @@ public virtual LLMCharacter CreateLLMCharacter()
240246
llmCharacter.seed = 0;
241247
llmCharacter.stream = false;
242248
llmCharacter.numPredict = 20;
249+
llmCharacter.port = port;
243250
return llmCharacter;
244251
}
245252

@@ -336,7 +343,13 @@ public void TestEmbeddings(List<float> embeddings)
336343
Assert.That(embeddings.Count == 896);
337344
}
338345

339-
public virtual void OnDestroy() {}
346+
public virtual void OnDestroy()
347+
{
348+
if (Monitor.IsEntered(_lock))
349+
{
350+
Monitor.Exit(_lock);
351+
}
352+
}
340353
}
341354

342355
public class TestLLM_LLMManager_Load : TestLLM
@@ -371,6 +384,7 @@ public override LLM CreateLLM()
371384

372385
public override void OnDestroy()
373386
{
387+
base.OnDestroy();
374388
if (!File.Exists(loadPath)) File.Delete(loadPath);
375389
}
376390
}

0 commit comments

Comments
 (0)