A game framework written with osu! in mind.
1// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
2// See the LICENCE file in the repository root for full licence text.
3
4using System.Threading;
5using NUnit.Framework;
6using osu.Framework.Audio;
7
8namespace osu.Framework.Tests.Audio
9{
10 [TestFixture]
11 public class AudioCollectionManagerTest
12 {
13 [Test]
14 public void TestDisposalWhileItemsAreAddedDoesNotThrowInvalidOperationException()
15 {
16 var manager = new TestAudioCollectionManager();
17
18 var threadExecutionFinished = new ManualResetEventSlim();
19 var updateLoopStarted = new ManualResetEventSlim();
20
21 // add a huge amount of items to the queue
22 for (int i = 0; i < 10000; i++)
23 manager.AddItem(new TestingAdjustableAudioComponent());
24
25 // in a separate thread start processing the queue
26 var thread = new Thread(() =>
27 {
28 while (!manager.IsDisposed)
29 {
30 updateLoopStarted.Set();
31 manager.Update();
32 }
33
34 threadExecutionFinished.Set();
35 });
36
37 thread.Start();
38
39 Assert.IsTrue(updateLoopStarted.Wait(10000));
40
41 Assert.DoesNotThrow(() => manager.Dispose());
42
43 Assert.IsTrue(threadExecutionFinished.Wait(10000));
44 }
45
46 private class TestAudioCollectionManager : AudioCollectionManager<AdjustableAudioComponent>
47 {
48 public new bool IsDisposed => base.IsDisposed;
49 }
50
51 private class TestingAdjustableAudioComponent : AdjustableAudioComponent
52 {
53 }
54 }
55}