From 6db872236ef90eca99bed3963a250f6f8bbb5671 Mon Sep 17 00:00:00 2001 From: hadashiA Date: Sat, 9 Sep 2023 10:16:01 +0900 Subject: [PATCH] Fix test --- src/UniTask.NetCoreTests/Linq/Merge.cs | 30 ++++++++++++++++++++------ 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/src/UniTask.NetCoreTests/Linq/Merge.cs b/src/UniTask.NetCoreTests/Linq/Merge.cs index 4db2214..7021d1d 100644 --- a/src/UniTask.NetCoreTests/Linq/Merge.cs +++ b/src/UniTask.NetCoreTests/Linq/Merge.cs @@ -13,24 +13,33 @@ namespace NetCoreTests.Linq [Fact] public async Task TwoSource() { + var semaphore = new SemaphoreSlim(1, 1); + var a = UniTaskAsyncEnumerable.Create(async (writer, _) => { await UniTask.SwitchToThreadPool(); + await semaphore.WaitAsync(); await writer.YieldAsync("A1"); - await Task.Delay(TimeSpan.FromMilliseconds(20)); + semaphore.Release(); + + await semaphore.WaitAsync(); await writer.YieldAsync("A2"); + semaphore.Release(); }); var b = UniTaskAsyncEnumerable.Create(async (writer, _) => { await UniTask.SwitchToThreadPool(); - await Task.Delay(TimeSpan.FromMilliseconds(10)); + await semaphore.WaitAsync(); await writer.YieldAsync("B1"); await writer.YieldAsync("B2"); - await Task.Delay(TimeSpan.FromMilliseconds(100)); + semaphore.Release(); + + await semaphore.WaitAsync(); await writer.YieldAsync("B3"); + semaphore.Release(); }); var result = await a.Merge(b).ToArrayAsync(); @@ -40,27 +49,33 @@ namespace NetCoreTests.Linq [Fact] public async Task ThreeSource() { + var semaphore = new SemaphoreSlim(0, 1); + var a = UniTaskAsyncEnumerable.Create(async (writer, _) => { await UniTask.SwitchToThreadPool(); - await Task.Delay(TimeSpan.FromMilliseconds(10)); + await semaphore.WaitAsync(); await writer.YieldAsync("A1"); + semaphore.Release(); - await Task.Delay(TimeSpan.FromMilliseconds(40)); + await semaphore.WaitAsync(); await writer.YieldAsync("A2"); + semaphore.Release(); }); var b = UniTaskAsyncEnumerable.Create(async (writer, _) => { await UniTask.SwitchToThreadPool(); - await Task.Delay(TimeSpan.FromMilliseconds(20)); + await semaphore.WaitAsync(); await writer.YieldAsync("B1"); await writer.YieldAsync("B2"); + semaphore.Release(); - await Task.Delay(TimeSpan.FromMilliseconds(80)); + await semaphore.WaitAsync(); await writer.YieldAsync("B3"); + semaphore.Release(); }); var c = UniTaskAsyncEnumerable.Create(async (writer, _) => @@ -68,6 +83,7 @@ namespace NetCoreTests.Linq await UniTask.SwitchToThreadPool(); await writer.YieldAsync("C1"); + semaphore.Release(); }); var result = await a.Merge(b, c).ToArrayAsync();