diff --git a/Directory.Packages.props b/Directory.Packages.props
index 843625d24..848d029ed 100644
--- a/Directory.Packages.props
+++ b/Directory.Packages.props
@@ -39,7 +39,7 @@
-
+
@@ -47,8 +47,8 @@
-
-
+
+
diff --git a/tests/MagicOnion.Abstractions.Tests/MagicOnion.Abstractions.Tests.csproj b/tests/MagicOnion.Abstractions.Tests/MagicOnion.Abstractions.Tests.csproj
index 786eea496..41b4e0e0b 100644
--- a/tests/MagicOnion.Abstractions.Tests/MagicOnion.Abstractions.Tests.csproj
+++ b/tests/MagicOnion.Abstractions.Tests/MagicOnion.Abstractions.Tests.csproj
@@ -11,7 +11,7 @@
-
+
runtime; build; native; contentfiles; analyzers; buildtransitive
all
diff --git a/tests/MagicOnion.Abstractions.Tests/UnaryResultNonGenericTest.cs b/tests/MagicOnion.Abstractions.Tests/UnaryResultNonGenericTest.cs
index 4f278297a..3945efe65 100644
--- a/tests/MagicOnion.Abstractions.Tests/UnaryResultNonGenericTest.cs
+++ b/tests/MagicOnion.Abstractions.Tests/UnaryResultNonGenericTest.cs
@@ -69,7 +69,7 @@ public async Task ResponseHeadersAsync_Ctor_ResponseContext()
public async Task ResponseHeadersAsync_Never_Ctor_ResponseContext()
{
var result = new UnaryResult(Task.FromResult>(new DummyResponseContext(new TaskCompletionSource())));
- await Assert.ThrowsAsync(async () => await result.ResponseHeadersAsync.WaitAsync(TimeSpan.FromMilliseconds(250)));
+ await Assert.ThrowsAsync(async () => await result.ResponseHeadersAsync.WaitAsync(TimeSpan.FromMilliseconds(250), TestContext.Current.CancellationToken));
}
[Fact]
@@ -90,14 +90,14 @@ public async Task ResponseAsync_Ctor_ResponseContext()
public async Task ResponseAsync_Never_Ctor_Task()
{
var result = new UnaryResult(new TaskCompletionSource().Task);
- await Assert.ThrowsAsync(async () => await result.ResponseAsync.WaitAsync(TimeSpan.FromMilliseconds(250)));
+ await Assert.ThrowsAsync(async () => await result.ResponseAsync.WaitAsync(TimeSpan.FromMilliseconds(250), TestContext.Current.CancellationToken));
}
[Fact]
public async Task ResponseAsync_Never_Ctor_ResponseContext()
{
var result = new UnaryResult(Task.FromResult>(new DummyResponseContext(new TaskCompletionSource())));
- await Assert.ThrowsAsync(async () => await result.ResponseAsync.WaitAsync(TimeSpan.FromMilliseconds(250)));
+ await Assert.ThrowsAsync(async () => await result.ResponseAsync.WaitAsync(TimeSpan.FromMilliseconds(250), TestContext.Current.CancellationToken));
}
static class DummyResponseContext
diff --git a/tests/MagicOnion.Client.SourceGenerator.Tests/Collector/MagicOnionTypeInfoTest.cs b/tests/MagicOnion.Client.SourceGenerator.Tests/Collector/MagicOnionTypeInfoTest.cs
index 22bac7293..2c8629a4b 100644
--- a/tests/MagicOnion.Client.SourceGenerator.Tests/Collector/MagicOnionTypeInfoTest.cs
+++ b/tests/MagicOnion.Client.SourceGenerator.Tests/Collector/MagicOnionTypeInfoTest.cs
@@ -255,7 +255,7 @@ namespace MyNamespace
public class MyClass { }
}
");
- var symbols = compilation.GetSymbolsWithName(x => x == "MyClass", SymbolFilter.Type).OfType().ToArray();
+ var symbols = compilation.GetSymbolsWithName(x => x == "MyClass", SymbolFilter.Type, TestContext.Current.CancellationToken).OfType().ToArray();
// Act
var typeInfo = MagicOnionTypeInfo.CreateFromSymbol(symbols[0]);
@@ -279,7 +279,7 @@ public class MyClass
}
}
");
- var symbols = compilation.GetSymbolsWithName(x => x == "FieldA", SymbolFilter.Member)
+ var symbols = compilation.GetSymbolsWithName(x => x == "FieldA", SymbolFilter.Member, TestContext.Current.CancellationToken)
.OfType()
.ToArray();
@@ -307,7 +307,7 @@ public class MyClass
}
}
");
- var symbols = compilation.GetSymbolsWithName(x => x == "FieldA", SymbolFilter.Member)
+ var symbols = compilation.GetSymbolsWithName(x => x == "FieldA", SymbolFilter.Member, TestContext.Current.CancellationToken)
.OfType()
.ToArray();
@@ -337,7 +337,7 @@ public class MyClass
}
}
");
- var symbols = compilation.GetSymbolsWithName(x => x == "FieldA", SymbolFilter.Member)
+ var symbols = compilation.GetSymbolsWithName(x => x == "FieldA", SymbolFilter.Member, TestContext.Current.CancellationToken)
.OfType()
.ToArray();
@@ -365,7 +365,7 @@ public class MyClass
}
}
");
- var symbols = compilation.GetSymbolsWithName(x => x == "FieldA", SymbolFilter.Member)
+ var symbols = compilation.GetSymbolsWithName(x => x == "FieldA", SymbolFilter.Member, TestContext.Current.CancellationToken)
.OfType()
.ToArray();
@@ -393,7 +393,7 @@ public class MyClass
}
}
");
- var symbols = compilation.GetSymbolsWithName(x => x == "FieldA", SymbolFilter.Member)
+ var symbols = compilation.GetSymbolsWithName(x => x == "FieldA", SymbolFilter.Member, TestContext.Current.CancellationToken)
.OfType()
.ToArray();
@@ -419,7 +419,7 @@ public class MyClass
}
}
");
- var symbols = compilation.GetSymbolsWithName(x => x == "FieldA", SymbolFilter.Member)
+ var symbols = compilation.GetSymbolsWithName(x => x == "FieldA", SymbolFilter.Member, TestContext.Current.CancellationToken)
.OfType()
.ToArray();
@@ -443,7 +443,7 @@ public class MyClass
}
}
");
- var symbols = compilation.GetSymbolsWithName(x => x == "FieldA", SymbolFilter.Member)
+ var symbols = compilation.GetSymbolsWithName(x => x == "FieldA", SymbolFilter.Member, TestContext.Current.CancellationToken)
.OfType()
.ToArray();
@@ -467,7 +467,7 @@ public class MyClass
}
}
");
- var symbols = compilation.GetSymbolsWithName(x => x == "FieldA", SymbolFilter.Member)
+ var symbols = compilation.GetSymbolsWithName(x => x == "FieldA", SymbolFilter.Member, TestContext.Current.CancellationToken)
.OfType()
.ToArray();
@@ -493,7 +493,7 @@ public class MyClass
}
}
");
- var symbols = compilation.GetSymbolsWithName(x => x == "FieldA", SymbolFilter.Member)
+ var symbols = compilation.GetSymbolsWithName(x => x == "FieldA", SymbolFilter.Member, TestContext.Current.CancellationToken)
.OfType()
.ToArray();
@@ -517,7 +517,7 @@ public class MyClass
}
}
");
- var symbols = compilation.GetSymbolsWithName(x => x == "FieldA", SymbolFilter.Member)
+ var symbols = compilation.GetSymbolsWithName(x => x == "FieldA", SymbolFilter.Member, TestContext.Current.CancellationToken)
.OfType()
.ToArray();
@@ -547,7 +547,7 @@ public class MyClass
}
}
");
- var symbols = compilation.GetSymbolsWithName(x => x == "FieldA", SymbolFilter.Member)
+ var symbols = compilation.GetSymbolsWithName(x => x == "FieldA", SymbolFilter.Member, TestContext.Current.CancellationToken)
.OfType()
.ToArray();
@@ -577,7 +577,7 @@ public class MyClass
}
}
");
- var symbols = compilation.GetSymbolsWithName(x => x == "FieldA", SymbolFilter.Member)
+ var symbols = compilation.GetSymbolsWithName(x => x == "FieldA", SymbolFilter.Member, TestContext.Current.CancellationToken)
.OfType()
.ToArray();
diff --git a/tests/MagicOnion.Client.SourceGenerator.Tests/Collector/MethodCollectorServicesTest.cs b/tests/MagicOnion.Client.SourceGenerator.Tests/Collector/MethodCollectorServicesTest.cs
index 69f67687a..ec28a34ba 100644
--- a/tests/MagicOnion.Client.SourceGenerator.Tests/Collector/MethodCollectorServicesTest.cs
+++ b/tests/MagicOnion.Client.SourceGenerator.Tests/Collector/MethodCollectorServicesTest.cs
@@ -2,7 +2,6 @@
using MessagePack;
using Microsoft.CodeAnalysis;
using System.Collections.Immutable;
-using Xunit.Abstractions;
namespace MagicOnion.Client.SourceGenerator.Tests.Collector;
@@ -38,7 +37,7 @@ public interface IMyService : IService
var (serviceCollection, diagnostics) = MethodCollector.Collect(interfaceSymbols, referenceSymbols, CancellationToken.None);
// Assert
- compilation.GetDiagnostics().Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
+ compilation.GetDiagnostics(TestContext.Current.CancellationToken).Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
serviceCollection.Should().NotBeNull();
serviceCollection.Hubs.Should().BeEmpty();
serviceCollection.Services.Should().HaveCount(1);
@@ -78,7 +77,7 @@ public interface IMyService : IService
var (serviceCollection, diagnostics) = MethodCollector.Collect(interfaceSymbols, referenceSymbols, CancellationToken.None);
// Assert
- compilation.GetDiagnostics().Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
+ compilation.GetDiagnostics(TestContext.Current.CancellationToken).Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
serviceCollection.Should().NotBeNull();
serviceCollection.Hubs.Should().BeEmpty();
serviceCollection.Services.Should().BeEmpty();
@@ -110,7 +109,7 @@ public interface IMyService : IService
var (serviceCollection, diagnostics) = MethodCollector.Collect(interfaceSymbols, referenceSymbols, CancellationToken.None);
// Assert
- compilation.GetDiagnostics().Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
+ compilation.GetDiagnostics(TestContext.Current.CancellationToken).Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
serviceCollection.Services[0].Methods[0].RequestType.Should().Be(MagicOnionTypeInfo.CreateFromType());
serviceCollection.Services[0].Methods[0].ResponseType.Should().Be(MagicOnionTypeInfo.CreateFromType());
serviceCollection.Services[0].Methods[0].MethodReturnType.Should().Be(MagicOnionTypeInfo.CreateFromType());
@@ -142,7 +141,7 @@ public interface IMyService : IService
var (serviceCollection, diagnostics) = MethodCollector.Collect(interfaceSymbols, referenceSymbols, CancellationToken.None);
// Assert
- compilation.GetDiagnostics().Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
+ compilation.GetDiagnostics(TestContext.Current.CancellationToken).Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
serviceCollection.Services[0].Methods[0].RequestType.Should().Be(MagicOnionTypeInfo.CreateFromType[]>());
serviceCollection.Services[0].Methods[0].ResponseType.Should().Be(MagicOnionTypeInfo.CreateFromType[]>());
serviceCollection.Services[0].Methods[0].MethodReturnType.Should().Be(MagicOnionTypeInfo.CreateFromType[]>>());
@@ -174,7 +173,7 @@ public interface IMyService : IService
var (serviceCollection, diagnostics) = MethodCollector.Collect(interfaceSymbols, referenceSymbols, CancellationToken.None);
// Assert
- compilation.GetDiagnostics().Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
+ compilation.GetDiagnostics(TestContext.Current.CancellationToken).Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
serviceCollection.Services[0].Methods[0].RequestType.Should().Be(MagicOnionTypeInfo.CreateFromType>());
serviceCollection.Services[0].Methods[0].ResponseType.Should().Be(MagicOnionTypeInfo.CreateFromType());
serviceCollection.Services[0].Methods[0].MethodReturnType.Should().Be(MagicOnionTypeInfo.CreateFromType>());
@@ -206,7 +205,7 @@ public interface IMyService : IService
var (serviceCollection, diagnostics) = MethodCollector.Collect(interfaceSymbols, referenceSymbols, CancellationToken.None);
// Assert
- compilation.GetDiagnostics().Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
+ compilation.GetDiagnostics(TestContext.Current.CancellationToken).Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
serviceCollection.Should().NotBeNull();
serviceCollection.Hubs.Should().BeEmpty();
serviceCollection.Services.Should().HaveCount(1);
@@ -248,7 +247,7 @@ public interface IMyService : IService
var (serviceCollection, diagnostics) = MethodCollector.Collect(interfaceSymbols, referenceSymbols, CancellationToken.None);
// Assert
- compilation.GetDiagnostics().Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
+ compilation.GetDiagnostics(TestContext.Current.CancellationToken).Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
serviceCollection.Should().NotBeNull();
serviceCollection.Hubs.Should().BeEmpty();
serviceCollection.Services.Should().HaveCount(1);
@@ -289,7 +288,7 @@ public interface IMyService : IService
var (serviceCollection, diagnostics) = MethodCollector.Collect(interfaceSymbols, referenceSymbols, CancellationToken.None);
// Assert
- compilation.GetDiagnostics().Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
+ compilation.GetDiagnostics(TestContext.Current.CancellationToken).Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
serviceCollection.Should().NotBeNull();
serviceCollection.Hubs.Should().BeEmpty();
serviceCollection.Services.Should().HaveCount(1);
@@ -331,7 +330,7 @@ public interface IMyService : IService
var (serviceCollection, diagnostics) = MethodCollector.Collect(interfaceSymbols, referenceSymbols, CancellationToken.None);
// Assert
- compilation.GetDiagnostics().Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
+ compilation.GetDiagnostics(TestContext.Current.CancellationToken).Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
serviceCollection.Should().NotBeNull();
serviceCollection.Hubs.Should().BeEmpty();
serviceCollection.Services.Should().HaveCount(1);
@@ -374,7 +373,7 @@ public interface IMyService : IService
var (serviceCollection, diagnostics) = MethodCollector.Collect(interfaceSymbols, referenceSymbols, CancellationToken.None);
// Assert
- compilation.GetDiagnostics().Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
+ compilation.GetDiagnostics(TestContext.Current.CancellationToken).Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
serviceCollection.Services[0].Methods[0].Parameters[0].Type.Should().Be(MagicOnionTypeInfo.CreateFromType());
serviceCollection.Services[0].Methods[0].Parameters[0].HasExplicitDefaultValue.Should().BeTrue();
serviceCollection.Services[0].Methods[0].Parameters[0].DefaultValue.Should().Be("\"Hello\"");
@@ -418,7 +417,7 @@ public interface IMyService : IService
var (serviceCollection, diagnostics) = MethodCollector.Collect(interfaceSymbols, referenceSymbols, CancellationToken.None);
// Assert
- compilation.GetDiagnostics().Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
+ compilation.GetDiagnostics(TestContext.Current.CancellationToken).Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
serviceCollection.Should().NotBeNull();
serviceCollection.Hubs.Should().BeEmpty();
serviceCollection.Services.Should().HaveCount(1);
@@ -571,7 +570,7 @@ public interface IMyService : IService
var (serviceCollection, diagnostics) = MethodCollector.Collect(interfaceSymbols, referenceSymbols, CancellationToken.None);
// Assert
- compilation.GetDiagnostics().Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
+ compilation.GetDiagnostics(TestContext.Current.CancellationToken).Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
serviceCollection.Should().NotBeNull();
serviceCollection.Hubs.Should().BeEmpty();
serviceCollection.Services.Should().HaveCount(1);
@@ -611,7 +610,7 @@ public interface IMyService : IService
var (serviceCollection, diagnostics) = MethodCollector.Collect(interfaceSymbols, referenceSymbols, CancellationToken.None);
// Assert
- compilation.GetDiagnostics().Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
+ compilation.GetDiagnostics(TestContext.Current.CancellationToken).Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
serviceCollection.Should().NotBeNull();
serviceCollection.Hubs.Should().BeEmpty();
serviceCollection.Services.Should().HaveCount(1);
@@ -652,7 +651,7 @@ public interface IMyService : IService
var (serviceCollection, diagnostics) = MethodCollector.Collect(interfaceSymbols, referenceSymbols, CancellationToken.None);
// Assert
- compilation.GetDiagnostics().Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
+ compilation.GetDiagnostics(TestContext.Current.CancellationToken).Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
serviceCollection.Should().NotBeNull();
serviceCollection.Hubs.Should().BeEmpty();
serviceCollection.Services.Should().HaveCount(1);
@@ -725,7 +724,7 @@ public interface IMyService : IService
var (serviceCollection, diagnostics) = MethodCollector.Collect(interfaceSymbols, referenceSymbols, CancellationToken.None);
// Assert
- compilation.GetDiagnostics().Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
+ compilation.GetDiagnostics(TestContext.Current.CancellationToken).Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
serviceCollection.Should().NotBeNull();
serviceCollection.Hubs.Should().BeEmpty();
serviceCollection.Services.Should().HaveCount(1);
@@ -794,7 +793,7 @@ public interface IMyService : IService
var (serviceCollection, diagnostics) = MethodCollector.Collect(interfaceSymbols, referenceSymbols, CancellationToken.None);
// Assert
- compilation.GetDiagnostics().Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
+ compilation.GetDiagnostics(TestContext.Current.CancellationToken).Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
serviceCollection.Should().NotBeNull();
serviceCollection.Hubs.Should().BeEmpty();
serviceCollection.Services.Should().HaveCount(1);
diff --git a/tests/MagicOnion.Client.SourceGenerator.Tests/Collector/SerializationInfoCollectorTest.cs b/tests/MagicOnion.Client.SourceGenerator.Tests/Collector/SerializationInfoCollectorTest.cs
index 95f8db3d0..01628eab0 100644
--- a/tests/MagicOnion.Client.SourceGenerator.Tests/Collector/SerializationInfoCollectorTest.cs
+++ b/tests/MagicOnion.Client.SourceGenerator.Tests/Collector/SerializationInfoCollectorTest.cs
@@ -1,5 +1,4 @@
using MagicOnion.Client.SourceGenerator.CodeAnalysis;
-using Xunit.Abstractions;
namespace MagicOnion.Client.SourceGenerator.Tests.Collector;
diff --git a/tests/MagicOnion.Client.SourceGenerator.Tests/MagicOnion.Client.SourceGenerator.Tests.csproj b/tests/MagicOnion.Client.SourceGenerator.Tests/MagicOnion.Client.SourceGenerator.Tests.csproj
index ba3c2d4cc..5599b5f5d 100644
--- a/tests/MagicOnion.Client.SourceGenerator.Tests/MagicOnion.Client.SourceGenerator.Tests.csproj
+++ b/tests/MagicOnion.Client.SourceGenerator.Tests/MagicOnion.Client.SourceGenerator.Tests.csproj
@@ -13,7 +13,7 @@
-
+
runtime; build; native; contentfiles; analyzers; buildtransitive
all
diff --git a/tests/MagicOnion.Client.SourceGenerator.Tests/RunTest.cs b/tests/MagicOnion.Client.SourceGenerator.Tests/RunTest.cs
index 568c89efb..d6accb47c 100644
--- a/tests/MagicOnion.Client.SourceGenerator.Tests/RunTest.cs
+++ b/tests/MagicOnion.Client.SourceGenerator.Tests/RunTest.cs
@@ -37,10 +37,10 @@ partial class MagicOnionInitializer {}
);
// Run generator and update compilation
- driver = driver.RunGeneratorsAndUpdateCompilation(compilation, out var newCompilation, out var diagnostics);
+ driver = driver.RunGeneratorsAndUpdateCompilation(compilation, out var newCompilation, out var diagnostics, TestContext.Current.CancellationToken);
Assert.DoesNotContain(diagnostics, x => x.Severity > DiagnosticSeverity.Info);
- Assert.Empty(newCompilation.GetDiagnostics());
+ Assert.Empty(newCompilation.GetDiagnostics(TestContext.Current.CancellationToken));
var results = driver.GetRunResult().Results;
var generatedTrees = driver.GetRunResult().GeneratedTrees;
@@ -68,10 +68,10 @@ partial class MagicOnionInitializer {}
);
// Run generator and update compilation
- driver = driver.RunGeneratorsAndUpdateCompilation(compilation, out var newCompilation, out var diagnostics);
+ driver = driver.RunGeneratorsAndUpdateCompilation(compilation, out var newCompilation, out var diagnostics, TestContext.Current.CancellationToken);
Assert.DoesNotContain(diagnostics, x => x.Severity > DiagnosticSeverity.Info);
- Assert.DoesNotContain(newCompilation.GetDiagnostics(), x => x.Severity > DiagnosticSeverity.Info);
+ Assert.DoesNotContain(newCompilation.GetDiagnostics(TestContext.Current.CancellationToken), x => x.Severity > DiagnosticSeverity.Info);
}
[Fact]
@@ -103,10 +103,10 @@ partial class MagicOnionInitializer {}
);
// Run generator and update compilation
- driver = driver.RunGeneratorsAndUpdateCompilation(compilation, out var newCompilation, out var diagnostics);
+ driver = driver.RunGeneratorsAndUpdateCompilation(compilation, out var newCompilation, out var diagnostics, TestContext.Current.CancellationToken);
Assert.DoesNotContain(diagnostics, x => x.Severity > DiagnosticSeverity.Info);
- Assert.DoesNotContain(newCompilation.GetDiagnostics(), x => x.Severity > DiagnosticSeverity.Info);
+ Assert.DoesNotContain(newCompilation.GetDiagnostics(TestContext.Current.CancellationToken), x => x.Severity > DiagnosticSeverity.Info);
}
[Fact]
@@ -145,10 +145,10 @@ partial class MagicOnionInitializer {}
);
// Run generator and update compilation
- driver = driver.RunGeneratorsAndUpdateCompilation(compilation, out var newCompilation, out var diagnostics);
+ driver = driver.RunGeneratorsAndUpdateCompilation(compilation, out var newCompilation, out var diagnostics, TestContext.Current.CancellationToken);
Assert.DoesNotContain(diagnostics, x => x.Severity > DiagnosticSeverity.Info);
- Assert.DoesNotContain(newCompilation.GetDiagnostics(), x => x.Severity > DiagnosticSeverity.Info);
+ Assert.DoesNotContain(newCompilation.GetDiagnostics(TestContext.Current.CancellationToken), x => x.Severity > DiagnosticSeverity.Info);
}
//[Fact]
@@ -232,10 +232,10 @@ partial class FullName_AliasQualified {}
);
// Run generator and update compilation
- driver = driver.RunGeneratorsAndUpdateCompilation(compilation, out var newCompilation, out var diagnostics);
+ driver = driver.RunGeneratorsAndUpdateCompilation(compilation, out var newCompilation, out var diagnostics, TestContext.Current.CancellationToken);
Assert.DoesNotContain(diagnostics, x => x.Severity > DiagnosticSeverity.Info);
- Assert.DoesNotContain(newCompilation.GetDiagnostics(), x => x.Severity > DiagnosticSeverity.Info);
+ Assert.DoesNotContain(newCompilation.GetDiagnostics(TestContext.Current.CancellationToken), x => x.Severity > DiagnosticSeverity.Info);
}
[Fact]
@@ -273,10 +273,10 @@ partial class MagicOnionInitializer {}
);
// Run generator and update compilation
- driver = driver.RunGeneratorsAndUpdateCompilation(compilation, out var newCompilation, out var diagnostics);
+ driver = driver.RunGeneratorsAndUpdateCompilation(compilation, out var newCompilation, out var diagnostics, TestContext.Current.CancellationToken);
Assert.DoesNotContain(diagnostics, x => x.Severity > DiagnosticSeverity.Info);
- Assert.DoesNotContain(newCompilation.GetDiagnostics(), x => x.Severity > DiagnosticSeverity.Info);
+ Assert.DoesNotContain(newCompilation.GetDiagnostics(TestContext.Current.CancellationToken), x => x.Severity > DiagnosticSeverity.Info);
}
[Fact]
@@ -317,9 +317,9 @@ partial class MagicOnionInitializer {}
);
// Run generator and update compilation
- driver = driver.RunGeneratorsAndUpdateCompilation(compilation, out var newCompilation, out var diagnostics);
+ driver = driver.RunGeneratorsAndUpdateCompilation(compilation, out var newCompilation, out var diagnostics, TestContext.Current.CancellationToken);
Assert.DoesNotContain(diagnostics, x => x.Severity > DiagnosticSeverity.Info);
- Assert.DoesNotContain(newCompilation.GetDiagnostics(), x => x.Severity > DiagnosticSeverity.Info);
+ Assert.DoesNotContain(newCompilation.GetDiagnostics(TestContext.Current.CancellationToken), x => x.Severity > DiagnosticSeverity.Info);
}
}
diff --git a/tests/MagicOnion.Client.Tests/ClientStreamingTest.cs b/tests/MagicOnion.Client.Tests/ClientStreamingTest.cs
index a6a41eea9..d9b7bff31 100644
--- a/tests/MagicOnion.Client.Tests/ClientStreamingTest.cs
+++ b/tests/MagicOnion.Client.Tests/ClientStreamingTest.cs
@@ -37,8 +37,8 @@ public async Task WriteAndCompleteArgumentValueTypeReturnValueType()
// Act
var result = await client.ValueTypeReturnValueType();
- await result.RequestStream.WriteAsync(123);
- await result.RequestStream.WriteAsync(456);
+ await result.RequestStream.WriteAsync(123, CancellationToken.None);
+ await result.RequestStream.WriteAsync(456, CancellationToken.None);
await result.RequestStream.CompleteAsync();
// Assert
@@ -70,8 +70,8 @@ public async Task WriteAndCompleteArgumentRefTypeReturnValueType()
// Act
var result = await client.RefTypeReturnValueType();
- await result.RequestStream.WriteAsync("foo");
- await result.RequestStream.WriteAsync("bar");
+ await result.RequestStream.WriteAsync("foo", CancellationToken.None);
+ await result.RequestStream.WriteAsync("bar", CancellationToken.None);
await result.RequestStream.CompleteAsync();
// Assert
@@ -102,8 +102,8 @@ public async Task WriteAndCompleteArgumentValueTypeReturnRefType()
// Act
var result = await client.ValueTypeReturnRefType();
- await result.RequestStream.WriteAsync(123);
- await result.RequestStream.WriteAsync(456);
+ await result.RequestStream.WriteAsync(123, CancellationToken.None);
+ await result.RequestStream.WriteAsync(456, CancellationToken.None);
await result.RequestStream.CompleteAsync();
// Assert
@@ -134,8 +134,8 @@ public async Task WriteAndCompleteArgumentRefTypeReturnRefType()
// Act
var result = await client.RefTypeReturnRefType();
- await result.RequestStream.WriteAsync(Tuple.Create("Foo", "Bar"));
- await result.RequestStream.WriteAsync(Tuple.Create("Baz", "Hello"));
+ await result.RequestStream.WriteAsync(Tuple.Create("Foo", "Bar"), CancellationToken.None);
+ await result.RequestStream.WriteAsync(Tuple.Create("Baz", "Hello"), CancellationToken.None);
await result.RequestStream.CompleteAsync();
// Assert
diff --git a/tests/MagicOnion.Client.Tests/MagicOnion.Client.Tests.csproj b/tests/MagicOnion.Client.Tests/MagicOnion.Client.Tests.csproj
index 957b2448f..c02b2a0ed 100644
--- a/tests/MagicOnion.Client.Tests/MagicOnion.Client.Tests.csproj
+++ b/tests/MagicOnion.Client.Tests/MagicOnion.Client.Tests.csproj
@@ -15,7 +15,7 @@
-
+
runtime; build; native; contentfiles; analyzers; buildtransitive
all
diff --git a/tests/MagicOnion.Client.Tests/ServerStreamingTest.cs b/tests/MagicOnion.Client.Tests/ServerStreamingTest.cs
index 35f5e3d2c..78b910c78 100644
--- a/tests/MagicOnion.Client.Tests/ServerStreamingTest.cs
+++ b/tests/MagicOnion.Client.Tests/ServerStreamingTest.cs
@@ -42,11 +42,11 @@ public async Task OneParameterValueTypeReturnValueType()
// Act
var result = await client.ValueTypeReturnValueType(arg1);
- var moveNext1 = await result.ResponseStream.MoveNext(default);
+ var moveNext1 = await result.ResponseStream.MoveNext(TestContext.Current.CancellationToken);
var current1 = result.ResponseStream.Current;
- var moveNext2 = await result.ResponseStream.MoveNext(default);
+ var moveNext2 = await result.ResponseStream.MoveNext(TestContext.Current.CancellationToken);
var current2 = result.ResponseStream.Current;
- var moveNext3 = await result.ResponseStream.MoveNext(default);
+ var moveNext3 = await result.ResponseStream.MoveNext(TestContext.Current.CancellationToken);
// Assert
client.Should().NotBeNull();
@@ -84,11 +84,11 @@ public async Task OneParameterRefTypeReturnValueType()
// Act
var result = await client.RefTypeReturnValueType(arg1);
- var moveNext1 = await result.ResponseStream.MoveNext(default);
+ var moveNext1 = await result.ResponseStream.MoveNext(TestContext.Current.CancellationToken);
var current1 = result.ResponseStream.Current;
- var moveNext2 = await result.ResponseStream.MoveNext(default);
+ var moveNext2 = await result.ResponseStream.MoveNext(TestContext.Current.CancellationToken);
var current2 = result.ResponseStream.Current;
- var moveNext3 = await result.ResponseStream.MoveNext(default);
+ var moveNext3 = await result.ResponseStream.MoveNext(TestContext.Current.CancellationToken);
// Assert
client.Should().NotBeNull();
@@ -126,11 +126,11 @@ public async Task OneParameterValueTypeReturnRefType()
// Act
var result = await client.ValueTypeReturnRefType(arg1);
- var moveNext1 = await result.ResponseStream.MoveNext(default);
+ var moveNext1 = await result.ResponseStream.MoveNext(TestContext.Current.CancellationToken);
var current1 = result.ResponseStream.Current;
- var moveNext2 = await result.ResponseStream.MoveNext(default);
+ var moveNext2 = await result.ResponseStream.MoveNext(TestContext.Current.CancellationToken);
var current2 = result.ResponseStream.Current;
- var moveNext3 = await result.ResponseStream.MoveNext(default);
+ var moveNext3 = await result.ResponseStream.MoveNext(TestContext.Current.CancellationToken);
// Assert
client.Should().NotBeNull();
@@ -168,11 +168,11 @@ public async Task OneParameterRefTypeReturnRefType()
// Act
var result = await client.RefTypeReturnRefType(arg1);
- var moveNext1 = await result.ResponseStream.MoveNext(default);
+ var moveNext1 = await result.ResponseStream.MoveNext(TestContext.Current.CancellationToken);
var current1 = result.ResponseStream.Current;
- var moveNext2 = await result.ResponseStream.MoveNext(default);
+ var moveNext2 = await result.ResponseStream.MoveNext(TestContext.Current.CancellationToken);
var current2 = result.ResponseStream.Current;
- var moveNext3 = await result.ResponseStream.MoveNext(default);
+ var moveNext3 = await result.ResponseStream.MoveNext(TestContext.Current.CancellationToken);
// Assert
client.Should().NotBeNull();
diff --git a/tests/MagicOnion.Client.Tests/StreamingHubClientHeartbeatManagerTest.cs b/tests/MagicOnion.Client.Tests/StreamingHubClientHeartbeatManagerTest.cs
index 270eaa83a..ce39d8a4c 100644
--- a/tests/MagicOnion.Client.Tests/StreamingHubClientHeartbeatManagerTest.cs
+++ b/tests/MagicOnion.Client.Tests/StreamingHubClientHeartbeatManagerTest.cs
@@ -33,11 +33,11 @@ public async Task Interval_TimeoutDisabled()
// Act
manager.StartClientHeartbeatLoop();
timeProvider.Advance(TimeSpan.FromSeconds(1));
- await Task.Delay(10);
+ await Task.Delay(10, TestContext.Current.CancellationToken);
timeProvider.Advance(TimeSpan.FromSeconds(1));
- await Task.Delay(10);
+ await Task.Delay(10, TestContext.Current.CancellationToken);
timeProvider.Advance(TimeSpan.FromSeconds(1));
- await Task.Delay(10);
+ await Task.Delay(10, TestContext.Current.CancellationToken);
// Assert
Assert.True(channel.Reader.TryRead(out var heartbeat1));
@@ -74,24 +74,24 @@ public async Task Elapsed_RoundTripTime()
// Act
manager.StartClientHeartbeatLoop();
timeProvider.Advance(TimeSpan.FromMilliseconds(1000)); // Send
- await Task.Delay(10);
+ await Task.Delay(10, TestContext.Current.CancellationToken);
timeProvider.Advance(TimeSpan.FromMilliseconds(100));
- await Task.Delay(10);
+ await Task.Delay(10, TestContext.Current.CancellationToken);
manager.ProcessClientHeartbeatResponse(StreamingHubPayloadPool.Shared.RentOrCreate([0x95 /* Array(5) */, 0x7e /* 0x7e(127) */, 0x0 /* Sequence(0) */, .. ToMessagePackBytes(TimeSpan.FromMilliseconds(1000)) /* ClientSentAt */, 0xc0 /* Nil */, 0xc0 /* Nil */]));
timeProvider.Advance(TimeSpan.FromMilliseconds(900)); // Send
- await Task.Delay(10);
+ await Task.Delay(10, TestContext.Current.CancellationToken);
timeProvider.Advance(TimeSpan.FromMilliseconds(100));
- await Task.Delay(10);
+ await Task.Delay(10, TestContext.Current.CancellationToken);
manager.ProcessClientHeartbeatResponse(StreamingHubPayloadPool.Shared.RentOrCreate([0x95 /* Array(5) */, 0x7e /* 0x7e(127) */, 0x1 /* Sequence(1) */, .. ToMessagePackBytes(TimeSpan.FromMilliseconds(2000)) /* ClientSentAt */, 0xc0 /* Nil */, 0xc0 /* Nil */]));
timeProvider.Advance(TimeSpan.FromMilliseconds(900)); // Send
- await Task.Delay(10);
+ await Task.Delay(10, TestContext.Current.CancellationToken);
timeProvider.Advance(TimeSpan.FromMilliseconds(100));
- await Task.Delay(10);
+ await Task.Delay(10, TestContext.Current.CancellationToken);
manager.ProcessClientHeartbeatResponse(StreamingHubPayloadPool.Shared.RentOrCreate([0x95 /* Array(5) */, 0x7e /* 0x7e(127) */, 0x2 /* Sequence(2) */, .. ToMessagePackBytes(TimeSpan.FromMilliseconds(3000)) /* ClientSentAt */, 0xc0 /* Nil */, 0xc0 /* Nil */]));
- await Task.Delay(10);
+ await Task.Delay(10, TestContext.Current.CancellationToken);
// Assert
Assert.Equal(3, clientHeartbeatResponseReceived.Count);
@@ -132,9 +132,9 @@ public async Task Timeout_Not_Responding()
// Act
manager.StartClientHeartbeatLoop();
timeProvider.Advance(TimeSpan.FromSeconds(1));
- await Task.Delay(10);
+ await Task.Delay(10, TestContext.Current.CancellationToken);
timeProvider.Advance(TimeSpan.FromSeconds(1));
- await Task.Delay(10);
+ await Task.Delay(10, TestContext.Current.CancellationToken);
// Assert
Assert.True(channel.Reader.TryRead(out var heartbeat1));
@@ -170,23 +170,23 @@ public async Task Timeout_Keep()
manager.StartClientHeartbeatLoop();
timeProvider.Advance(TimeSpan.FromSeconds(1)); // Send a client heartbeat message
- await Task.Delay(10);
+ await Task.Delay(10, TestContext.Current.CancellationToken);
Assert.True(channel.Reader.TryRead(out var heartbeat1));
timeProvider.Advance(TimeSpan.FromMilliseconds(250));
- await Task.Delay(10);
+ await Task.Delay(10, TestContext.Current.CancellationToken);
Assert.False(manager.TimeoutToken.IsCancellationRequested);
// Received a response message from the server.
manager.ProcessClientHeartbeatResponse(StreamingHubPayloadPool.Shared.RentOrCreate([0x95 /* Array(5) */, 0x7e /* 0x7e(127) */, 0x0 /* Sequence(0) */, .. ToMessagePackBytes(origin.AddSeconds(1)) /* ClientSentAt */, 0xc0 /* Nil */, 0xc0 /* Nil */]));
timeProvider.Advance(TimeSpan.FromMilliseconds(250));
- await Task.Delay(10);
+ await Task.Delay(10, TestContext.Current.CancellationToken);
Assert.False(manager.TimeoutToken.IsCancellationRequested);
timeProvider.Advance(TimeSpan.FromMilliseconds(500));
- await Task.Delay(10);
+ await Task.Delay(10, TestContext.Current.CancellationToken);
Assert.False(manager.TimeoutToken.IsCancellationRequested);
Assert.True(channel.Reader.TryRead(out var heartbeat2));
@@ -217,26 +217,26 @@ public async Task Timeout_IntervalLongerThanTimeout_Not_Responding()
// Act & Assert
manager.StartClientHeartbeatLoop();
timeProvider.Advance(TimeSpan.FromSeconds(1)); // Send a client heartbeat message.
- await Task.Delay(10);
+ await Task.Delay(10, TestContext.Current.CancellationToken);
Assert.False(manager.TimeoutToken.IsCancellationRequested);
timeProvider.Advance(TimeSpan.FromSeconds(1)); // 1s has elapsed since the first message.
- await Task.Delay(10);
+ await Task.Delay(10, TestContext.Current.CancellationToken);
Assert.False(manager.TimeoutToken.IsCancellationRequested);
timeProvider.Advance(TimeSpan.FromSeconds(1)); // 2s has elapsed since the first message.
- await Task.Delay(10);
+ await Task.Delay(10, TestContext.Current.CancellationToken);
Assert.False(manager.TimeoutToken.IsCancellationRequested);
timeProvider.Advance(TimeSpan.FromMilliseconds(900)); // 2.9s has elapsed since the first message.
- await Task.Delay(10);
+ await Task.Delay(10, TestContext.Current.CancellationToken);
Assert.False(manager.TimeoutToken.IsCancellationRequested);
// Respond to the first message. but it does not respond to subsequent messages.
manager.ProcessClientHeartbeatResponse(StreamingHubPayloadPool.Shared.RentOrCreate([0x95 /* Array(5) */, 0x7e /* 0x7e(127) */, 0x0 /* Sequence(0) */, .. ToMessagePackBytes(origin.AddSeconds(1)) /* ClientSentAt */, 0xc0 /* Nil */, 0xc0 /* Nil */]));
timeProvider.Advance(TimeSpan.FromMilliseconds(100)); // 3s has elapsed since the first message.
- await Task.Delay(10);
+ await Task.Delay(10, TestContext.Current.CancellationToken);
Assert.True(manager.TimeoutToken.IsCancellationRequested);
}
@@ -265,19 +265,19 @@ public async Task Timeout_IntervalLongerThanTimeout_Keep()
// Act & Assert
manager.StartClientHeartbeatLoop();
timeProvider.Advance(TimeSpan.FromSeconds(1)); // Send a client heartbeat message.
- await Task.Delay(10);
+ await Task.Delay(10, TestContext.Current.CancellationToken);
Assert.False(manager.TimeoutToken.IsCancellationRequested);
timeProvider.Advance(TimeSpan.FromSeconds(1)); // 1s has elapsed since the first message.
- await Task.Delay(10);
+ await Task.Delay(10, TestContext.Current.CancellationToken);
Assert.False(manager.TimeoutToken.IsCancellationRequested);
timeProvider.Advance(TimeSpan.FromSeconds(1)); // 2s has elapsed since the first message.
- await Task.Delay(10);
+ await Task.Delay(10, TestContext.Current.CancellationToken);
Assert.False(manager.TimeoutToken.IsCancellationRequested);
timeProvider.Advance(TimeSpan.FromMilliseconds(900)); // 2.9s has elapsed since the first message.
- await Task.Delay(10);
+ await Task.Delay(10, TestContext.Current.CancellationToken);
Assert.False(manager.TimeoutToken.IsCancellationRequested);
// Respond to the first message. but it does not respond to subsequent messages.
@@ -286,7 +286,7 @@ public async Task Timeout_IntervalLongerThanTimeout_Keep()
manager.ProcessClientHeartbeatResponse(StreamingHubPayloadPool.Shared.RentOrCreate([0x95 /* Array(5) */, 0x7e /* 0x7e(127) */, 0x2 /* Sequence(2) */, .. ToMessagePackBytes(origin.AddSeconds(3)) /* ClientSentAt */, 0xc0 /* Nil */, 0xc0 /* Nil */]));
timeProvider.Advance(TimeSpan.FromMilliseconds(100)); // 3s has elapsed since the first message.
- await Task.Delay(10);
+ await Task.Delay(10, TestContext.Current.CancellationToken);
Assert.False(manager.TimeoutToken.IsCancellationRequested);
}
diff --git a/tests/MagicOnion.Client.Tests/StreamingHubTest.cs b/tests/MagicOnion.Client.Tests/StreamingHubTest.cs
index cbc568784..a77c2d119 100644
--- a/tests/MagicOnion.Client.Tests/StreamingHubTest.cs
+++ b/tests/MagicOnion.Client.Tests/StreamingHubTest.cs
@@ -449,11 +449,11 @@ public async Task ClientHeartbeat_Interval()
// Act
var t = client.Parameter_One(1234);
timeProvider.Advance(TimeSpan.FromMilliseconds(100));
- await Task.Delay(100); // Wait for processing queue.
+ await Task.Delay(100, TestContext.Current.CancellationToken); // Wait for processing queue.
timeProvider.Advance(TimeSpan.FromMilliseconds(100));
- await Task.Delay(100); // Wait for processing queue.
+ await Task.Delay(100, TestContext.Current.CancellationToken); // Wait for processing queue.
timeProvider.Advance(TimeSpan.FromMilliseconds(100));
- await Task.Delay(100); // Wait for processing queue.
+ await Task.Delay(100, TestContext.Current.CancellationToken); // Wait for processing queue.
// Assert
var (messageId, methodId, requestBody) = await helper.ReadRequestAsync();
@@ -494,11 +494,11 @@ public async Task ClientHeartbeat_FirstTime()
// Act
var waitForDisconnectTask = client.WaitForDisconnect();
timeProvider.Advance(TimeSpan.FromSeconds(1));
- await Task.Delay(100); // Wait for processing queue.
+ await Task.Delay(100, TestContext.Current.CancellationToken); // Wait for processing queue.
timeProvider.Advance(TimeSpan.FromSeconds(1));
- await Task.Delay(100); // Wait for processing queue.
+ await Task.Delay(100, TestContext.Current.CancellationToken); // Wait for processing queue.
timeProvider.Advance(TimeSpan.FromSeconds(1));
- await Task.Delay(100); // Wait for processing queue.
+ await Task.Delay(100, TestContext.Current.CancellationToken); // Wait for processing queue.
await waitForDisconnectTask.WaitAsync(timeout.Token);
// Assert
@@ -517,7 +517,7 @@ public async Task ServerHeartbeat_Respond()
// Act
var t = client.Parameter_One(1234);
helper.WriteResponseRaw([0x95 /* Array(5) */, 0x7f /* Type:127 */, 0x00 /* Sequence(0) */, .. (byte[])[0xcd, 0x30, 0x39] /* ServerSentAt */, 0xc0 /* Nil */, 0xc0 /* Extra */]); // Simulate heartbeat from the server.
- await Task.Delay(100);
+ await Task.Delay(100, TestContext.Current.CancellationToken);
// Assert
var (messageId, methodId, requestBody) = await helper.ReadRequestAsync();
@@ -543,7 +543,7 @@ public async Task ServerHeartbeat_ServerTime()
// Act
helper.WriteResponseRaw((byte[])[0x95 /* Array(5) */, 0x7f /* Type:127 */, 0x00 /* Sequence(0) */, .. (byte[])[0xcf, 0x00, 0x00, 0x01, 0x90, 0x6b, 0x97, 0x5c, 0x00] /* ServerSentAt */, 0xc0 /* Nil */, 0xc0 /* Extra(Nil) */]); // Simulate heartbeat from the server.
- await Task.Delay(100);
+ await Task.Delay(100, TestContext.Current.CancellationToken);
// Assert
var request1 = await helper.ReadRequestRawAsync();
@@ -567,7 +567,7 @@ public async Task ServerHeartbeat_Extra()
// Act
helper.WriteResponseRaw((byte[])[0x95 /* Array(5) */, 0x7f /* Type:127 */, 0x00 /* Sequence(0) */, .. (byte[])[ 0xcd, 0x30, 0x39 ] /* ServerSentAt */, 0xc0 /* Nil */, .."Hello World"u8 /* Extra */]); // Simulate heartbeat from the server.
- await Task.Delay(100);
+ await Task.Delay(100, TestContext.Current.CancellationToken);
// Assert
Assert.Equal([.. "Hello World"u8], received); // Respond to the heartbeat from the server.
@@ -609,11 +609,11 @@ public async Task WaitForDisconnectAsync_TimedOut()
// Act
var waitForDisconnectTask = client.WaitForDisconnectAsync();
timeProvider.Advance(TimeSpan.FromSeconds(1));
- await Task.Delay(100);
+ await Task.Delay(100, TestContext.Current.CancellationToken);
timeProvider.Advance(TimeSpan.FromSeconds(1));
- await Task.Delay(100);
+ await Task.Delay(100, TestContext.Current.CancellationToken);
timeProvider.Advance(TimeSpan.FromSeconds(1));
- await Task.Delay(100);
+ await Task.Delay(100, TestContext.Current.CancellationToken);
var disconnectionReason = await waitForDisconnectTask.WaitAsync(timeout.Token);
// Assert
@@ -692,12 +692,12 @@ public async Task Cancel_While_WritingStream()
{
TaskScheduler.UnobservedTaskException += unobservedTaskExceptionEventHandler;
await CoreAsync();
- await Task.Delay(100);
+ await Task.Delay(100, TestContext.Current.CancellationToken);
GC.Collect();
GC.Collect();
GC.Collect();
GC.Collect();
- await Task.Delay(100);
+ await Task.Delay(100, TestContext.Current.CancellationToken);
}
finally
{
@@ -727,8 +727,8 @@ static async Task CoreAsync()
{
// Ignore exception
}
- });
- await Task.Delay(100);
+ }, TestContext.Current.CancellationToken);
+ await Task.Delay(100, TestContext.Current.CancellationToken);
await client.DisposeAsync();
}
}
diff --git a/tests/MagicOnion.Integration.Tests/ClientFilterTest.cs b/tests/MagicOnion.Integration.Tests/ClientFilterTest.cs
index 0ff339dc8..fcde28f2a 100644
--- a/tests/MagicOnion.Integration.Tests/ClientFilterTest.cs
+++ b/tests/MagicOnion.Integration.Tests/ClientFilterTest.cs
@@ -2,7 +2,6 @@
using MagicOnion.Client;
using MagicOnion.Server;
-using Xunit.Abstractions;
using System.Diagnostics;
using Grpc.Net.Client;
using MagicOnion.Client.DynamicClient;
@@ -81,7 +80,7 @@ public async Task ErrorRetry(TestMagicOnionClientFactory clientFactory)
ex.RetryCount.Should().Be(3);
ex.LastException.Should().NotBeNull();
- logger.WriteLine(ex.LastException?.ToString());
+ logger.WriteLine(ex.LastException?.ToString() ?? "(null)");
}
}
public interface IClientFilterTestService : IService
diff --git a/tests/MagicOnion.Integration.Tests/HandCraftedStreamingHubClientTest.cs b/tests/MagicOnion.Integration.Tests/HandCraftedStreamingHubClientTest.cs
index 3c7b76f33..998933cf6 100644
--- a/tests/MagicOnion.Integration.Tests/HandCraftedStreamingHubClientTest.cs
+++ b/tests/MagicOnion.Integration.Tests/HandCraftedStreamingHubClientTest.cs
@@ -23,7 +23,7 @@ public async Task MethodParameterless()
// Arrange
var channel = GrpcChannel.ForAddress("http://localhost", new GrpcChannelOptions() { HttpClient = factory.CreateDefaultClient() });
var receiver = new Receiver();
- var clientConnectTask = StreamingHubClient.ConnectAsync(channel.CreateCallInvoker(), receiver, StreamingHubClientOptions.CreateWithDefault(), factoryProvider: HandCraftedClientFactoryProvider.Instance);
+ var clientConnectTask = StreamingHubClient.ConnectAsync(channel.CreateCallInvoker(), receiver, StreamingHubClientOptions.CreateWithDefault(), factoryProvider: HandCraftedClientFactoryProvider.Instance, cancellationToken: TestContext.Current.CancellationToken);
// Act
var client = await clientConnectTask;
@@ -39,12 +39,12 @@ public async Task Callback()
// Arrange
var channel = GrpcChannel.ForAddress("http://localhost", new GrpcChannelOptions() { HttpClient = factory.CreateDefaultClient() });
var receiver = new Receiver();
- var clientConnectTask = StreamingHubClient.ConnectAsync(channel.CreateCallInvoker(), receiver, StreamingHubClientOptions.CreateWithDefault(), factoryProvider: HandCraftedClientFactoryProvider.Instance);
+ var clientConnectTask = StreamingHubClient.ConnectAsync(channel.CreateCallInvoker(), receiver, StreamingHubClientOptions.CreateWithDefault(), factoryProvider: HandCraftedClientFactoryProvider.Instance, cancellationToken: TestContext.Current.CancellationToken);
// Act
var client = await clientConnectTask;
var retVal = await client.Callback(1234, "FooBarBaz");
- await Task.Delay(500); // Wait for the broadcast queue to be consumed.
+ await Task.Delay(500, TestContext.Current.CancellationToken); // Wait for the broadcast queue to be consumed.
// Assert
retVal.Should().Be(123);
diff --git a/tests/MagicOnion.Integration.Tests/MagicOnion.Integration.Tests.csproj b/tests/MagicOnion.Integration.Tests/MagicOnion.Integration.Tests.csproj
index 9f7493b38..af0666653 100644
--- a/tests/MagicOnion.Integration.Tests/MagicOnion.Integration.Tests.csproj
+++ b/tests/MagicOnion.Integration.Tests/MagicOnion.Integration.Tests.csproj
@@ -13,7 +13,7 @@
-
+
runtime; build; native; contentfiles; analyzers; buildtransitive
all
diff --git a/tests/MagicOnion.Integration.Tests/SerializerStreamingHubTest.cs b/tests/MagicOnion.Integration.Tests/SerializerStreamingHubTest.cs
index 1a2c00f70..331ff05a3 100644
--- a/tests/MagicOnion.Integration.Tests/SerializerStreamingHubTest.cs
+++ b/tests/MagicOnion.Integration.Tests/SerializerStreamingHubTest.cs
@@ -83,9 +83,9 @@ public async Task StreamingHub_Callback(TestStreamingHubClientFactory clientFact
// Act
var result = await client.Callback(12345, "6789");
- await Task.Delay(100);
+ await Task.Delay(100, TestContext.Current.CancellationToken);
var result2 = await client.Callback(98765, "43210");
- await Task.Delay(100);
+ await Task.Delay(100, TestContext.Current.CancellationToken);
// Assert
result.Should().Be(123);
diff --git a/tests/MagicOnion.Integration.Tests/StreamingHubClientDiagnosticHandlerTest.cs b/tests/MagicOnion.Integration.Tests/StreamingHubClientDiagnosticHandlerTest.cs
index 95012e464..6dbb75e6d 100644
--- a/tests/MagicOnion.Integration.Tests/StreamingHubClientDiagnosticHandlerTest.cs
+++ b/tests/MagicOnion.Integration.Tests/StreamingHubClientDiagnosticHandlerTest.cs
@@ -25,7 +25,8 @@ public async Task Request_Response()
var receiver = Substitute.For();
var client = await StreamingHubClient.ConnectAsync(
channel, receiver,
- factoryProvider: MagicOnionGeneratedClientInitializerStreamingHubDiagnosticHandler.StreamingHubClientFactoryProvider);
+ factoryProvider: MagicOnionGeneratedClientInitializerStreamingHubDiagnosticHandler.StreamingHubClientFactoryProvider,
+ cancellationToken: TestContext.Current.CancellationToken);
// Act
var result = await client.Parameter_Many(12345, "Hello✨", true);
@@ -55,7 +56,8 @@ public async Task Request_Parameterless_Response()
var receiver = Substitute.For();
var client = await StreamingHubClient.ConnectAsync(
channel, receiver,
- factoryProvider: MagicOnionGeneratedClientInitializerStreamingHubDiagnosticHandler.StreamingHubClientFactoryProvider);
+ factoryProvider: MagicOnionGeneratedClientInitializerStreamingHubDiagnosticHandler.StreamingHubClientFactoryProvider,
+ cancellationToken: TestContext.Current.CancellationToken);
// Act
var result = await client.Parameter_Zero();
@@ -85,7 +87,8 @@ public async Task Request_Response_Void()
var receiver = Substitute.For();
var client = await StreamingHubClient.ConnectAsync(
channel, receiver,
- factoryProvider: MagicOnionGeneratedClientInitializerStreamingHubDiagnosticHandler.StreamingHubClientFactoryProvider);
+ factoryProvider: MagicOnionGeneratedClientInitializerStreamingHubDiagnosticHandler.StreamingHubClientFactoryProvider,
+ cancellationToken: TestContext.Current.CancellationToken);
// Act
await client.NoReturn_Parameter_Many(12345, "Hello✨", true);
@@ -119,10 +122,11 @@ public async Task Request_Throw()
var receiver = Substitute.For();
var client = await StreamingHubClient.ConnectAsync(
channel, receiver,
- factoryProvider: MagicOnionGeneratedClientInitializerStreamingHubDiagnosticHandler.StreamingHubClientFactoryProvider);
+ factoryProvider: MagicOnionGeneratedClientInitializerStreamingHubDiagnosticHandler.StreamingHubClientFactoryProvider,
+ cancellationToken: TestContext.Current.CancellationToken);
// Act
- var ex = await Record.ExceptionAsync(async () => await client.Throw());
+ var ex = await Record.ExceptionAsync(() => client.Throw());
// Assert
Assert.Equal([DiagnosticHandler.EventType.OnRequestBegin, DiagnosticHandler.EventType.OnRequestEnd], diagnosticHandler.Events.Select(x => x.EventType));
@@ -150,11 +154,12 @@ public async Task Receiver()
var receiver = Substitute.For();
var client = await StreamingHubClient.ConnectAsync(
channel, receiver,
- factoryProvider: MagicOnionGeneratedClientInitializerStreamingHubDiagnosticHandler.StreamingHubClientFactoryProvider);
+ factoryProvider: MagicOnionGeneratedClientInitializerStreamingHubDiagnosticHandler.StreamingHubClientFactoryProvider,
+ cancellationToken: TestContext.Current.CancellationToken);
// Act
await client.CallReceiver_Parameter_Many(12345, "Hello✨", true);
- await Task.Delay(500); // Wait for broadcast queue to be consumed.
+ await Task.Delay(500, TestContext.Current.CancellationToken); // Wait for broadcast queue to be consumed.
// Assert
receiver.Received().Receiver_Parameter_Many(12345, "Hello✨", true);
diff --git a/tests/MagicOnion.Integration.Tests/StreamingHubClientResultTest.cs b/tests/MagicOnion.Integration.Tests/StreamingHubClientResultTest.cs
index c715a588d..232b1be6b 100644
--- a/tests/MagicOnion.Integration.Tests/StreamingHubClientResultTest.cs
+++ b/tests/MagicOnion.Integration.Tests/StreamingHubClientResultTest.cs
@@ -3,8 +3,6 @@
using MagicOnion.Client.DynamicClient;
using MagicOnion.Server.Hubs;
using Microsoft.Extensions.DependencyInjection;
-using Xunit.Abstractions;
-using Xunit.Sdk;
namespace MagicOnion.Integration.Tests;
@@ -257,13 +255,13 @@ public async Task Invoke_After_Disconnected(TestStreamingHubClientFactory client
// Act
_ = client.Invoke_After_Disconnected();
- await Task.Delay(200);
+ await Task.Delay(200, TestContext.Current.CancellationToken);
await client.DisposeAsync();
channel.Dispose();
signalFromClient.Release();
// Wait for complete processing the request on the server.
- await signalToClient.WaitAsync();
+ await signalToClient.WaitAsync(TestContext.Current.CancellationToken);
// Assert
//testOutputHelper.WriteLine(serverItems.GetValueOrDefault(nameof(IStreamingHubClientResultTestHub.Invoke_After_Disconnected) + "/Exception") + "");
diff --git a/tests/MagicOnion.Integration.Tests/StreamingHubInterfaceInheritanceTest.cs b/tests/MagicOnion.Integration.Tests/StreamingHubInterfaceInheritanceTest.cs
index 740a75b58..9d567f05c 100644
--- a/tests/MagicOnion.Integration.Tests/StreamingHubInterfaceInheritanceTest.cs
+++ b/tests/MagicOnion.Integration.Tests/StreamingHubInterfaceInheritanceTest.cs
@@ -34,7 +34,7 @@ public async Task InterfaceInheritance(TestStreamingHubClientFactory clientFacto
await client.MethodA();
await client.MethodB();
await client.MethodC();
- await Task.Delay(500); // Wait for broadcast queue to be consumed.
+ await Task.Delay(500, TestContext.Current.CancellationToken); // Wait for broadcast queue to be consumed.
// Assert
receiver.Received().Receiver_MethodA();
diff --git a/tests/MagicOnion.Integration.Tests/StreamingHubStressTest.cs b/tests/MagicOnion.Integration.Tests/StreamingHubStressTest.cs
index 7ec592df7..8042e9ccd 100644
--- a/tests/MagicOnion.Integration.Tests/StreamingHubStressTest.cs
+++ b/tests/MagicOnion.Integration.Tests/StreamingHubStressTest.cs
@@ -45,7 +45,7 @@ public async Task Short(TestStreamingHubClientFactory clientFactory)
Interlocked.Increment(ref count);
}
- await Task.Delay(500);
+ await Task.Delay(500, TestContext.Current.CancellationToken);
});
// Act
diff --git a/tests/MagicOnion.Integration.Tests/StreamingHubTest.UnknownMethodId.cs b/tests/MagicOnion.Integration.Tests/StreamingHubTest.UnknownMethodId.cs
index fe4aa638b..4ed6ca87c 100644
--- a/tests/MagicOnion.Integration.Tests/StreamingHubTest.UnknownMethodId.cs
+++ b/tests/MagicOnion.Integration.Tests/StreamingHubTest.UnknownMethodId.cs
@@ -17,7 +17,7 @@ public async Task UnknownMethodId(TestStreamingHubClientFactory clientFactory)
var client = await clientFactory.CreateAndConnectAsync(channel, receiver);
// Act
- var ex = await Record.ExceptionAsync(async () => await client.CustomMethodId().WaitAsync(TimeSpan.FromSeconds(1)));
+ var ex = await Record.ExceptionAsync(() => client.CustomMethodId().WaitAsync(TimeSpan.FromSeconds(1), TestContext.Current.CancellationToken));
// Assert
ex.Should().NotBeNull();
diff --git a/tests/MagicOnion.Integration.Tests/StreamingHubTest.cs b/tests/MagicOnion.Integration.Tests/StreamingHubTest.cs
index b73bd6f63..145cbb92e 100644
--- a/tests/MagicOnion.Integration.Tests/StreamingHubTest.cs
+++ b/tests/MagicOnion.Integration.Tests/StreamingHubTest.cs
@@ -234,7 +234,7 @@ public async Task Receiver_Parameter_Zero(TestStreamingHubClientFactory clientFa
// Act
await client.CallReceiver_Parameter_Zero();
- await Task.Delay(500); // Wait for broadcast queue to be consumed.
+ await Task.Delay(500, TestContext.Current.CancellationToken); // Wait for broadcast queue to be consumed.
// Assert
receiver.Received().Receiver_Parameter_Zero();
@@ -253,7 +253,7 @@ public async Task Receiver_Parameter_One(TestStreamingHubClientFactory clientFac
// Act
await client.CallReceiver_Parameter_One(12345);
- await Task.Delay(500); // Wait for broadcast queue to be consumed.
+ await Task.Delay(500, TestContext.Current.CancellationToken); // Wait for broadcast queue to be consumed.
// Assert
receiver.Received().Receiver_Parameter_One(12345);
@@ -272,7 +272,7 @@ public async Task Receiver_Parameter_Many(TestStreamingHubClientFactory clientFa
// Act
await client.CallReceiver_Parameter_Many(12345, "Hello✨", true);
- await Task.Delay(500); // Wait for broadcast queue to be consumed.
+ await Task.Delay(500, TestContext.Current.CancellationToken); // Wait for broadcast queue to be consumed.
// Assert
receiver.Received().Receiver_Parameter_Many(12345, "Hello✨", true);
@@ -400,7 +400,7 @@ public async Task Receiver_RefType(TestStreamingHubClientFactory clientFactory)
// Act
await client.CallReceiver_RefType(request);
- await Task.Delay(500); // Wait for broadcast queue to be consumed.
+ await Task.Delay(500, TestContext.Current.CancellationToken); // Wait for broadcast queue to be consumed.
// Assert
receiver.Received().Receiver_RefType(Arg.Is(y => y.Value == 123 + 456));
@@ -419,7 +419,7 @@ public async Task Receiver_RefType_Null(TestStreamingHubClientFactory clientFact
// Act
await client.CallReceiver_RefType_Null();
- await Task.Delay(500); // Wait for broadcast queue to be consumed.
+ await Task.Delay(500, TestContext.Current.CancellationToken); // Wait for broadcast queue to be consumed.
// Assert
receiver.Received().Receiver_RefType_Null(default);
@@ -442,8 +442,8 @@ public async Task ContinuationBlocking(TestStreamingHubClientFactory clientFacto
{
await client.CallReceiver_Delay(500); // The receiver will be called after 500ms.
Thread.Sleep(60 * 1000); // Block the continuation.
- });
- await Task.Delay(1000); // Wait for broadcast queue to be consumed.
+ }, TestContext.Current.CancellationToken);
+ await Task.Delay(1000, TestContext.Current.CancellationToken); // Wait for broadcast queue to be consumed.
// Assert
receiver.Received().Receiver_Delay();
@@ -455,10 +455,10 @@ public async Task ThrowReturnStatusException()
// Arrange
var channel = GrpcChannel.ForAddress("http://localhost", new GrpcChannelOptions() { HttpClient = factory.CreateDefaultClient() });
var receiver = Substitute.For();
- var client = await StreamingHubClient.ConnectAsync(channel, receiver);
+ var client = await StreamingHubClient.ConnectAsync(channel, receiver, cancellationToken: TestContext.Current.CancellationToken);
// Act
- var ex = (RpcException?)await Record.ExceptionAsync(async () => await client.ThrowReturnStatusException());
+ var ex = (RpcException?)await Record.ExceptionAsync(() => client.ThrowReturnStatusException());
// Assert
ex.Should().NotBeNull();
@@ -472,10 +472,10 @@ public async Task Throw()
// Arrange
var channel = GrpcChannel.ForAddress("http://localhost", new GrpcChannelOptions() { HttpClient = factory.CreateDefaultClient() });
var receiver = Substitute.For();
- var client = await StreamingHubClient.ConnectAsync(channel, receiver);
+ var client = await StreamingHubClient.ConnectAsync(channel, receiver, cancellationToken: TestContext.Current.CancellationToken);
// Act
- var ex = (RpcException?)await Record.ExceptionAsync(async () => await client.Throw());
+ var ex = (RpcException?)await Record.ExceptionAsync(() => client.Throw());
// Assert
ex.Should().NotBeNull();
@@ -514,12 +514,12 @@ public async Task Concurrency(TestStreamingHubClientFactory clientFactory)
{
var response = await client.Concurrent((x * 100) + count, $"Task{x}-{count}", x % 2 == 0);
results.Add((Index: count, Request: ((x * 100) + count, $"Task{x}-{count}", x % 2 == 0), Response: response));
- await semaphore.WaitAsync();
+ await semaphore.WaitAsync(TestContext.Current.CancellationToken);
count++;
}
- await Task.Delay(1000);
+ await Task.Delay(1000, TestContext.Current.CancellationToken);
return (Sequence: x, Results: results, ReceiverResults: receiverResults);
});
@@ -555,7 +555,7 @@ public async Task Void_Parameter_Zero(TestStreamingHubClientFactory clientFactor
// Act
client.Void_Parameter_Zero();
- await Task.Delay(500); // Wait for broadcast queue to be consumed.
+ await Task.Delay(500, TestContext.Current.CancellationToken); // Wait for broadcast queue to be consumed.
// Assert
receiver.Received().Receiver_Test_Void_Parameter_Zero();
@@ -574,7 +574,7 @@ public async Task Void_Parameter_One(TestStreamingHubClientFactory clientFactory
// Act
client.Void_Parameter_One(12345);
- await Task.Delay(500); // Wait for broadcast queue to be consumed.
+ await Task.Delay(500, TestContext.Current.CancellationToken); // Wait for broadcast queue to be consumed.
// Assert
receiver.Received().Receiver_Test_Void_Parameter_One(12345);
@@ -593,7 +593,7 @@ public async Task Void_Parameter_Many(TestStreamingHubClientFactory clientFactor
// Act
client.Void_Parameter_Many(12345, "Hello✨", true);
- await Task.Delay(500); // Wait for broadcast queue to be consumed.
+ await Task.Delay(500, TestContext.Current.CancellationToken); // Wait for broadcast queue to be consumed.
// Assert
receiver.Received().Receiver_Test_Void_Parameter_Many(12345, "Hello✨", true);
@@ -654,7 +654,7 @@ public async Task CustomMethodId_Receiver(TestStreamingHubClientFactory clientFa
// Act
await client.CallReceiver_CustomMethodId();
- await Task.Delay(500); // Wait for broadcast queue to be consumed.
+ await Task.Delay(500, TestContext.Current.CancellationToken); // Wait for broadcast queue to be consumed.
// Assert
receiver.Received().Receiver_CustomMethodId();
diff --git a/tests/MagicOnion.Integration.Tests/StreamingServiceTest.cs b/tests/MagicOnion.Integration.Tests/StreamingServiceTest.cs
index 0e9e8b8c4..9dd222d4d 100644
--- a/tests/MagicOnion.Integration.Tests/StreamingServiceTest.cs
+++ b/tests/MagicOnion.Integration.Tests/StreamingServiceTest.cs
@@ -36,8 +36,8 @@ public async Task ClientStreaming_1(TestMagicOnionClientFactory clientFactory)
var result = await client.ClientStreaming();
// Act
- await result.RequestStream.WriteAsync((123, 456));
- await result.RequestStream.WriteAsync((789, 123));
+ await result.RequestStream.WriteAsync((123, 456), CancellationToken.None);
+ await result.RequestStream.WriteAsync((789, 123), CancellationToken.None);
await result.RequestStream.CompleteAsync();
var response = await result.ResponseAsync;
@@ -56,7 +56,7 @@ public async Task ServerStreaming_1(TestMagicOnionClientFactory clientFactory)
// Act
var sum = 0;
- await foreach (var item in result.ResponseStream.ReadAllAsync())
+ await foreach (var item in result.ResponseStream.ReadAllAsync(CancellationToken.None))
{
sum += item;
}
@@ -78,14 +78,14 @@ public async Task DuplexStreaming_1(TestMagicOnionClientFactory clientFactory)
var sum = 0;
var readResponseTask = Task.Run(async () =>
{
- await foreach (var response in result.ResponseStream.ReadAllAsync())
+ await foreach (var response in result.ResponseStream.ReadAllAsync(TestContext.Current.CancellationToken))
{
sum += response;
}
- });
- await result.RequestStream.WriteAsync((123, 456));
- await result.RequestStream.WriteAsync((789, 123));
- await result.RequestStream.WriteAsync((111, 222));
+ }, TestContext.Current.CancellationToken);
+ await result.RequestStream.WriteAsync((123, 456), CancellationToken.None);
+ await result.RequestStream.WriteAsync((789, 123), CancellationToken.None);
+ await result.RequestStream.WriteAsync((111, 222), CancellationToken.None);
await result.RequestStream.CompleteAsync();
await readResponseTask;
@@ -103,8 +103,8 @@ public async Task ClientStreamingRefType_1(TestMagicOnionClientFactory clientFac
var result = await client.ClientStreamingRefType();
// Act
- await result.RequestStream.WriteAsync(new MyStreamingRequest(123, 456));
- await result.RequestStream.WriteAsync(new MyStreamingRequest(789, 123));
+ await result.RequestStream.WriteAsync(new MyStreamingRequest(123, 456), CancellationToken.None);
+ await result.RequestStream.WriteAsync(new MyStreamingRequest(789, 123), CancellationToken.None);
await result.RequestStream.CompleteAsync();
var response = await result.ResponseAsync;
@@ -123,7 +123,7 @@ public async Task ServerStreamingRefType_1(TestMagicOnionClientFactory clientFac
// Act
var sum = 0;
- await foreach (var item in result.ResponseStream.ReadAllAsync())
+ await foreach (var item in result.ResponseStream.ReadAllAsync(TestContext.Current.CancellationToken))
{
sum += item.Value;
}
@@ -145,14 +145,14 @@ public async Task DuplexStreamingRefType_1(TestMagicOnionClientFactory clientFac
var sum = 0;
var readResponseTask = Task.Run(async () =>
{
- await foreach (var response in result.ResponseStream.ReadAllAsync())
+ await foreach (var response in result.ResponseStream.ReadAllAsync(TestContext.Current.CancellationToken))
{
sum += response.Value;
}
- });
- await result.RequestStream.WriteAsync(new MyStreamingRequest(123, 456));
- await result.RequestStream.WriteAsync(new MyStreamingRequest(789, 123));
- await result.RequestStream.WriteAsync(new MyStreamingRequest(111, 222));
+ }, TestContext.Current.CancellationToken);
+ await result.RequestStream.WriteAsync(new MyStreamingRequest(123, 456), CancellationToken.None);
+ await result.RequestStream.WriteAsync(new MyStreamingRequest(789, 123), CancellationToken.None);
+ await result.RequestStream.WriteAsync(new MyStreamingRequest(111, 222), CancellationToken.None);
await result.RequestStream.CompleteAsync();
await readResponseTask;
@@ -170,8 +170,8 @@ public async Task ClientStreamingRefType_RequestResponseNull(TestMagicOnionClien
var result = await client.ClientStreamingRefTypeReturnsNull();
// Act
- await result.RequestStream.WriteAsync(null);
- await result.RequestStream.WriteAsync(null);
+ await result.RequestStream.WriteAsync(null, CancellationToken.None);
+ await result.RequestStream.WriteAsync(null, CancellationToken.None);
await result.RequestStream.CompleteAsync();
var response = await result.ResponseAsync;
@@ -190,7 +190,7 @@ public async Task ServerStreamingRefType_RequestResponseNull(TestMagicOnionClien
// Act
var nullResponseCount = 0;
- await foreach (var response in result.ResponseStream.ReadAllAsync())
+ await foreach (var response in result.ResponseStream.ReadAllAsync(TestContext.Current.CancellationToken))
{
nullResponseCount += response is null ? 1 : 0;
}
@@ -212,14 +212,14 @@ public async Task DuplexStreamingRefType_RequestResponseNull(TestMagicOnionClien
var nullResponseCount = 0;
var readResponseTask = Task.Run(async () =>
{
- await foreach (var response in result.ResponseStream.ReadAllAsync())
+ await foreach (var response in result.ResponseStream.ReadAllAsync(TestContext.Current.CancellationToken))
{
nullResponseCount += response is null ? 1 : 0;
}
- });
- await result.RequestStream.WriteAsync(null);
- await result.RequestStream.WriteAsync(null);
- await result.RequestStream.WriteAsync(null);
+ }, TestContext.Current.CancellationToken);
+ await result.RequestStream.WriteAsync(null, CancellationToken.None);
+ await result.RequestStream.WriteAsync(null, CancellationToken.None);
+ await result.RequestStream.WriteAsync(null, CancellationToken.None);
await result.RequestStream.CompleteAsync();
await readResponseTask;
diff --git a/tests/MagicOnion.Integration.Tests/TestStreamingHubClientFactory.cs b/tests/MagicOnion.Integration.Tests/TestStreamingHubClientFactory.cs
index 33f5b08ce..c0d17e533 100644
--- a/tests/MagicOnion.Integration.Tests/TestStreamingHubClientFactory.cs
+++ b/tests/MagicOnion.Integration.Tests/TestStreamingHubClientFactory.cs
@@ -8,5 +8,5 @@ public record TestStreamingHubClientFactory(string Name, IStreamingHubClientFact
public override string ToString() => Name;
public Task CreateAndConnectAsync(ChannelBase channelBase, TReceiver receiver, IMagicOnionSerializerProvider? serializerProvider = default)
where T : IStreamingHub
- => StreamingHubClient.ConnectAsync(channelBase.CreateCallInvoker(), receiver, serializerProvider: serializerProvider, factoryProvider: FactoryProvider);
+ => StreamingHubClient.ConnectAsync(channelBase.CreateCallInvoker(), receiver, serializerProvider: serializerProvider, factoryProvider: FactoryProvider, cancellationToken: TestContext.Current.CancellationToken);
}
diff --git a/tests/MagicOnion.Serialization.MemoryPack.Tests/MagicOnion.Serialization.MemoryPack.Tests.csproj b/tests/MagicOnion.Serialization.MemoryPack.Tests/MagicOnion.Serialization.MemoryPack.Tests.csproj
index 2b380b7f2..dcdc7e408 100644
--- a/tests/MagicOnion.Serialization.MemoryPack.Tests/MagicOnion.Serialization.MemoryPack.Tests.csproj
+++ b/tests/MagicOnion.Serialization.MemoryPack.Tests/MagicOnion.Serialization.MemoryPack.Tests.csproj
@@ -12,7 +12,7 @@
-
+
runtime; build; native; contentfiles; analyzers; buildtransitive
all
diff --git a/tests/MagicOnion.Serialization.MemoryPack.Tests/MemoryPackSerializerStreamingHubTest.cs b/tests/MagicOnion.Serialization.MemoryPack.Tests/MemoryPackSerializerStreamingHubTest.cs
index 4a07485a2..9ece9b69d 100644
--- a/tests/MagicOnion.Serialization.MemoryPack.Tests/MemoryPackSerializerStreamingHubTest.cs
+++ b/tests/MagicOnion.Serialization.MemoryPack.Tests/MemoryPackSerializerStreamingHubTest.cs
@@ -26,7 +26,7 @@ public async Task StreamingHub_ReturnCustomObject()
// Arrange
var channel = GrpcChannel.ForAddress("http://localhost", new GrpcChannelOptions() { HttpClient = factory.CreateDefaultClient() });
var receiver = new Receiver();
- var client = await StreamingHubClient.ConnectAsync(channel, receiver, serializerProvider: MemoryPackMagicOnionSerializerProvider.Instance);
+ var client = await StreamingHubClient.ConnectAsync(channel, receiver, serializerProvider: MemoryPackMagicOnionSerializerProvider.Instance, cancellationToken: TestContext.Current.CancellationToken);
// Act
var result = await client.MethodReturnCustomObject();
@@ -43,7 +43,7 @@ public async Task StreamingHub_Parameterless()
// Arrange
var channel = GrpcChannel.ForAddress("http://localhost", new GrpcChannelOptions() { HttpClient = factory.CreateDefaultClient() });
var receiver = new Receiver();
- var client = await StreamingHubClient.ConnectAsync(channel, receiver, serializerProvider: MemoryPackMagicOnionSerializerProvider.Instance);
+ var client = await StreamingHubClient.ConnectAsync(channel, receiver, serializerProvider: MemoryPackMagicOnionSerializerProvider.Instance, cancellationToken: TestContext.Current.CancellationToken);
// Act
var result = await client.MethodParameterless();
@@ -58,7 +58,7 @@ public async Task StreamingHub_Parameter_One()
// Arrange
var channel = GrpcChannel.ForAddress("http://localhost", new GrpcChannelOptions() { HttpClient = factory.CreateDefaultClient() });
var receiver = new Receiver();
- var client = await StreamingHubClient.ConnectAsync(channel, receiver, serializerProvider: MemoryPackMagicOnionSerializerProvider.Instance);
+ var client = await StreamingHubClient.ConnectAsync(channel, receiver, serializerProvider: MemoryPackMagicOnionSerializerProvider.Instance, cancellationToken: TestContext.Current.CancellationToken);
// Act
var result = await client.MethodParameter_One(12345);
@@ -73,7 +73,7 @@ public async Task StreamingHub_Parameter_Many()
// Arrange
var channel = GrpcChannel.ForAddress("http://localhost", new GrpcChannelOptions() { HttpClient = factory.CreateDefaultClient() });
var receiver = new Receiver();
- var client = await StreamingHubClient.ConnectAsync(channel, receiver, serializerProvider: MemoryPackMagicOnionSerializerProvider.Instance);
+ var client = await StreamingHubClient.ConnectAsync(channel, receiver, serializerProvider: MemoryPackMagicOnionSerializerProvider.Instance, cancellationToken: TestContext.Current.CancellationToken);
// Act
var result = await client.MethodParameter_Many(12345, "6789");
@@ -88,7 +88,7 @@ public async Task StreamingHub_Parameter_CustomObject()
// Arrange
var channel = GrpcChannel.ForAddress("http://localhost", new GrpcChannelOptions() { HttpClient = factory.CreateDefaultClient() });
var receiver = new Receiver();
- var client = await StreamingHubClient.ConnectAsync(channel, receiver, serializerProvider: MemoryPackMagicOnionSerializerProvider.Instance);
+ var client = await StreamingHubClient.ConnectAsync(channel, receiver, serializerProvider: MemoryPackMagicOnionSerializerProvider.Instance, cancellationToken: TestContext.Current.CancellationToken);
// Act
var result = await client.MethodParameter_CustomObject(new MyRequestResponse() { Item1 = 12345, Item2 = "6789" });
@@ -103,13 +103,13 @@ public async Task StreamingHub_Callback()
// Arrange
var channel = GrpcChannel.ForAddress("http://localhost", new GrpcChannelOptions() { HttpClient = factory.CreateDefaultClient() });
var receiver = new Receiver();
- var client = await StreamingHubClient.ConnectAsync(channel, receiver, serializerProvider: MemoryPackMagicOnionSerializerProvider.Instance);
+ var client = await StreamingHubClient.ConnectAsync(channel, receiver, serializerProvider: MemoryPackMagicOnionSerializerProvider.Instance, cancellationToken: TestContext.Current.CancellationToken);
// Act
var result = await client.Callback(12345, "6789");
- await Task.Delay(100);
+ await Task.Delay(100, TestContext.Current.CancellationToken);
var result2 = await client.Callback(98765, "43210");
- await Task.Delay(100);
+ await Task.Delay(100, TestContext.Current.CancellationToken);
// Assert
result.Should().Be(123);
@@ -125,13 +125,13 @@ public async Task StreamingHub_CallbackCustomObject()
// Arrange
var channel = GrpcChannel.ForAddress("http://localhost", new GrpcChannelOptions() { HttpClient = factory.CreateDefaultClient() });
var receiver = new Receiver();
- var client = await StreamingHubClient.ConnectAsync(channel, receiver, serializerProvider: MemoryPackMagicOnionSerializerProvider.Instance);
+ var client = await StreamingHubClient.ConnectAsync(channel, receiver, serializerProvider: MemoryPackMagicOnionSerializerProvider.Instance, cancellationToken: TestContext.Current.CancellationToken);
// Act
var result = await client.CallbackCustomObject(new MyRequestResponse() { Item1 = 12345, Item2 = "6789" });
- await Task.Delay(100);
+ await Task.Delay(100, TestContext.Current.CancellationToken);
var result2 = await client.CallbackCustomObject(new MyRequestResponse() { Item1 = 98765, Item2 = "43210" });
- await Task.Delay(100);
+ await Task.Delay(100, TestContext.Current.CancellationToken);
// Assert
result.Should().Be(123);
@@ -147,10 +147,10 @@ public async Task StreamingHub_ThrowReturnStatusException()
// Arrange
var channel = GrpcChannel.ForAddress("http://localhost", new GrpcChannelOptions() { HttpClient = factory.CreateDefaultClient() });
var receiver = new Receiver();
- var client = await StreamingHubClient.ConnectAsync(channel, receiver, serializerProvider: MemoryPackMagicOnionSerializerProvider.Instance);
+ var client = await StreamingHubClient.ConnectAsync(channel, receiver, serializerProvider: MemoryPackMagicOnionSerializerProvider.Instance, cancellationToken: TestContext.Current.CancellationToken);
// Act
- var ex = (RpcException?)await Record.ExceptionAsync(async () => await client.ThrowReturnStatusException());
+ var ex = (RpcException?)await Record.ExceptionAsync(() => client.ThrowReturnStatusException());
// Assert
ex.Should().NotBeNull();
@@ -164,10 +164,10 @@ public async Task StreamingHub_Throw()
// Arrange
var channel = GrpcChannel.ForAddress("http://localhost", new GrpcChannelOptions() { HttpClient = factory.CreateDefaultClient() });
var receiver = new Receiver();
- var client = await StreamingHubClient.ConnectAsync(channel, receiver, serializerProvider: MemoryPackMagicOnionSerializerProvider.Instance);
+ var client = await StreamingHubClient.ConnectAsync(channel, receiver, serializerProvider: MemoryPackMagicOnionSerializerProvider.Instance, cancellationToken: TestContext.Current.CancellationToken);
// Act
- var ex = (RpcException?)await Record.ExceptionAsync(async () => await client.Throw());
+ var ex = (RpcException?)await Record.ExceptionAsync(() => client.Throw());
// Assert
ex.Should().NotBeNull();
@@ -182,10 +182,10 @@ public async Task StreamingHub_Throw_WithServerStackTrace()
var factory = this.factory.WithWebHostBuilder(builder => builder.ConfigureServices(services => services.Configure(options => options.IsReturnExceptionStackTraceInErrorDetail = true)));
var channel = GrpcChannel.ForAddress("http://localhost", new GrpcChannelOptions() { HttpClient = factory.CreateDefaultClient() });
var receiver = new Receiver();
- var client = await StreamingHubClient.ConnectAsync(channel, receiver, serializerProvider: MemoryPackMagicOnionSerializerProvider.Instance);
+ var client = await StreamingHubClient.ConnectAsync(channel, receiver, serializerProvider: MemoryPackMagicOnionSerializerProvider.Instance, cancellationToken: TestContext.Current.CancellationToken);
// Act
- var ex = (RpcException?)await Record.ExceptionAsync(async () => await client.Throw());
+ var ex = (RpcException?)await Record.ExceptionAsync(() => client.Throw());
// Assert
ex.Should().NotBeNull();
diff --git a/tests/MagicOnion.Serialization.MessagePack.Tests/MagicOnion.Serialization.MessagePack.Tests.csproj b/tests/MagicOnion.Serialization.MessagePack.Tests/MagicOnion.Serialization.MessagePack.Tests.csproj
index 179ebc8db..3166d4a8b 100644
--- a/tests/MagicOnion.Serialization.MessagePack.Tests/MagicOnion.Serialization.MessagePack.Tests.csproj
+++ b/tests/MagicOnion.Serialization.MessagePack.Tests/MagicOnion.Serialization.MessagePack.Tests.csproj
@@ -12,7 +12,7 @@
-
+
runtime; build; native; contentfiles; analyzers; buildtransitive
all
diff --git a/tests/MagicOnion.Serialization.MessagePack.Tests/UnsafeDirectBlitResolverTest.cs b/tests/MagicOnion.Serialization.MessagePack.Tests/UnsafeDirectBlitResolverTest.cs
index c9d065bc0..ff17ed7ba 100644
--- a/tests/MagicOnion.Serialization.MessagePack.Tests/UnsafeDirectBlitResolverTest.cs
+++ b/tests/MagicOnion.Serialization.MessagePack.Tests/UnsafeDirectBlitResolverTest.cs
@@ -15,9 +15,9 @@ public void SerializeTest()
var s = new MyStruct { X = 10, Y = 99, Z = 999 };
- var bin = MessagePackSerializer.Serialize(s, options);
+ var bin = MessagePackSerializer.Serialize(s, options, cancellationToken: TestContext.Current.CancellationToken);
- var z = MessagePackSerializer.Deserialize(bin, options);
+ var z = MessagePackSerializer.Deserialize(bin, options, cancellationToken: TestContext.Current.CancellationToken);
z.X.Should().Be(10);
z.Y.Should().Be(99);
diff --git a/tests/MagicOnion.Server.JsonTranscoding.Tests/MagicOnion.Server.JsonTranscoding.Tests.csproj b/tests/MagicOnion.Server.JsonTranscoding.Tests/MagicOnion.Server.JsonTranscoding.Tests.csproj
index cd75ea3ae..0561a8af2 100644
--- a/tests/MagicOnion.Server.JsonTranscoding.Tests/MagicOnion.Server.JsonTranscoding.Tests.csproj
+++ b/tests/MagicOnion.Server.JsonTranscoding.Tests/MagicOnion.Server.JsonTranscoding.Tests.csproj
@@ -16,7 +16,7 @@
-
+
diff --git a/tests/MagicOnion.Server.JsonTranscoding.Tests/NonUnaryMethodsTest.cs b/tests/MagicOnion.Server.JsonTranscoding.Tests/NonUnaryMethodsTest.cs
index 1f178a3cc..e72b13fe7 100644
--- a/tests/MagicOnion.Server.JsonTranscoding.Tests/NonUnaryMethodsTest.cs
+++ b/tests/MagicOnion.Server.JsonTranscoding.Tests/NonUnaryMethodsTest.cs
@@ -18,7 +18,7 @@ public async Task IgnoreStreamingHub()
var httpClient = factory.CreateDefaultClient();
// Act
- var response = await httpClient.PostAsync($"http://localhost/webapi/ITestHub/Connect", new StringContent(string.Empty, new MediaTypeHeaderValue("application/json")));
+ var response = await httpClient.PostAsync($"http://localhost/webapi/ITestHub/Connect", new StringContent(string.Empty, new MediaTypeHeaderValue("application/json")), cancellationToken: TestContext.Current.CancellationToken);
// Assert
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
@@ -31,7 +31,7 @@ public async Task NotImplemented_ServerStreaming()
var httpClient = factory.CreateDefaultClient();
// Act
- var response = await httpClient.PostAsync($"http://localhost/webapi/INotSupportedMethodsService/ServerStreamingMethod", new StringContent(string.Empty, new MediaTypeHeaderValue("application/json")));
+ var response = await httpClient.PostAsync($"http://localhost/webapi/INotSupportedMethodsService/ServerStreamingMethod", new StringContent(string.Empty, new MediaTypeHeaderValue("application/json")), cancellationToken: TestContext.Current.CancellationToken);
// Assert
Assert.Equal(HttpStatusCode.NotImplemented, response.StatusCode);
@@ -44,7 +44,7 @@ public async Task NotImplemented_ClientStreaming()
var httpClient = factory.CreateDefaultClient();
// Act
- var response = await httpClient.PostAsync($"http://localhost/webapi/INotSupportedMethodsService/ClientStreamingMethod", new StringContent(string.Empty, new MediaTypeHeaderValue("application/json")));
+ var response = await httpClient.PostAsync($"http://localhost/webapi/INotSupportedMethodsService/ClientStreamingMethod", new StringContent(string.Empty, new MediaTypeHeaderValue("application/json")), cancellationToken: TestContext.Current.CancellationToken);
// Assert
Assert.Equal(HttpStatusCode.NotImplemented, response.StatusCode);
@@ -57,7 +57,7 @@ public async Task NotImplemented_DuplexStreaming()
var httpClient = factory.CreateDefaultClient();
// Act
- var response = await httpClient.PostAsync($"http://localhost/webapi/INotSupportedMethodsService/DuplexStreamingMethod", new StringContent(string.Empty, new MediaTypeHeaderValue("application/json")));
+ var response = await httpClient.PostAsync($"http://localhost/webapi/INotSupportedMethodsService/DuplexStreamingMethod", new StringContent(string.Empty, new MediaTypeHeaderValue("application/json")), cancellationToken: TestContext.Current.CancellationToken);
// Assert
Assert.Equal(HttpStatusCode.NotImplemented, response.StatusCode);
diff --git a/tests/MagicOnion.Server.JsonTranscoding.Tests/UnaryFunctionalTests.cs b/tests/MagicOnion.Server.JsonTranscoding.Tests/UnaryFunctionalTests.cs
index 0c3243966..1bfdbc5db 100644
--- a/tests/MagicOnion.Server.JsonTranscoding.Tests/UnaryFunctionalTests.cs
+++ b/tests/MagicOnion.Server.JsonTranscoding.Tests/UnaryFunctionalTests.cs
@@ -17,7 +17,7 @@ public async Task NotImplemented()
var httpClient = factory.CreateDefaultClient();
// Act
- var response = await httpClient.PostAsync($"http://localhost/webapi/ITestService/NotImplemented", new StringContent(string.Empty, new MediaTypeHeaderValue("application/json")));
+ var response = await httpClient.PostAsync($"http://localhost/webapi/ITestService/NotImplemented", new StringContent(string.Empty, new MediaTypeHeaderValue("application/json")), cancellationToken: TestContext.Current.CancellationToken);
// Assert
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
@@ -30,8 +30,8 @@ public async Task Method_NoParameter_NoResult()
var httpClient = factory.CreateDefaultClient();
// Act
- var response = await httpClient.PostAsync($"http://localhost/webapi/ITestService/Method_NoParameter_NoResult", new StringContent(string.Empty, new MediaTypeHeaderValue("application/json")));
- var content = await response.Content.ReadAsStringAsync();
+ var response = await httpClient.PostAsync($"http://localhost/webapi/ITestService/Method_NoParameter_NoResult", new StringContent(string.Empty, new MediaTypeHeaderValue("application/json")), cancellationToken: TestContext.Current.CancellationToken);
+ var content = await response.Content.ReadAsStringAsync(TestContext.Current.CancellationToken);
// Assert
var result = default(object); // null
@@ -49,8 +49,8 @@ public async Task Method_NoParameter_NoResult_IgnoreBody()
var requestBody = "{}";
// Act
- var response = await httpClient.PostAsync($"http://localhost/webapi/ITestService/Method_NoParameter_NoResult", new StringContent(requestBody, new MediaTypeHeaderValue("application/json")));
- var content = await response.Content.ReadAsStringAsync();
+ var response = await httpClient.PostAsync($"http://localhost/webapi/ITestService/Method_NoParameter_NoResult", new StringContent(requestBody, new MediaTypeHeaderValue("application/json")), cancellationToken: TestContext.Current.CancellationToken);
+ var content = await response.Content.ReadAsStringAsync(TestContext.Current.CancellationToken);
// Assert
var result = default(object); // null
@@ -67,8 +67,8 @@ public async Task Method_NoParameter_ResultRefType()
var httpClient = factory.CreateDefaultClient();
// Act
- var response = await httpClient.PostAsync($"http://localhost/webapi/ITestService/Method_NoParameter_ResultRefType", new StringContent(string.Empty, new MediaTypeHeaderValue("application/json")));
- var content = await response.Content.ReadAsStringAsync();
+ var response = await httpClient.PostAsync($"http://localhost/webapi/ITestService/Method_NoParameter_ResultRefType", new StringContent(string.Empty, new MediaTypeHeaderValue("application/json")), cancellationToken: TestContext.Current.CancellationToken);
+ var content = await response.Content.ReadAsStringAsync(TestContext.Current.CancellationToken);
// Assert
var result = nameof(Method_NoParameter_ResultRefType); // string
@@ -84,8 +84,8 @@ public async Task Method_NoParameter_ResultComplexType()
var httpClient = factory.CreateDefaultClient();
// Act
- var response = await httpClient.PostAsync($"http://localhost/webapi/ITestService/Method_NoParameter_ResultComplexType", new StringContent(string.Empty, new MediaTypeHeaderValue("application/json")));
- var content = await response.Content.ReadAsStringAsync();
+ var response = await httpClient.PostAsync($"http://localhost/webapi/ITestService/Method_NoParameter_ResultComplexType", new StringContent(string.Empty, new MediaTypeHeaderValue("application/json")), cancellationToken: TestContext.Current.CancellationToken);
+ var content = await response.Content.ReadAsStringAsync(TestContext.Current.CancellationToken);
// Assert
Assert.Equivalent(new TestResponse()
@@ -113,8 +113,8 @@ public async Task Method_OneParameter_NoResult()
""";
// Act
- var response = await httpClient.PostAsync($"http://localhost/webapi/ITestService/Method_OneParameter_NoResult", new StringContent(requestBody, new MediaTypeHeaderValue("application/json")));
- var content = await response.Content.ReadAsStringAsync();
+ var response = await httpClient.PostAsync($"http://localhost/webapi/ITestService/Method_OneParameter_NoResult", new StringContent(requestBody, new MediaTypeHeaderValue("application/json")), cancellationToken: TestContext.Current.CancellationToken);
+ var content = await response.Content.ReadAsStringAsync(TestContext.Current.CancellationToken);
// Assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
@@ -132,8 +132,8 @@ public async Task Method_TwoParameter_NoResult()
""";
// Act
- var response = await httpClient.PostAsync($"http://localhost/webapi/ITestService/Method_TwoParameter_NoResult", new StringContent(requestBody, new MediaTypeHeaderValue("application/json")));
- var content = await response.Content.ReadAsStringAsync();
+ var response = await httpClient.PostAsync($"http://localhost/webapi/ITestService/Method_TwoParameter_NoResult", new StringContent(requestBody, new MediaTypeHeaderValue("application/json")), cancellationToken: TestContext.Current.CancellationToken);
+ var content = await response.Content.ReadAsStringAsync(TestContext.Current.CancellationToken);
// Assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
@@ -151,8 +151,8 @@ public async Task Method_ManyParameter_NoResult()
""";
// Act
- var response = await httpClient.PostAsync($"http://localhost/webapi/ITestService/Method_ManyParameter_NoResult", new StringContent(requestBody, new MediaTypeHeaderValue("application/json")));
- var content = await response.Content.ReadAsStringAsync();
+ var response = await httpClient.PostAsync($"http://localhost/webapi/ITestService/Method_ManyParameter_NoResult", new StringContent(requestBody, new MediaTypeHeaderValue("application/json")), cancellationToken: TestContext.Current.CancellationToken);
+ var content = await response.Content.ReadAsStringAsync(TestContext.Current.CancellationToken);
// Assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
@@ -170,8 +170,8 @@ public async Task Method_TwoParameter_NoResult_Keyed()
""";
// Act
- var response = await httpClient.PostAsync($"http://localhost/webapi/ITestService/Method_TwoParameter_NoResult", new StringContent(requestBody, new MediaTypeHeaderValue("application/json")));
- var content = await response.Content.ReadAsStringAsync();
+ var response = await httpClient.PostAsync($"http://localhost/webapi/ITestService/Method_TwoParameter_NoResult", new StringContent(requestBody, new MediaTypeHeaderValue("application/json")), cancellationToken: TestContext.Current.CancellationToken);
+ var content = await response.Content.ReadAsStringAsync(TestContext.Current.CancellationToken);
// Assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
@@ -189,8 +189,8 @@ public async Task Method_ManyParameter_NoResult_Keyed()
""";
// Act
- var response = await httpClient.PostAsync($"http://localhost/webapi/ITestService/Method_ManyParameter_NoResult", new StringContent(requestBody, new MediaTypeHeaderValue("application/json")));
- var content = await response.Content.ReadAsStringAsync();
+ var response = await httpClient.PostAsync($"http://localhost/webapi/ITestService/Method_ManyParameter_NoResult", new StringContent(requestBody, new MediaTypeHeaderValue("application/json")), cancellationToken: TestContext.Current.CancellationToken);
+ var content = await response.Content.ReadAsStringAsync(TestContext.Current.CancellationToken);
// Assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
@@ -208,8 +208,8 @@ public async Task Throw()
""";
// Act
- var response = await httpClient.PostAsync($"http://localhost/webapi/ITestService/ThrowAsync", new StringContent(requestBody, new MediaTypeHeaderValue("application/json")));
- var content = await response.Content.ReadAsStringAsync();
+ var response = await httpClient.PostAsync($"http://localhost/webapi/ITestService/ThrowAsync", new StringContent(requestBody, new MediaTypeHeaderValue("application/json")), cancellationToken: TestContext.Current.CancellationToken);
+ var content = await response.Content.ReadAsStringAsync(TestContext.Current.CancellationToken);
// Assert
Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode);
@@ -227,8 +227,8 @@ public async Task ThrowWithReturnStatusCode()
""";
// Act
- var response = await httpClient.PostAsync($"http://localhost/webapi/ITestService/ThrowWithReturnStatusCodeAsync", new StringContent(requestBody, new MediaTypeHeaderValue("application/json")));
- var content = await response.Content.ReadAsStringAsync();
+ var response = await httpClient.PostAsync($"http://localhost/webapi/ITestService/ThrowWithReturnStatusCodeAsync", new StringContent(requestBody, new MediaTypeHeaderValue("application/json")), cancellationToken: TestContext.Current.CancellationToken);
+ var content = await response.Content.ReadAsStringAsync(TestContext.Current.CancellationToken);
// Assert
Assert.Equal(HttpStatusCode.ServiceUnavailable, response.StatusCode);
@@ -245,8 +245,8 @@ public async Task CallContextInfo()
var httpClient = factory.CreateDefaultClient();
// Act
- var response = await httpClient.PostAsync($"http://localhost/webapi/ITestService/CallContextInfo", new StringContent(string.Empty, new MediaTypeHeaderValue("application/json")));
- var content = await response.Content.ReadAsStringAsync();
+ var response = await httpClient.PostAsync($"http://localhost/webapi/ITestService/CallContextInfo", new StringContent(string.Empty, new MediaTypeHeaderValue("application/json")), cancellationToken: TestContext.Current.CancellationToken);
+ var content = await response.Content.ReadAsStringAsync(TestContext.Current.CancellationToken);
// Assert
var dict = JsonSerializer.Deserialize>(content) ?? throw new InvalidOperationException("Failed to deserialize a response.");
@@ -266,8 +266,8 @@ public async Task CallContext_WriteResponseHeader()
""";
// Act
- var response = await httpClient.PostAsync($"http://localhost/webapi/ITestService/CallContext_WriteResponseHeader", new StringContent(requestBody, new MediaTypeHeaderValue("application/json")));
- var content = await response.Content.ReadAsStringAsync();
+ var response = await httpClient.PostAsync($"http://localhost/webapi/ITestService/CallContext_WriteResponseHeader", new StringContent(requestBody, new MediaTypeHeaderValue("application/json")), cancellationToken: TestContext.Current.CancellationToken);
+ var content = await response.Content.ReadAsStringAsync(TestContext.Current.CancellationToken);
// Assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
diff --git a/tests/MagicOnion.Server.Redis.Tests/MagicOnion.Server.Redis.Tests.csproj b/tests/MagicOnion.Server.Redis.Tests/MagicOnion.Server.Redis.Tests.csproj
index 8687965d6..a81390a74 100644
--- a/tests/MagicOnion.Server.Redis.Tests/MagicOnion.Server.Redis.Tests.csproj
+++ b/tests/MagicOnion.Server.Redis.Tests/MagicOnion.Server.Redis.Tests.csproj
@@ -14,7 +14,7 @@
-
+
runtime; build; native; contentfiles; analyzers; buildtransitive
all
diff --git a/tests/MagicOnion.Server.Redis.Tests/RedisGroupFunctionalTest.cs b/tests/MagicOnion.Server.Redis.Tests/RedisGroupFunctionalTest.cs
index d77c93fd4..91ce6cd1a 100644
--- a/tests/MagicOnion.Server.Redis.Tests/RedisGroupFunctionalTest.cs
+++ b/tests/MagicOnion.Server.Redis.Tests/RedisGroupFunctionalTest.cs
@@ -54,19 +54,19 @@ public async Task Broadcast()
var httpClient1 = factory.CreateDefaultClient();
var channel1 = GrpcChannel.ForAddress("http://localhost", new GrpcChannelOptions() { HttpClient = httpClient1 });
var receiver1 = Substitute.For();
- var client1 = await StreamingHubClient.ConnectAsync(channel1, receiver1);
+ var client1 = await StreamingHubClient.ConnectAsync(channel1, receiver1, cancellationToken: TestContext.Current.CancellationToken);
await client1.JoinAsync("group-1");
// Client-2 on Server-2
var httpClient2 = factory2.CreateDefaultClient();
var channel2 = GrpcChannel.ForAddress("http://localhost", new GrpcChannelOptions() { HttpClient = httpClient2 });
var receiver2 = Substitute.For();
- var client2 = await StreamingHubClient.ConnectAsync(channel2, receiver2);
+ var client2 = await StreamingHubClient.ConnectAsync(channel2, receiver2, cancellationToken: TestContext.Current.CancellationToken);
await client2.JoinAsync("group-1");
// Act
// Cilent-1 --> Server-1 --> Redis --> Server-2 --> Client-2
await client1.CallAsync(12345);
- await Task.Delay(500); // Wait for broadcast queue to be consumed.
+ await Task.Delay(500, TestContext.Current.CancellationToken); // Wait for broadcast queue to be consumed.
// Assert
receiver1.Received().OnMessage(12345);
@@ -82,25 +82,25 @@ public async Task RemoveMemberFromInMemoryGroup_KeepSubscription()
var httpClient1 = factory.CreateDefaultClient();
var channel1 = GrpcChannel.ForAddress("http://localhost", new GrpcChannelOptions() { HttpClient = httpClient1 });
var receiver1 = Substitute.For();
- var client1 = await StreamingHubClient.ConnectAsync(channel1, receiver1);
+ var client1 = await StreamingHubClient.ConnectAsync(channel1, receiver1, cancellationToken: TestContext.Current.CancellationToken);
await client1.JoinAsync(groupName);
// Client-2 on Server-2
var httpClient2 = factory2.CreateDefaultClient();
var channel2 = GrpcChannel.ForAddress("http://localhost", new GrpcChannelOptions() { HttpClient = httpClient2 });
var receiver2 = Substitute.For();
- var client2 = await StreamingHubClient.ConnectAsync(channel2, receiver2);
+ var client2 = await StreamingHubClient.ConnectAsync(channel2, receiver2, cancellationToken: TestContext.Current.CancellationToken);
await client2.JoinAsync(groupName);
// Client-3 on Server-2 (same as Client-2)
var httpClient3 = factory2.CreateDefaultClient();
var channel3 = GrpcChannel.ForAddress("http://localhost", new GrpcChannelOptions() { HttpClient = httpClient3 });
var receiver3 = Substitute.For();
- var client3 = await StreamingHubClient.ConnectAsync(channel3, receiver3);
+ var client3 = await StreamingHubClient.ConnectAsync(channel3, receiver3, cancellationToken: TestContext.Current.CancellationToken);
await client3.JoinAsync(groupName);
// Act
await client2.LeaveAsync(); // Leave Client-2 from the group on Server-2.
await client1.CallAsync(123); // Client-1 --> Server-1 --> Redis --> Server-2 --> Client-3
- await Task.Delay(500); // Wait for broadcast queue to be consumed.
+ await Task.Delay(500, TestContext.Current.CancellationToken); // Wait for broadcast queue to be consumed.
// Assert
receiver3.Received().OnMessage(123);
diff --git a/tests/MagicOnion.Server.Redis.Tests/TemporaryRedisServerFixture.cs b/tests/MagicOnion.Server.Redis.Tests/TemporaryRedisServerFixture.cs
index 0bc2fd1e8..ffb5347e7 100644
--- a/tests/MagicOnion.Server.Redis.Tests/TemporaryRedisServerFixture.cs
+++ b/tests/MagicOnion.Server.Redis.Tests/TemporaryRedisServerFixture.cs
@@ -22,14 +22,14 @@ public string GetConnectionString()
return $"{container.Hostname}:{container.GetMappedPublicPort(redisPort)}";
}
- Task IAsyncLifetime.InitializeAsync()
+ ValueTask IAsyncLifetime.InitializeAsync()
{
- return container.StartAsync();
+ return new ValueTask(container.StartAsync());
}
- Task IAsyncLifetime.DisposeAsync()
+ ValueTask IAsyncDisposable.DisposeAsync()
{
- return container.DisposeAsync().AsTask();
+ return container.DisposeAsync();
}
static int GetAvailableListenerPort()
diff --git a/tests/MagicOnion.Server.Tests/ArgumentPatternTest.cs b/tests/MagicOnion.Server.Tests/ArgumentPatternTest.cs
index 3d2320cad..ba23168e7 100644
--- a/tests/MagicOnion.Server.Tests/ArgumentPatternTest.cs
+++ b/tests/MagicOnion.Server.Tests/ArgumentPatternTest.cs
@@ -3,7 +3,6 @@
using MessagePack;
using Grpc.Net.Client;
using MagicOnion.Internal;
-using Xunit.Abstractions;
using MagicOnion.Serialization;
namespace MagicOnion.Server.Tests;
diff --git a/tests/MagicOnion.Server.Tests/AuthorizeStreamingHubTest.cs b/tests/MagicOnion.Server.Tests/AuthorizeStreamingHubTest.cs
index 5e35a8d5b..62ce1fe55 100644
--- a/tests/MagicOnion.Server.Tests/AuthorizeStreamingHubTest.cs
+++ b/tests/MagicOnion.Server.Tests/AuthorizeStreamingHubTest.cs
@@ -21,7 +21,7 @@ public async Task Authorize_Connect()
{
var httpClient = factory.CreateDefaultClient();
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "Alice");
- var client = await StreamingHubClient.ConnectAsync(GrpcChannel.ForAddress("http://localhost", new GrpcChannelOptions() { HttpClient = httpClient }), this);
+ var client = await StreamingHubClient.ConnectAsync(GrpcChannel.ForAddress("http://localhost", new GrpcChannelOptions() { HttpClient = httpClient }), this, cancellationToken: TestContext.Current.CancellationToken);
var userName = await client.GetUserNameAsync();
userName.Should().Be("Alice");
}
@@ -33,7 +33,7 @@ public async Task Unauthenticated_Connect()
var ex = await Assert.ThrowsAsync(async () =>
{
- var client = await StreamingHubClient.ConnectAsync(GrpcChannel.ForAddress("http://localhost", new GrpcChannelOptions() { HttpClient = httpClient }), this);
+ var client = await StreamingHubClient.ConnectAsync(GrpcChannel.ForAddress("http://localhost", new GrpcChannelOptions() { HttpClient = httpClient }), this, cancellationToken: TestContext.Current.CancellationToken);
});
ex.StatusCode.Should().Be(StatusCode.Unauthenticated);
diff --git a/tests/MagicOnion.Server.Tests/Filter/FilterHelperTest.cs b/tests/MagicOnion.Server.Tests/Filter/FilterHelperTest.cs
index aab56acf8..74adb23fb 100644
--- a/tests/MagicOnion.Server.Tests/Filter/FilterHelperTest.cs
+++ b/tests/MagicOnion.Server.Tests/Filter/FilterHelperTest.cs
@@ -770,7 +770,7 @@ public async Task WrapMethodBodyWithFilter_Surround_Service_ThrowStackTrace()
callStack = Environment.StackTrace;
throw new InvalidOperationException();
});
- var ex = await Record.ExceptionAsync(async () => await body(default));
+ var ex = await Record.ExceptionAsync(() => body(default));
// Assert
ex.Should().NotBeNull();
@@ -851,7 +851,7 @@ public async Task WrapMethodBodyWithFilter_Surround_StreamingHub_ThrowStackTrace
callStack = Environment.StackTrace;
throw new InvalidOperationException();
});
- var ex = await Record.ExceptionAsync(async () => await body(default));
+ var ex = await Record.ExceptionAsync(() => body(default));
// Assert
ex.Should().NotBeNull();
diff --git a/tests/MagicOnion.Server.Tests/FilterConstructorInjectionTest.cs b/tests/MagicOnion.Server.Tests/FilterConstructorInjectionTest.cs
index 839c7aea4..f1947c86a 100644
--- a/tests/MagicOnion.Server.Tests/FilterConstructorInjectionTest.cs
+++ b/tests/MagicOnion.Server.Tests/FilterConstructorInjectionTest.cs
@@ -1,5 +1,4 @@
using Grpc.Core;
-using Xunit.Abstractions;
using Microsoft.Extensions.DependencyInjection;
using MagicOnion.Server.Filters;
diff --git a/tests/MagicOnion.Server.Tests/FilterTest.cs b/tests/MagicOnion.Server.Tests/FilterTest.cs
index f0df06621..de44b3d50 100644
--- a/tests/MagicOnion.Server.Tests/FilterTest.cs
+++ b/tests/MagicOnion.Server.Tests/FilterTest.cs
@@ -1,5 +1,4 @@
using Grpc.Core;
-using Xunit.Abstractions;
namespace MagicOnion.Server.Tests;
diff --git a/tests/MagicOnion.Server.Tests/HandCraftedMagicOnionMethodProviderTest.cs b/tests/MagicOnion.Server.Tests/HandCraftedMagicOnionMethodProviderTest.cs
index 6dab752bb..8c4fa3c20 100644
--- a/tests/MagicOnion.Server.Tests/HandCraftedMagicOnionMethodProviderTest.cs
+++ b/tests/MagicOnion.Server.Tests/HandCraftedMagicOnionMethodProviderTest.cs
@@ -69,7 +69,7 @@ public async Task StreamingHub()
var httpClient = factory.CreateDefaultClient();
var receiver = Substitute.For();
var client = await StreamingHubClient.ConnectAsync(
- GrpcChannel.ForAddress("http://localhost", new GrpcChannelOptions() { HttpClient = httpClient }), receiver);
+ GrpcChannel.ForAddress("http://localhost", new GrpcChannelOptions() { HttpClient = httpClient }), receiver, cancellationToken: TestContext.Current.CancellationToken);
// Act
await client.JoinAsync("Alice", "Room-A");
diff --git a/tests/MagicOnion.Server.Tests/InterfaceInheritanceTest.cs b/tests/MagicOnion.Server.Tests/InterfaceInheritanceTest.cs
index f2d6066c5..ec7346325 100644
--- a/tests/MagicOnion.Server.Tests/InterfaceInheritanceTest.cs
+++ b/tests/MagicOnion.Server.Tests/InterfaceInheritanceTest.cs
@@ -1,6 +1,5 @@
using Grpc.Net.Client;
using MagicOnion.Client;
-using Xunit.Abstractions;
namespace MagicOnion.Server.Tests;
diff --git a/tests/MagicOnion.Server.Tests/MagicOnion.Server.Tests.csproj b/tests/MagicOnion.Server.Tests/MagicOnion.Server.Tests.csproj
index 137c8592b..57ef2c474 100644
--- a/tests/MagicOnion.Server.Tests/MagicOnion.Server.Tests.csproj
+++ b/tests/MagicOnion.Server.Tests/MagicOnion.Server.Tests.csproj
@@ -17,7 +17,7 @@
-
+
diff --git a/tests/MagicOnion.Server.Tests/MagicOnionGrpcMethodTest.cs b/tests/MagicOnion.Server.Tests/MagicOnionGrpcMethodTest.cs
index ca26ff543..58fbd7956 100644
--- a/tests/MagicOnion.Server.Tests/MagicOnionGrpcMethodTest.cs
+++ b/tests/MagicOnion.Server.Tests/MagicOnionGrpcMethodTest.cs
@@ -202,7 +202,7 @@ public async Task DuplexStreaming_Invoker_RequestValueType_ResponseValueType()
var streamingContext = new DuplexStreamingContext((StreamingServiceContext)context);
await streamingContext.WriteAsync(12345);
- var request = await streamingContext.MoveNext();
+ var request = await streamingContext.MoveNext(TestContext.Current.CancellationToken);
requestCurrentFirst = streamingContext.Current;
});
var instance = new ServiceImpl();
@@ -211,7 +211,7 @@ public async Task DuplexStreaming_Invoker_RequestValueType_ResponseValueType()
var serviceProvider = Substitute.For();
var metrics = new MagicOnionMetrics(new TestMeterFactory());
var requestStream = Substitute.For>();
- requestStream.MoveNext(default).ReturnsForAnyArgs(Task.FromResult(true));
+ requestStream.MoveNext(TestContext.Current.CancellationToken).ReturnsForAnyArgs(Task.FromResult(true));
requestStream.Current.Returns(54321);
var responseStream = Substitute.For>();
@@ -225,7 +225,9 @@ public async Task DuplexStreaming_Invoker_RequestValueType_ResponseValueType()
Assert.True(called);
Assert.Equal(instance, invokerArgInstance);
Assert.Equal(54321, requestCurrentFirst);
+#pragma warning disable xUnit1051 // Calls to methods which accept CancellationToken should use TestContext.Current.CancellationToken
_ = responseStream.Received(1).WriteAsync(12345);
+#pragma warning restore xUnit1051 // Calls to methods which accept CancellationToken should use TestContext.Current.CancellationToken
}
diff --git a/tests/MagicOnion.Server.Tests/MagicOnionMetricsTest.cs b/tests/MagicOnion.Server.Tests/MagicOnionMetricsTest.cs
index 9dafcef0f..14060e1b2 100644
--- a/tests/MagicOnion.Server.Tests/MagicOnionMetricsTest.cs
+++ b/tests/MagicOnion.Server.Tests/MagicOnionMetricsTest.cs
@@ -38,7 +38,7 @@ public async Task StreamingHubConnectionCounter()
{
using var channel = GrpcChannel.ForAddress("http://localhost", new GrpcChannelOptions() { HttpClient = factory.CreateDefaultClient() });
- var client = await StreamingHubClient.ConnectAsync(channel, receiver, serializerProvider: MessagePackMagicOnionSerializerProvider.Default);
+ var client = await StreamingHubClient.ConnectAsync(channel, receiver, serializerProvider: MessagePackMagicOnionSerializerProvider.Default, cancellationToken: TestContext.Current.CancellationToken);
values2 = collector.GetMeasurementSnapshot();
await client.DisposeAsync();
}
@@ -65,10 +65,10 @@ public async Task StreamingHubMethodDuration()
var receiver = new Receiver();
using var collector = new MetricCollector(meterFactory, MagicOnionMetrics.MeterName, "magiconion.server.streaminghub.method_duration");
using var channel = GrpcChannel.ForAddress("http://localhost", new GrpcChannelOptions() { HttpClient = factory.CreateDefaultClient() });
- var client = await StreamingHubClient.ConnectAsync(channel, receiver, serializerProvider: MessagePackMagicOnionSerializerProvider.Default);
+ var client = await StreamingHubClient.ConnectAsync(channel, receiver, serializerProvider: MessagePackMagicOnionSerializerProvider.Default, cancellationToken: TestContext.Current.CancellationToken);
await client.SleepAsync();
- await Task.Delay(100);
+ await Task.Delay(100, TestContext.Current.CancellationToken);
var values = collector.GetMeasurementSnapshot();
@@ -85,10 +85,10 @@ public async Task StreamingHubMethodCompleted()
var receiver = new Receiver();
using var collector = new MetricCollector(meterFactory, MagicOnionMetrics.MeterName, "magiconion.server.streaminghub.method_completed");
using var channel = GrpcChannel.ForAddress("http://localhost", new GrpcChannelOptions() { HttpClient = factory.CreateDefaultClient() });
- var client = await StreamingHubClient.ConnectAsync(channel, receiver, serializerProvider: MessagePackMagicOnionSerializerProvider.Default);
+ var client = await StreamingHubClient.ConnectAsync(channel, receiver, serializerProvider: MessagePackMagicOnionSerializerProvider.Default, cancellationToken: TestContext.Current.CancellationToken);
await client.MethodAsync();
- await Task.Delay(100);
+ await Task.Delay(100, TestContext.Current.CancellationToken);
var values = collector.GetMeasurementSnapshot();
@@ -106,7 +106,7 @@ public async Task StreamingHubMethodCompleted_Failure()
var receiver = new Receiver();
using var collector = new MetricCollector(meterFactory, MagicOnionMetrics.MeterName, "magiconion.server.streaminghub.method_completed");
using var channel = GrpcChannel.ForAddress("http://localhost", new GrpcChannelOptions() { HttpClient = factory.CreateDefaultClient() });
- var client = await StreamingHubClient.ConnectAsync(channel, receiver, serializerProvider: MessagePackMagicOnionSerializerProvider.Default);
+ var client = await StreamingHubClient.ConnectAsync(channel, receiver, serializerProvider: MessagePackMagicOnionSerializerProvider.Default, cancellationToken: TestContext.Current.CancellationToken);
try
{
@@ -114,7 +114,7 @@ public async Task StreamingHubMethodCompleted_Failure()
}
catch
{ }
- await Task.Delay(100);
+ await Task.Delay(100, TestContext.Current.CancellationToken);
var values = collector.GetMeasurementSnapshot();
@@ -131,7 +131,7 @@ public async Task StreamingHubException()
var receiver = new Receiver();
using var collector = new MetricCollector(meterFactory, MagicOnionMetrics.MeterName, "magiconion.server.streaminghub.exceptions");
using var channel = GrpcChannel.ForAddress("http://localhost", new GrpcChannelOptions() { HttpClient = factory.CreateDefaultClient() });
- var client = await StreamingHubClient.ConnectAsync(channel, receiver, serializerProvider: MessagePackMagicOnionSerializerProvider.Default);
+ var client = await StreamingHubClient.ConnectAsync(channel, receiver, serializerProvider: MessagePackMagicOnionSerializerProvider.Default, cancellationToken: TestContext.Current.CancellationToken);
try
{
@@ -139,7 +139,7 @@ public async Task StreamingHubException()
}
catch
{ }
- await Task.Delay(100);
+ await Task.Delay(100, TestContext.Current.CancellationToken);
var values = collector.GetMeasurementSnapshot();
diff --git a/tests/MagicOnion.Server.Tests/ReturnStatusTest.cs b/tests/MagicOnion.Server.Tests/ReturnStatusTest.cs
index 18a98f012..ae40e8fa2 100644
--- a/tests/MagicOnion.Server.Tests/ReturnStatusTest.cs
+++ b/tests/MagicOnion.Server.Tests/ReturnStatusTest.cs
@@ -1,5 +1,4 @@
using Grpc.Core;
-using Xunit.Abstractions;
namespace MagicOnion.Server.Tests;
diff --git a/tests/MagicOnion.Server.Tests/StreamingHubBroadcastTest/GroupTest.cs b/tests/MagicOnion.Server.Tests/StreamingHubBroadcastTest/GroupTest.cs
index 16fa09711..7981413ce 100644
--- a/tests/MagicOnion.Server.Tests/StreamingHubBroadcastTest/GroupTest.cs
+++ b/tests/MagicOnion.Server.Tests/StreamingHubBroadcastTest/GroupTest.cs
@@ -29,7 +29,7 @@ public async Task BroadcastToSelf()
await hub.CallBroadcastToSelfAsync();
- await Task.Delay(10); // NOTE: The receivers may not receive broadcast yet at this point.
+ await Task.Delay(10, TestContext.Current.CancellationToken); // NOTE: The receivers may not receive broadcast yet at this point.
// Target: Self
Assert.True(mockReceiver.HasCalled);
@@ -53,7 +53,7 @@ public async Task BroadcastToSelf_2()
await hub.CallBroadcastToSelfAsync();
- await Task.Delay(10); // NOTE: The receivers may not receive broadcast yet at this point.
+ await Task.Delay(10, TestContext.Current.CancellationToken); // NOTE: The receivers may not receive broadcast yet at this point.
// Target: Self
Assert.True(mockReceiver.HasCalled);
@@ -76,7 +76,7 @@ public async Task BroadcastToExceptSelf()
await hub.CallBroadcastExceptSelfAsync();
- await Task.Delay(10); // NOTE: The receivers may not receive broadcast yet at this point.
+ await Task.Delay(10, TestContext.Current.CancellationToken); // NOTE: The receivers may not receive broadcast yet at this point.
// Target: Other
Assert.False(mockReceiver.HasCalled);
@@ -100,7 +100,7 @@ public async Task BroadcastToExceptSelf_2()
await hub.CallBroadcastExceptSelfAsync();
- await Task.Delay(TimeSpan.FromMilliseconds(100)); // NOTE: The receivers may not receive broadcast yet at this point.
+ await Task.Delay(TimeSpan.FromMilliseconds(100), TestContext.Current.CancellationToken); // NOTE: The receivers may not receive broadcast yet at this point.
// Target: Other
Assert.False(mockReceiver.HasCalled);
@@ -123,7 +123,7 @@ public async Task BroadcastToExcept_One_1()
await hub.CallBroadcastExceptAsync(Guid.NewGuid());
- await Task.Delay(10); // NOTE: The receivers may not receive broadcast yet at this point.
+ await Task.Delay(10, TestContext.Current.CancellationToken); // NOTE: The receivers may not receive broadcast yet at this point.
// Target: Self, Other
Assert.True(mockReceiver.HasCalled);
@@ -146,7 +146,7 @@ public async Task BroadcastToExcept_One_2()
await hub.CallBroadcastExceptAsync(connectionIdOther);
- await Task.Delay(10); // NOTE: The receivers may not receive broadcast yet at this point.
+ await Task.Delay(10, TestContext.Current.CancellationToken); // NOTE: The receivers may not receive broadcast yet at this point.
// Target: Self
Assert.True(mockReceiver.HasCalled);
@@ -169,7 +169,7 @@ public async Task BroadcastToExcept_One_3()
await hub.CallBroadcastExceptAsync(connectionId);
- await Task.Delay(10); // NOTE: The receivers may not receive broadcast yet at this point.
+ await Task.Delay(10, TestContext.Current.CancellationToken); // NOTE: The receivers may not receive broadcast yet at this point.
// Target: Other
Assert.False(mockReceiver.HasCalled);
@@ -192,7 +192,7 @@ public async Task BroadcastToExcept_Many_1()
await hub.CallBroadcastExceptManyAsync(new[] { Guid.NewGuid(), Guid.NewGuid() });
- await Task.Delay(10); // NOTE: The receivers may not receive broadcast yet at this point.
+ await Task.Delay(10, TestContext.Current.CancellationToken); // NOTE: The receivers may not receive broadcast yet at this point.
// Target: Self, Other
Assert.True(mockReceiver.HasCalled);
@@ -215,7 +215,7 @@ public async Task BroadcastToExcept_Many_2()
await hub.CallBroadcastExceptManyAsync(new[] { Guid.NewGuid(), connectionIdOther, Guid.NewGuid() });
- await Task.Delay(10); // NOTE: The receivers may not receive broadcast yet at this point.
+ await Task.Delay(10, TestContext.Current.CancellationToken); // NOTE: The receivers may not receive broadcast yet at this point.
// Target: Self
Assert.True(mockReceiver.HasCalled);
@@ -238,7 +238,7 @@ public async Task BroadcastToExcept_Many_3()
await hub.CallBroadcastExceptManyAsync(new[] { Guid.NewGuid(), connectionIdOther, Guid.NewGuid(), connectionId, Guid.NewGuid() });
- await Task.Delay(10); // NOTE: The receivers may not receive broadcast yet at this point.
+ await Task.Delay(10, TestContext.Current.CancellationToken); // NOTE: The receivers may not receive broadcast yet at this point.
// Target: None
Assert.False(mockReceiver.HasCalled);
@@ -262,7 +262,7 @@ public async Task BroadcastTo_One_1()
await hub.CallBroadcastToAsync(Guid.NewGuid());
- await Task.Delay(10); // NOTE: The receivers may not receive broadcast yet at this point.
+ await Task.Delay(10, TestContext.Current.CancellationToken); // NOTE: The receivers may not receive broadcast yet at this point.
// Target: None
Assert.False(mockReceiver.HasCalled);
@@ -285,7 +285,7 @@ public async Task BroadcastTo_One_2()
await hub.CallBroadcastToAsync(connectionId);
- await Task.Delay(100); // NOTE: The receivers may not receive broadcast yet at this point.
+ await Task.Delay(100, TestContext.Current.CancellationToken); // NOTE: The receivers may not receive broadcast yet at this point.
// Target: Other
Assert.True(mockReceiver.HasCalled);
@@ -308,7 +308,7 @@ public async Task BroadcastTo_One_3()
await hub.CallBroadcastToAsync(connectionIdOther);
- await Task.Delay(10); // NOTE: The receivers may not receive broadcast yet at this point.
+ await Task.Delay(10, TestContext.Current.CancellationToken); // NOTE: The receivers may not receive broadcast yet at this point.
// Target: Other
Assert.False(mockReceiver.HasCalled);
@@ -331,7 +331,7 @@ public async Task BroadcastTo_Many_1()
await hub.CallBroadcastToManyAsync(new[] { Guid.NewGuid(), Guid.NewGuid() });
- await Task.Delay(10); // NOTE: The receivers may not receive broadcast yet at this point.
+ await Task.Delay(10, TestContext.Current.CancellationToken); // NOTE: The receivers may not receive broadcast yet at this point.
// Target: None
Assert.False(mockReceiver.HasCalled);
@@ -354,7 +354,7 @@ public async Task BroadcastTo_Many_2()
await hub.CallBroadcastToManyAsync(new[] { Guid.NewGuid(), connectionId, Guid.NewGuid() });
- await Task.Delay(10); // NOTE: The receivers may not receive broadcast yet at this point.
+ await Task.Delay(10, TestContext.Current.CancellationToken); // NOTE: The receivers may not receive broadcast yet at this point.
// Target: Self
Assert.True(mockReceiver.HasCalled);
@@ -377,7 +377,7 @@ public async Task BroadcastTo_Many_3()
await hub.CallBroadcastToManyAsync(new[] { Guid.NewGuid(), connectionId, Guid.NewGuid(), connectionIdOther });
- await Task.Delay(10); // NOTE: The receivers may not receive broadcast yet at this point.
+ await Task.Delay(10, TestContext.Current.CancellationToken); // NOTE: The receivers may not receive broadcast yet at this point.
// Target: Self, Other
Assert.True(mockReceiver.HasCalled);
diff --git a/tests/MagicOnion.Server.Tests/StreamingHubHandlerTest.cs b/tests/MagicOnion.Server.Tests/StreamingHubHandlerTest.cs
index 65bcec960..d526eaba2 100644
--- a/tests/MagicOnion.Server.Tests/StreamingHubHandlerTest.cs
+++ b/tests/MagicOnion.Server.Tests/StreamingHubHandlerTest.cs
@@ -31,7 +31,7 @@ public async Task Parameterless_Returns_Task()
// Act
var handler = new StreamingHubHandler(hubMethod, new StreamingHubHandlerOptions(new MagicOnionOptions()), serviceProvider);
var ctx = new StreamingHubContext();
- ctx.Initialize(handler, fakeStreamingHubContext, hubInstance, MessagePackSerializer.Serialize(Nil.Default), DateTime.Now, 0);
+ ctx.Initialize(handler, fakeStreamingHubContext, hubInstance, MessagePackSerializer.Serialize(Nil.Default, cancellationToken: TestContext.Current.CancellationToken), DateTime.Now, 0);
await handler.MethodBody.Invoke(ctx);
// Assert
@@ -69,7 +69,7 @@ public async Task Parameterless_Returns_TaskOfInt32()
// Act
var handler = new StreamingHubHandler(hubMethod, new StreamingHubHandlerOptions(new MagicOnionOptions()), serviceProvider);
var ctx = new StreamingHubContext();
- ctx.Initialize(handler, fakeStreamingHubContext, hubInstance, MessagePackSerializer.Serialize(Nil.Default), DateTime.Now, 0);
+ ctx.Initialize(handler, fakeStreamingHubContext, hubInstance, MessagePackSerializer.Serialize(Nil.Default, cancellationToken: TestContext.Current.CancellationToken), DateTime.Now, 0);
await handler.MethodBody.Invoke(ctx);
// Assert
@@ -106,7 +106,7 @@ public async Task Parameterless_Returns_ValueTask()
// Act
var handler = new StreamingHubHandler(hubMethod, new StreamingHubHandlerOptions(new MagicOnionOptions()), serviceProvider);
var ctx = new StreamingHubContext();
- ctx.Initialize(handler, fakeStreamingHubContext, hubInstance, MessagePackSerializer.Serialize(Nil.Default), DateTime.Now, 0);
+ ctx.Initialize(handler, fakeStreamingHubContext, hubInstance, MessagePackSerializer.Serialize(Nil.Default, cancellationToken: TestContext.Current.CancellationToken), DateTime.Now, 0);
await handler.MethodBody.Invoke(ctx);
// Assert
@@ -144,7 +144,7 @@ public async Task Parameterless_Returns_ValueTaskOfInt32()
// Act
var handler = new StreamingHubHandler(hubMethod, new StreamingHubHandlerOptions(new MagicOnionOptions()), serviceProvider);
var ctx = new StreamingHubContext();
- ctx.Initialize(handler, fakeStreamingHubContext, hubInstance, MessagePackSerializer.Serialize(Nil.Default), DateTime.Now, 0);
+ ctx.Initialize(handler, fakeStreamingHubContext, hubInstance, MessagePackSerializer.Serialize(Nil.Default, cancellationToken: TestContext.Current.CancellationToken), DateTime.Now, 0);
await handler.MethodBody.Invoke(ctx);
// Assert
@@ -182,7 +182,7 @@ public async Task Parameter_Single_Returns_Task()
// Act
var handler = new StreamingHubHandler(hubMethod, new StreamingHubHandlerOptions(new MagicOnionOptions()), serviceProvider);
var ctx = new StreamingHubContext();
- ctx.Initialize(handler, fakeStreamingHubContext, hubInstance, MessagePackSerializer.Serialize(12345), DateTime.Now, 0);
+ ctx.Initialize(handler, fakeStreamingHubContext, hubInstance, MessagePackSerializer.Serialize(12345, cancellationToken: TestContext.Current.CancellationToken), DateTime.Now, 0);
await handler.MethodBody.Invoke(ctx);
// Assert
@@ -220,7 +220,7 @@ public async Task Parameter_Multiple_Returns_Task()
// Act
var handler = new StreamingHubHandler(hubMethod, new StreamingHubHandlerOptions(new MagicOnionOptions()), serviceProvider);
var ctx = new StreamingHubContext();
- ctx.Initialize(handler, fakeStreamingHubContext, hubInstance, MessagePackSerializer.Serialize(new DynamicArgumentTuple(12345, "テスト", true)), DateTime.Now, 0);
+ ctx.Initialize(handler, fakeStreamingHubContext, hubInstance, MessagePackSerializer.Serialize(new DynamicArgumentTuple(12345, "テスト", true), cancellationToken: TestContext.Current.CancellationToken), DateTime.Now, 0);
await handler.MethodBody.Invoke(ctx);
// Assert
@@ -257,7 +257,7 @@ public async Task Parameter_Multiple_Returns_TaskOfInt32()
// Act
var handler = new StreamingHubHandler(hubMethod, new StreamingHubHandlerOptions(new MagicOnionOptions()), serviceProvider);
var ctx = new StreamingHubContext();
- ctx.Initialize(handler, fakeStreamingHubContext, hubInstance, MessagePackSerializer.Serialize(new DynamicArgumentTuple(12345, "テスト", true)), DateTime.Now, 0);
+ ctx.Initialize(handler, fakeStreamingHubContext, hubInstance, MessagePackSerializer.Serialize(new DynamicArgumentTuple(12345, "テスト", true), cancellationToken: TestContext.Current.CancellationToken), DateTime.Now, 0);
await handler.MethodBody.Invoke(ctx);
// Assert
@@ -296,7 +296,7 @@ public async Task CallRepeated_Parameter_Multiple_Returns_TaskOfInt32()
for (var i = 0; i < 3; i++)
{
var ctx = new StreamingHubContext();
- ctx.Initialize(handler, fakeStreamingHubContext, hubInstance, MessagePackSerializer.Serialize(new DynamicArgumentTuple(i, $"テスト{i}", i % 2 == 0)), DateTime.Now, i * 1000);
+ ctx.Initialize(handler, fakeStreamingHubContext, hubInstance, MessagePackSerializer.Serialize(new DynamicArgumentTuple(i, $"テスト{i}", i % 2 == 0), cancellationToken: TestContext.Current.CancellationToken), DateTime.Now, i * 1000);
await handler.MethodBody.Invoke(ctx);
}
@@ -339,7 +339,7 @@ public async Task Parameterless_Void()
// Act
var handler = new StreamingHubHandler(hubMethod, new StreamingHubHandlerOptions(new MagicOnionOptions()), serviceProvider);
var ctx = new StreamingHubContext();
- ctx.Initialize(handler, fakeStreamingHubContext, hubInstance, MessagePackSerializer.Serialize(Nil.Default), DateTime.Now, 0);
+ ctx.Initialize(handler, fakeStreamingHubContext, hubInstance, MessagePackSerializer.Serialize(Nil.Default, cancellationToken: TestContext.Current.CancellationToken), DateTime.Now, 0);
await handler.MethodBody.Invoke(ctx);
// Assert
@@ -377,7 +377,7 @@ public async Task Parameter_Single_Void()
// Act
var handler = new StreamingHubHandler(hubMethod, new StreamingHubHandlerOptions(new MagicOnionOptions()), serviceProvider);
var ctx = new StreamingHubContext();
- ctx.Initialize(handler, fakeStreamingHubContext, hubInstance, MessagePackSerializer.Serialize(12345), DateTime.Now, 0);
+ ctx.Initialize(handler, fakeStreamingHubContext, hubInstance, MessagePackSerializer.Serialize(12345, cancellationToken: TestContext.Current.CancellationToken), DateTime.Now, 0);
await handler.MethodBody.Invoke(ctx);
// Assert
@@ -415,7 +415,7 @@ public async Task Parameter_Multiple_Void()
// Act
var handler = new StreamingHubHandler(hubMethod, new StreamingHubHandlerOptions(new MagicOnionOptions()), serviceProvider);
var ctx = new StreamingHubContext();
- ctx.Initialize(handler, fakeStreamingHubContext, hubInstance, MessagePackSerializer.Serialize(new DynamicArgumentTuple(12345, "テスト", true)), DateTime.Now, 0);
+ ctx.Initialize(handler, fakeStreamingHubContext, hubInstance, MessagePackSerializer.Serialize(new DynamicArgumentTuple(12345, "テスト", true), cancellationToken: TestContext.Current.CancellationToken), DateTime.Now, 0);
await handler.MethodBody.Invoke(ctx);
// Assert
@@ -453,7 +453,7 @@ public async Task Parameter_Multiple_Void_Without_MessageId()
// Act
var handler = new StreamingHubHandler(hubMethod, new StreamingHubHandlerOptions(new MagicOnionOptions()), serviceProvider);
var ctx = new StreamingHubContext();
- ctx.Initialize(handler, fakeStreamingHubContext, hubInstance, MessagePackSerializer.Serialize(new DynamicArgumentTuple(12345, "テスト", true)), DateTime.Now, -1 /* The client requires no response */);
+ ctx.Initialize(handler, fakeStreamingHubContext, hubInstance, MessagePackSerializer.Serialize(new DynamicArgumentTuple(12345, "テスト", true), cancellationToken: TestContext.Current.CancellationToken), DateTime.Now, -1 /* The client requires no response */);
await handler.MethodBody.Invoke(ctx);
// Assert
diff --git a/tests/MagicOnion.Server.Tests/StreamingHubHeartbeat/StreamingHubClientHeartbeatResponseTest.cs b/tests/MagicOnion.Server.Tests/StreamingHubHeartbeat/StreamingHubClientHeartbeatResponseTest.cs
index 40d9115cb..2deee58f2 100644
--- a/tests/MagicOnion.Server.Tests/StreamingHubHeartbeat/StreamingHubClientHeartbeatResponseTest.cs
+++ b/tests/MagicOnion.Server.Tests/StreamingHubHeartbeat/StreamingHubClientHeartbeatResponseTest.cs
@@ -37,9 +37,9 @@ public async Task Interval()
// Act
var client = await Fixture.CreateStreamingHubClientAsync(receiver, options);
Fixture.FakeTimeProvider.Advance(TimeSpan.FromMilliseconds(100)); // 100ms
- await Task.Delay(50); // Client -> Server -> Client
+ await Task.Delay(50, TestContext.Current.CancellationToken); // Client -> Server -> Client
Fixture.FakeTimeProvider.Advance(TimeSpan.FromMilliseconds(100)); // 200ms
- await Task.Delay(50); // Client -> Server -> Client
+ await Task.Delay(50, TestContext.Current.CancellationToken); // Client -> Server -> Client
Fixture.FakeTimeProvider.Advance(TimeSpan.FromMilliseconds(50)); // 250ms
await client.DisposeAsync();
diff --git a/tests/MagicOnion.Server.Tests/StreamingHubHeartbeat/StreamingHubHeartbeatManagerTest.cs b/tests/MagicOnion.Server.Tests/StreamingHubHeartbeat/StreamingHubHeartbeatManagerTest.cs
index 10a96fe3f..21125d0e2 100644
--- a/tests/MagicOnion.Server.Tests/StreamingHubHeartbeat/StreamingHubHeartbeatManagerTest.cs
+++ b/tests/MagicOnion.Server.Tests/StreamingHubHeartbeat/StreamingHubHeartbeatManagerTest.cs
@@ -59,12 +59,12 @@ public async Task Latency()
// Act
using var handle = manager.Register(context);
timeProvider.Advance(TimeSpan.FromMilliseconds(350));
- await Task.Delay(16);
+ await Task.Delay(16, TestContext.Current.CancellationToken);
// Simulate to send heartbeat responses from clients.
timeProvider.Advance(TimeSpan.FromMilliseconds(50));
handle.Ack(0);
- await Task.Delay(16);
+ await Task.Delay(16, TestContext.Current.CancellationToken);
// Assert
Assert.Equal(TimeSpan.FromMilliseconds(50), handle.Latency);
@@ -100,7 +100,7 @@ public async Task Latency_Before_Ack()
// Act
using var handle = manager.Register(context);
timeProvider.Advance(TimeSpan.FromMilliseconds(350));
- await Task.Delay(16);
+ await Task.Delay(16, TestContext.Current.CancellationToken);
// Assert
Assert.Equal(TimeSpan.Zero, handle.Latency);
@@ -125,11 +125,11 @@ public async Task Interval_Disable_Timeout()
using var handle2 = manager.Register(context2);
using var handle3 = manager.Register(context3);
timeProvider.Advance(TimeSpan.FromMilliseconds(100));
- await Task.Delay(16);
+ await Task.Delay(16, TestContext.Current.CancellationToken);
timeProvider.Advance(TimeSpan.FromMilliseconds(100));
- await Task.Delay(16);
+ await Task.Delay(16, TestContext.Current.CancellationToken);
timeProvider.Advance(TimeSpan.FromMilliseconds(100));
- await Task.Delay(16);
+ await Task.Delay(16, TestContext.Current.CancellationToken);
// Assert
Assert.Equal(3, context1.Responses.Count);
@@ -163,7 +163,7 @@ public async Task Interval_Keep()
using var handle2 = manager.Register(context2);
using var handle3 = manager.Register(context3);
timeProvider.Advance(TimeSpan.FromMilliseconds(350));
- await Task.Delay(16);
+ await Task.Delay(16, TestContext.Current.CancellationToken);
var isCanceled1 = handle1.TimeoutToken.IsCancellationRequested;
var isCanceled2 = handle2.TimeoutToken.IsCancellationRequested;
var isCanceled3 = handle3.TimeoutToken.IsCancellationRequested;
@@ -172,7 +172,7 @@ public async Task Interval_Keep()
handle2.Ack(0);
handle3.Ack(0);
timeProvider.Advance(TimeSpan.FromMilliseconds(250));
- await Task.Delay(16);
+ await Task.Delay(16, TestContext.Current.CancellationToken);
// Assert
Assert.False(isCanceled1);
@@ -200,12 +200,12 @@ public async Task Interval_With_Timeout()
using var handle2 = manager.Register(context2);
using var handle3 = manager.Register(context3);
timeProvider.Advance(TimeSpan.FromMilliseconds(350));
- await Task.Delay(16);
+ await Task.Delay(16, TestContext.Current.CancellationToken);
var isCanceled1 = handle1.TimeoutToken.IsCancellationRequested;
var isCanceled2 = handle2.TimeoutToken.IsCancellationRequested;
var isCanceled3 = handle3.TimeoutToken.IsCancellationRequested;
timeProvider.Advance(TimeSpan.FromMilliseconds(250)); // No responses from clients and timeouts are reached.
- await Task.Delay(16);
+ await Task.Delay(16, TestContext.Current.CancellationToken);
// Assert
Assert.False(isCanceled1);
@@ -235,20 +235,20 @@ public async Task Interval_Stop_After_HandleDisposed()
var handle2 = manager.Register(context2);
var handle3 = manager.Register(context3);
timeProvider.Advance(TimeSpan.FromMilliseconds(100));
- await Task.Delay(16);
+ await Task.Delay(16, TestContext.Current.CancellationToken);
timeProvider.Advance(TimeSpan.FromMilliseconds(100));
- await Task.Delay(16);
+ await Task.Delay(16, TestContext.Current.CancellationToken);
timeProvider.Advance(TimeSpan.FromMilliseconds(100));
- await Task.Delay(16);
+ await Task.Delay(16, TestContext.Current.CancellationToken);
handle1.Dispose();
handle2.Dispose();
handle3.Dispose();
timeProvider.Advance(TimeSpan.FromMilliseconds(100));
- await Task.Delay(16);
+ await Task.Delay(16, TestContext.Current.CancellationToken);
timeProvider.Advance(TimeSpan.FromMilliseconds(100));
- await Task.Delay(16);
+ await Task.Delay(16, TestContext.Current.CancellationToken);
timeProvider.Advance(TimeSpan.FromMilliseconds(100));
- await Task.Delay(16);
+ await Task.Delay(16, TestContext.Current.CancellationToken);
// Assert
Assert.Equal(3, context1.Responses.Count);
@@ -284,11 +284,11 @@ public async Task CustomMetadataProvider()
using var handle2 = manager.Register(context2);
using var handle3 = manager.Register(context3);
timeProvider.Advance(TimeSpan.FromMilliseconds(100));
- await Task.Delay(16);
+ await Task.Delay(16, TestContext.Current.CancellationToken);
timeProvider.Advance(TimeSpan.FromMilliseconds(100));
- await Task.Delay(16);
+ await Task.Delay(16, TestContext.Current.CancellationToken);
timeProvider.Advance(TimeSpan.FromMilliseconds(100));
- await Task.Delay(16);
+ await Task.Delay(16, TestContext.Current.CancellationToken);
// Assert
Assert.Equal(3, context1.Responses.Count);
@@ -318,21 +318,21 @@ public async Task Timeout_Longer_Than_Interval_Keep()
// Act & Assert
using var handle = manager.Register(context);
timeProvider.Advance(TimeSpan.FromSeconds(1));
- await Task.Delay(16);
+ await Task.Delay(16, TestContext.Current.CancellationToken);
Assert.False(handle.TimeoutToken.IsCancellationRequested);
Assert.Single(context.Responses);
timeProvider.Advance(TimeSpan.FromSeconds(1));
- await Task.Delay(16);
+ await Task.Delay(16, TestContext.Current.CancellationToken);
Assert.False(handle.TimeoutToken.IsCancellationRequested);
Assert.Equal(2, context.Responses.Count);
timeProvider.Advance(TimeSpan.FromSeconds(1));
- await Task.Delay(16);
+ await Task.Delay(16, TestContext.Current.CancellationToken);
Assert.False(handle.TimeoutToken.IsCancellationRequested);
timeProvider.Advance(TimeSpan.FromMilliseconds(900));
- await Task.Delay(16);
+ await Task.Delay(16, TestContext.Current.CancellationToken);
Assert.False(handle.TimeoutToken.IsCancellationRequested);
handle.Ack(0);
@@ -340,7 +340,7 @@ public async Task Timeout_Longer_Than_Interval_Keep()
handle.Ack(2);
timeProvider.Advance(TimeSpan.FromMilliseconds(100));
- await Task.Delay(16);
+ await Task.Delay(16, TestContext.Current.CancellationToken);
Assert.False(handle.TimeoutToken.IsCancellationRequested);
Assert.Equal(4, context.Responses.Count);
}
@@ -358,21 +358,21 @@ public async Task Timeout_Longer_Than_Interval_Lost()
// Act & Assert
using var handle = manager.Register(context);
timeProvider.Advance(TimeSpan.FromSeconds(1));
- await Task.Delay(16);
+ await Task.Delay(16, TestContext.Current.CancellationToken);
Assert.False(handle.TimeoutToken.IsCancellationRequested);
Assert.Single(context.Responses);
timeProvider.Advance(TimeSpan.FromSeconds(1)); // 1s has elapsed since the first message.
- await Task.Delay(16);
+ await Task.Delay(16, TestContext.Current.CancellationToken);
Assert.False(handle.TimeoutToken.IsCancellationRequested);
Assert.Equal(2, context.Responses.Count);
timeProvider.Advance(TimeSpan.FromSeconds(1)); // 2s has elapsed since the first message.
- await Task.Delay(16);
+ await Task.Delay(16, TestContext.Current.CancellationToken);
Assert.False(handle.TimeoutToken.IsCancellationRequested);
timeProvider.Advance(TimeSpan.FromMilliseconds(900)); // 2.9s has elapsed since the first message.
- await Task.Delay(16);
+ await Task.Delay(16, TestContext.Current.CancellationToken);
Assert.False(handle.TimeoutToken.IsCancellationRequested);
// Only returns a response to the first message.
@@ -381,7 +381,7 @@ public async Task Timeout_Longer_Than_Interval_Lost()
//handle.Ack(2);
timeProvider.Advance(TimeSpan.FromMilliseconds(100)); // 3s has elapsed since the first message.
- await Task.Delay(16);
+ await Task.Delay(16, TestContext.Current.CancellationToken);
Assert.True(handle.TimeoutToken.IsCancellationRequested); // The client should be disconnected.
Assert.Equal(4, context.Responses.Count);
}
@@ -400,12 +400,12 @@ public async Task Sequence()
// Act
using var handle1 = manager.Register(context1);
timeProvider.Advance(TimeSpan.FromMilliseconds(350));
- await Task.Delay(16);
+ await Task.Delay(16, TestContext.Current.CancellationToken);
// Simulate to send heartbeat responses from clients.
handle1.Ack(0);
timeProvider.Advance(TimeSpan.FromMilliseconds(350));
- await Task.Delay(16);
+ await Task.Delay(16, TestContext.Current.CancellationToken);
handle1.Ack(1);
// Assert
@@ -444,12 +444,12 @@ public async Task AckCallback()
using var handle = manager.Register(context);
handle.SetAckCallback(x => ackCalled = x);
timeProvider.Advance(TimeSpan.FromMilliseconds(350)); // SentAt = 00:00.0350
- await Task.Delay(16);
+ await Task.Delay(16, TestContext.Current.CancellationToken);
// Simulate to send heartbeat responses from clients.
timeProvider.Advance(TimeSpan.FromMilliseconds(50)); // ReceivedAt = 00:00.0400
handle.Ack(0);
- await Task.Delay(16);
+ await Task.Delay(16, TestContext.Current.CancellationToken);
// Assert
Assert.True(ackCalled.HasValue);
diff --git a/tests/MagicOnion.Server.Tests/StreamingHubHeartbeat/StreamingHubServerHeartbeatTest.cs b/tests/MagicOnion.Server.Tests/StreamingHubHeartbeat/StreamingHubServerHeartbeatTest.cs
index b21b86517..1d6f45346 100644
--- a/tests/MagicOnion.Server.Tests/StreamingHubHeartbeat/StreamingHubServerHeartbeatTest.cs
+++ b/tests/MagicOnion.Server.Tests/StreamingHubHeartbeat/StreamingHubServerHeartbeatTest.cs
@@ -52,9 +52,9 @@ public async Task EnableByAttribute()
// Act
var client = await Fixture.CreateStreamingHubClientAsync(receiver, options);
Fixture.FakeTimeProvider.Advance(TimeSpan.FromMilliseconds(300));
- await Task.Delay(15);
+ await Task.Delay(15, TestContext.Current.CancellationToken);
Fixture.FakeTimeProvider.Advance(TimeSpan.FromMilliseconds(300));
- await Task.Delay(15);
+ await Task.Delay(15, TestContext.Current.CancellationToken);
await client.DisposeAsync();
// Assert
@@ -72,9 +72,9 @@ public async Task DisableByAttribute()
// Act
var client = await Fixture.CreateStreamingHubClientAsync(receiver, options);
Fixture.FakeTimeProvider.Advance(TimeSpan.FromMilliseconds(300));
- await Task.Delay(15);
+ await Task.Delay(15, TestContext.Current.CancellationToken);
Fixture.FakeTimeProvider.Advance(TimeSpan.FromMilliseconds(300));
- await Task.Delay(15);
+ await Task.Delay(15, TestContext.Current.CancellationToken);
await client.DisposeAsync();
// Assert
@@ -92,9 +92,9 @@ public async Task Override_Interval()
// Act
var client = await Fixture.CreateStreamingHubClientAsync(receiver, options);
Fixture.FakeTimeProvider.Advance(TimeSpan.FromMilliseconds(300));
- await Task.Delay(15);
+ await Task.Delay(15, TestContext.Current.CancellationToken);
Fixture.FakeTimeProvider.Advance(TimeSpan.FromMilliseconds(300));
- await Task.Delay(15);
+ await Task.Delay(15, TestContext.Current.CancellationToken);
await client.DisposeAsync();
// Assert
@@ -121,16 +121,16 @@ public async Task Timeout()
// Send a heartbeat to the client.
Fixture.FakeTimeProvider.Advance(TimeSpan.FromMilliseconds(300));
- await Task.Delay(15);
+ await Task.Delay(15, TestContext.Current.CancellationToken);
// Wait for receiving a heartbeat from the server.
// The client must receive a heartbeat every 200ms from the server.
- await heartbeatReceived.Task.WaitAsync(TimeSpan.FromSeconds(1));
+ await heartbeatReceived.Task.WaitAsync(TimeSpan.FromSeconds(1), TestContext.Current.CancellationToken);
// Timeout at 200 ms after receiving a heartbeat.
Fixture.FakeTimeProvider.Advance(TimeSpan.FromMilliseconds(200));
- await Task.Delay(150); // Wait for unblocking and disconnection.
+ await Task.Delay(150, TestContext.Current.CancellationToken); // Wait for unblocking and disconnection.
// Assert
Assert.True((bool)Fixture.Items.GetValueOrDefault("Disconnected"));
@@ -154,9 +154,9 @@ public async Task Disabled_Unregister_Manually()
// Act
var client = await Fixture.CreateStreamingHubClientAsync(receiver, options);
Fixture.FakeTimeProvider.Advance(TimeSpan.FromMilliseconds(300));
- await Task.Delay(15);
+ await Task.Delay(15, TestContext.Current.CancellationToken);
Fixture.FakeTimeProvider.Advance(TimeSpan.FromMilliseconds(300));
- await Task.Delay(15);
+ await Task.Delay(15, TestContext.Current.CancellationToken);
await client.DisposeAsync();
// Assert
@@ -191,9 +191,9 @@ public async Task Default_Disable()
// Act
var client = await Fixture.CreateStreamingHubClientAsync(receiver, options);
Fixture.FakeTimeProvider.Advance(TimeSpan.FromMilliseconds(300));
- await Task.Delay(15);
+ await Task.Delay(15, TestContext.Current.CancellationToken);
Fixture.FakeTimeProvider.Advance(TimeSpan.FromMilliseconds(300));
- await Task.Delay(15);
+ await Task.Delay(15, TestContext.Current.CancellationToken);
await client.DisposeAsync();
// Assert
@@ -228,9 +228,9 @@ public async Task Default_Enable()
// Act
var client = await Fixture.CreateStreamingHubClientAsync(receiver, options);
Fixture.FakeTimeProvider.Advance(TimeSpan.FromMilliseconds(300));
- await Task.Delay(15);
+ await Task.Delay(15, TestContext.Current.CancellationToken);
Fixture.FakeTimeProvider.Advance(TimeSpan.FromMilliseconds(300));
- await Task.Delay(15);
+ await Task.Delay(15, TestContext.Current.CancellationToken);
await client.DisposeAsync();
// Assert
diff --git a/tests/MagicOnion.Server.Tests/StreamingHubTest.cs b/tests/MagicOnion.Server.Tests/StreamingHubTest.cs
index fbdd3d9fd..153aa1c7b 100644
--- a/tests/MagicOnion.Server.Tests/StreamingHubTest.cs
+++ b/tests/MagicOnion.Server.Tests/StreamingHubTest.cs
@@ -5,7 +5,6 @@
using MagicOnion.Server.Hubs;
using MessagePack;
using Grpc.Net.Client;
-using Xunit.Abstractions;
namespace MagicOnion.Server.Tests;
@@ -143,7 +142,7 @@ public BasicStreamingHubTest(ITestOutputHelper logger, ServerFixture se
[Fact]
public async Task OnConnected()
{
- client = await StreamingHubClient.ConnectAsync(channel, this);
+ client = await StreamingHubClient.ConnectAsync(channel, this, cancellationToken: TestContext.Current.CancellationToken);
var x = await voidOnConnectedTask.Task;
x.Should().Be((123, "foo", 12.3f));
await client.DisposeAsync();
@@ -154,7 +153,7 @@ public async Task ZeroArgument()
{
try
{
- client = await StreamingHubClient.ConnectAsync(channel, this);
+ client = await StreamingHubClient.ConnectAsync(channel, this, cancellationToken: TestContext.Current.CancellationToken);
await client.ZeroArgument();
await voidZeroTask.Task;
//await zeroTask.Task;
@@ -173,7 +172,7 @@ public async Task ZeroArgument()
[Fact]
public async Task OneArgument()
{
- var client = await StreamingHubClient.ConnectAsync(channel, this);
+ var client = await StreamingHubClient.ConnectAsync(channel, this, cancellationToken: TestContext.Current.CancellationToken);
await client.OneArgument(100);
//var x = await oneTask.Task;
var y = await voidoneTask.Task;
@@ -185,7 +184,7 @@ public async Task OneArgument()
[Fact]
public async Task MoreArgument()
{
- var client = await StreamingHubClient.ConnectAsync(channel, this);
+ var client = await StreamingHubClient.ConnectAsync(channel, this, cancellationToken: TestContext.Current.CancellationToken);
await client.MoreArgument(100, "foo", 10.3);
//var x = await moreTask.Task;
var y = await voidmoreTask.Task;
@@ -197,7 +196,7 @@ public async Task MoreArgument()
[Fact]
public async Task RetrunZeroArgument()
{
- var client = await StreamingHubClient.ConnectAsync(channel, this);
+ var client = await StreamingHubClient.ConnectAsync(channel, this, cancellationToken: TestContext.Current.CancellationToken);
var v = await client.RetrunZeroArgument();
v.Should().Be(1000);
await client.DisposeAsync();
@@ -205,7 +204,7 @@ public async Task RetrunZeroArgument()
[Fact]
public async Task RetrunOneArgument()
{
- var client = await StreamingHubClient.ConnectAsync(channel, this);
+ var client = await StreamingHubClient.ConnectAsync(channel, this, cancellationToken: TestContext.Current.CancellationToken);
var v = await client.RetrunZeroArgument();
v.Should().Be(1000);
await client.DisposeAsync();
@@ -213,7 +212,7 @@ public async Task RetrunOneArgument()
[Fact]
public async Task RetrunMoreArgument()
{
- var client = await StreamingHubClient.ConnectAsync(channel, this);
+ var client = await StreamingHubClient.ConnectAsync(channel, this, cancellationToken: TestContext.Current.CancellationToken);
var v = await client.RetrunMoreArgument(10, "foo", 30.4);
v.Should().Be(30.4);
await client.DisposeAsync();
@@ -222,7 +221,7 @@ public async Task RetrunMoreArgument()
[Fact]
public async Task OneArgument2()
{
- var client = await StreamingHubClient.ConnectAsync(channel, this);
+ var client = await StreamingHubClient.ConnectAsync(channel, this, cancellationToken: TestContext.Current.CancellationToken);
await client.OneArgument2(new TestObject() { X = 10, Y = 99, Z = 100 });
{
//var v = await one2Task.Task;
@@ -241,7 +240,7 @@ public async Task OneArgument2()
[Fact]
public async Task RetrunOneArgument2()
{
- var client = await StreamingHubClient.ConnectAsync(channel, this);
+ var client = await StreamingHubClient.ConnectAsync(channel, this, cancellationToken: TestContext.Current.CancellationToken);
var v = await client.RetrunOneArgument2(new TestObject() { X = 10, Y = 99, Z = 100 });
v.X.Should().Be(10);
v.Y.Should().Be(99);
@@ -252,7 +251,7 @@ public async Task RetrunOneArgument2()
[Fact]
public async Task OneArgument3()
{
- var client = await StreamingHubClient.ConnectAsync(channel, this);
+ var client = await StreamingHubClient.ConnectAsync(channel, this, cancellationToken: TestContext.Current.CancellationToken);
await client.OneArgument3(new[]
{
new TestObject() { X = 10, Y = 99, Z = 100 },
@@ -294,7 +293,7 @@ await client.OneArgument3(new[]
[Fact]
public async Task RetrunOneArgument3()
{
- var client = await StreamingHubClient.ConnectAsync(channel, this);
+ var client = await StreamingHubClient.ConnectAsync(channel, this, cancellationToken: TestContext.Current.CancellationToken);
var v = await client.RetrunOneArgument3(new[]
{
new TestObject() { X = 10, Y = 99, Z = 100 },
@@ -453,7 +452,7 @@ public MoreCheckHubTest(ITestOutputHelper logger, ServerFixture se
[Fact]
public async Task ReceiveEx()
{
- client = await StreamingHubClient.ConnectAsync(channel, this);
+ client = await StreamingHubClient.ConnectAsync(channel, this, cancellationToken: TestContext.Current.CancellationToken);
var ex = Assert.Throws(() =>
{
@@ -469,7 +468,7 @@ public async Task ReceiveEx()
[Fact]
public async Task StatusCodeEx()
{
- client = await StreamingHubClient.ConnectAsync(channel, this);
+ client = await StreamingHubClient.ConnectAsync(channel, this, cancellationToken: TestContext.Current.CancellationToken);
var ex = Assert.Throws(() =>
{
@@ -486,7 +485,7 @@ public async Task StatusCodeEx()
[Fact]
public async Task Filter()
{
- client = await StreamingHubClient.ConnectAsync(channel, this);
+ client = await StreamingHubClient.ConnectAsync(channel, this, cancellationToken: TestContext.Current.CancellationToken);
await client.FilterCheckAsync();
}